Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
5eace5f7
Commit
5eace5f7
authored
Mar 31, 2014
by
Matt Martz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return untouhced servers with exact_count
parent
621fcbb9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
14 deletions
+29
-14
library/cloud/rax
+29
-14
No files found.
library/cloud/rax
View file @
5eace5f7
...
@@ -200,7 +200,7 @@ def rax_slugify(value):
...
@@ -200,7 +200,7 @@ def rax_slugify(value):
return
'rax_
%
s'
%
(
re
.
sub
(
'[^
\
w-]'
,
'_'
,
value
)
.
lower
()
.
lstrip
(
'_'
))
return
'rax_
%
s'
%
(
re
.
sub
(
'[^
\
w-]'
,
'_'
,
value
)
.
lower
()
.
lstrip
(
'_'
))
def
pyrax_object
_to_dict
(
obj
):
def
server
_to_dict
(
obj
):
instance
=
{}
instance
=
{}
for
key
in
dir
(
obj
):
for
key
in
dir
(
obj
):
value
=
getattr
(
obj
,
key
)
value
=
getattr
(
obj
,
key
)
...
@@ -216,7 +216,7 @@ def pyrax_object_to_dict(obj):
...
@@ -216,7 +216,7 @@ def pyrax_object_to_dict(obj):
def
create
(
module
,
names
,
flavor
,
image
,
meta
,
key_name
,
files
,
def
create
(
module
,
names
,
flavor
,
image
,
meta
,
key_name
,
files
,
wait
,
wait_timeout
,
disk_config
,
group
,
nics
,
wait
,
wait_timeout
,
disk_config
,
group
,
nics
,
extra_create_args
):
extra_create_args
,
existing
=
[]
):
cs
=
pyrax
.
cloudservers
cs
=
pyrax
.
cloudservers
changed
=
False
changed
=
False
...
@@ -266,7 +266,7 @@ def create(module, names, flavor, image, meta, key_name, files,
...
@@ -266,7 +266,7 @@ def create(module, names, flavor, image, meta, key_name, files,
server
.
get
()
server
.
get
()
except
:
except
:
server
.
status
==
'ERROR'
server
.
status
==
'ERROR'
instance
=
pyrax_object
_to_dict
(
server
)
instance
=
server
_to_dict
(
server
)
if
server
.
status
==
'ACTIVE'
or
not
wait
:
if
server
.
status
==
'ACTIVE'
or
not
wait
:
success
.
append
(
instance
)
success
.
append
(
instance
)
elif
server
.
status
==
'ERROR'
:
elif
server
.
status
==
'ERROR'
:
...
@@ -274,15 +274,18 @@ def create(module, names, flavor, image, meta, key_name, files,
...
@@ -274,15 +274,18 @@ def create(module, names, flavor, image, meta, key_name, files,
elif
wait
:
elif
wait
:
timeout
.
append
(
instance
)
timeout
.
append
(
instance
)
untouched
=
[
server_to_dict
(
s
)
for
s
in
existing
]
instances
=
success
+
untouched
results
=
{
results
=
{
'changed'
:
changed
,
'changed'
:
changed
,
'action'
:
'create'
,
'action'
:
'create'
,
'instances'
:
success
+
error
+
timeout
,
'instances'
:
instances
,
'success'
:
success
,
'success'
:
success
,
'error'
:
error
,
'error'
:
error
,
'timeout'
:
timeout
,
'timeout'
:
timeout
,
'instance_ids'
:
{
'instance_ids'
:
{
'instances'
:
[
i
[
'id'
]
for
i
in
success
+
error
+
timeout
],
'instances'
:
[
i
[
'id'
]
for
i
in
instances
],
'success'
:
[
i
[
'id'
]
for
i
in
success
],
'success'
:
[
i
[
'id'
]
for
i
in
success
],
'error'
:
[
i
[
'id'
]
for
i
in
error
],
'error'
:
[
i
[
'id'
]
for
i
in
error
],
'timeout'
:
[
i
[
'id'
]
for
i
in
timeout
]
'timeout'
:
[
i
[
'id'
]
for
i
in
timeout
]
...
@@ -300,7 +303,7 @@ def create(module, names, flavor, image, meta, key_name, files,
...
@@ -300,7 +303,7 @@ def create(module, names, flavor, image, meta, key_name, files,
module
.
exit_json
(
**
results
)
module
.
exit_json
(
**
results
)
def
delete
(
module
,
instance_ids
,
wait
,
wait_timeout
):
def
delete
(
module
,
instance_ids
,
wait
,
wait_timeout
,
kept
=
[]
):
cs
=
pyrax
.
cloudservers
cs
=
pyrax
.
cloudservers
changed
=
False
changed
=
False
...
@@ -318,7 +321,7 @@ def delete(module, instance_ids, wait, wait_timeout):
...
@@ -318,7 +321,7 @@ def delete(module, instance_ids, wait, wait_timeout):
else
:
else
:
changed
=
True
changed
=
True
instance
=
pyrax_object
_to_dict
(
server
)
instance
=
server
_to_dict
(
server
)
instances
[
instance
[
'id'
]]
=
instance
instances
[
instance
[
'id'
]]
=
instance
# If requested, wait for server deletion
# If requested, wait for server deletion
...
@@ -332,6 +335,7 @@ def delete(module, instance_ids, wait, wait_timeout):
...
@@ -332,6 +335,7 @@ def delete(module, instance_ids, wait, wait_timeout):
server
.
get
()
server
.
get
()
except
:
except
:
instances
[
instance_id
][
'status'
]
=
'DELETED'
instances
[
instance_id
][
'status'
]
=
'DELETED'
instances
[
instance_id
][
'rax_status'
]
=
'DELETED'
if
not
filter
(
lambda
s
:
s
[
'status'
]
not
in
(
''
,
'DELETED'
,
if
not
filter
(
lambda
s
:
s
[
'status'
]
not
in
(
''
,
'DELETED'
,
'ERROR'
),
'ERROR'
),
...
@@ -347,15 +351,17 @@ def delete(module, instance_ids, wait, wait_timeout):
...
@@ -347,15 +351,17 @@ def delete(module, instance_ids, wait, wait_timeout):
success
=
filter
(
lambda
s
:
s
[
'status'
]
in
(
''
,
'DELETED'
),
success
=
filter
(
lambda
s
:
s
[
'status'
]
in
(
''
,
'DELETED'
),
instances
.
values
())
instances
.
values
())
instances
=
[
server_to_dict
(
s
)
for
s
in
kept
]
results
=
{
results
=
{
'changed'
:
changed
,
'changed'
:
changed
,
'action'
:
'delete'
,
'action'
:
'delete'
,
'instances'
:
success
+
error
+
timeout
,
'instances'
:
instances
,
'success'
:
success
,
'success'
:
success
,
'error'
:
error
,
'error'
:
error
,
'timeout'
:
timeout
,
'timeout'
:
timeout
,
'instance_ids'
:
{
'instance_ids'
:
{
'instances'
:
[
i
[
'id'
]
for
i
in
success
+
error
+
timeout
],
'instances'
:
[
i
[
'id'
]
for
i
in
instances
],
'success'
:
[
i
[
'id'
]
for
i
in
success
],
'success'
:
[
i
[
'id'
]
for
i
in
success
],
'error'
:
[
i
[
'id'
]
for
i
in
error
],
'error'
:
[
i
[
'id'
]
for
i
in
error
],
'timeout'
:
[
i
[
'id'
]
for
i
in
timeout
]
'timeout'
:
[
i
[
'id'
]
for
i
in
timeout
]
...
@@ -501,11 +507,13 @@ def cloudservers(module, state, name, flavor, image, meta, key_name, files,
...
@@ -501,11 +507,13 @@ def cloudservers(module, state, name, flavor, image, meta, key_name, files,
if
len
(
servers
)
>
count
:
if
len
(
servers
)
>
count
:
state
=
'absent'
state
=
'absent'
kept
=
servers
[:
count
]
del
servers
[:
count
]
del
servers
[:
count
]
instance_ids
=
[]
instance_ids
=
[]
for
server
in
servers
:
for
server
in
servers
:
instance_ids
.
append
(
server
.
id
)
instance_ids
.
append
(
server
.
id
)
delete
(
module
,
instance_ids
,
wait
,
wait_timeout
)
delete
(
module
,
instance_ids
,
wait
,
wait_timeout
,
kept
=
kept
)
elif
len
(
servers
)
<
count
:
elif
len
(
servers
)
<
count
:
if
auto_increment
:
if
auto_increment
:
names
=
[]
names
=
[]
...
@@ -516,9 +524,15 @@ def cloudservers(module, state, name, flavor, image, meta, key_name, files,
...
@@ -516,9 +524,15 @@ def cloudservers(module, state, name, flavor, image, meta, key_name, files,
else
:
else
:
names
=
[
name
]
*
(
count
-
len
(
servers
))
names
=
[
name
]
*
(
count
-
len
(
servers
))
else
:
else
:
module
.
exit_json
(
changed
=
False
,
action
=
None
,
instances
=
[],
instances
=
[]
instance_ids
=
[]
for
server
in
servers
:
instances
.
append
(
server_to_dict
(
server
))
instance_ids
.
append
(
server
.
id
)
module
.
exit_json
(
changed
=
False
,
action
=
None
,
instances
=
instances
,
success
=
[],
error
=
[],
timeout
=
[],
success
=
[],
error
=
[],
timeout
=
[],
instance_ids
=
{
'instances'
:
[]
,
instance_ids
=
{
'instances'
:
instance_ids
,
'success'
:
[],
'error'
:
[],
'success'
:
[],
'error'
:
[],
'timeout'
:
[]})
'timeout'
:
[]})
else
:
else
:
...
@@ -568,7 +582,7 @@ def cloudservers(module, state, name, flavor, image, meta, key_name, files,
...
@@ -568,7 +582,7 @@ def cloudservers(module, state, name, flavor, image, meta, key_name, files,
if
len
(
servers
)
>=
count
:
if
len
(
servers
)
>=
count
:
instances
=
[]
instances
=
[]
for
server
in
servers
:
for
server
in
servers
:
instances
.
append
(
pyrax_object
_to_dict
(
server
))
instances
.
append
(
server
_to_dict
(
server
))
instance_ids
=
[
i
[
'id'
]
for
i
in
instances
]
instance_ids
=
[
i
[
'id'
]
for
i
in
instances
]
module
.
exit_json
(
changed
=
False
,
action
=
None
,
module
.
exit_json
(
changed
=
False
,
action
=
None
,
...
@@ -581,7 +595,8 @@ def cloudservers(module, state, name, flavor, image, meta, key_name, files,
...
@@ -581,7 +595,8 @@ def cloudservers(module, state, name, flavor, image, meta, key_name, files,
names
=
[
name
]
*
(
count
-
len
(
servers
))
names
=
[
name
]
*
(
count
-
len
(
servers
))
create
(
module
,
names
,
flavor
,
image
,
meta
,
key_name
,
files
,
create
(
module
,
names
,
flavor
,
image
,
meta
,
key_name
,
files
,
wait
,
wait_timeout
,
disk_config
,
group
,
nics
,
extra_create_args
)
wait
,
wait_timeout
,
disk_config
,
group
,
nics
,
extra_create_args
,
existing
=
servers
)
elif
state
==
'absent'
:
elif
state
==
'absent'
:
if
instance_ids
is
None
:
if
instance_ids
is
None
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment