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
a0fcd0f6
Commit
a0fcd0f6
authored
Aug 08, 2014
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6847 from atlashealth/ec2_vol_list
ec2_vol: adds ability to list existing volumes
parents
7737736b
98edfa46
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
4 deletions
+47
-4
library/cloud/ec2_vol
+47
-4
No files found.
library/cloud/ec2_vol
View file @
a0fcd0f6
...
@@ -89,10 +89,10 @@ options:
...
@@ -89,10 +89,10 @@ options:
version_added: "1.5"
version_added: "1.5"
state:
state:
description:
description:
- whether to ensure the volume is present or absent
- whether to ensure the volume is present or absent
, or to list existing volumes
required: false
required: false
default: present
default: present
choices: ['absent', 'present']
choices: ['absent', 'present'
, 'list'
]
version_added: "1.6"
version_added: "1.6"
author: Lester Wade
author: Lester Wade
extends_documentation_fragment: aws
extends_documentation_fragment: aws
...
@@ -162,6 +162,12 @@ EXAMPLES = '''
...
@@ -162,6 +162,12 @@ EXAMPLES = '''
module: ec2_vol
module: ec2_vol
id: vol-XXXXXXXX
id: vol-XXXXXXXX
state: absent
state: absent
# List volumes for an instance
- local_action:
module: ec2_vol
instance: i-XXXXXX
state: list
'''
'''
# Note: this module needs to be made idempotent. Possible solution is to use resource tags with the volumes.
# Note: this module needs to be made idempotent. Possible solution is to use resource tags with the volumes.
...
@@ -201,6 +207,17 @@ def get_volume(module, ec2):
...
@@ -201,6 +207,17 @@ def get_volume(module, ec2):
module
.
fail_json
(
msg
=
"Found more than one volume in zone (if specified) with name:
%
s"
%
name
)
module
.
fail_json
(
msg
=
"Found more than one volume in zone (if specified) with name:
%
s"
%
name
)
return
vols
[
0
]
return
vols
[
0
]
def
get_volumes
(
module
,
ec2
):
instance
=
module
.
params
.
get
(
'instance'
)
if
not
instance
:
module
.
fail_json
(
msg
=
"Instance must be specified to get volumes"
)
try
:
vols
=
ec2
.
get_all_volumes
(
filters
=
{
'attachment.instance-id'
:
instance
})
except
boto
.
exception
.
BotoServerError
,
e
:
module
.
fail_json
(
msg
=
"
%
s:
%
s"
%
(
e
.
error_code
,
e
.
error_message
))
return
vols
def
delete_volume
(
module
,
ec2
):
def
delete_volume
(
module
,
ec2
):
vol
=
get_volume
(
module
,
ec2
)
vol
=
get_volume
(
module
,
ec2
)
...
@@ -305,7 +322,7 @@ def main():
...
@@ -305,7 +322,7 @@ def main():
device_name
=
dict
(),
device_name
=
dict
(),
zone
=
dict
(
aliases
=
[
'availability_zone'
,
'aws_zone'
,
'ec2_zone'
]),
zone
=
dict
(
aliases
=
[
'availability_zone'
,
'aws_zone'
,
'ec2_zone'
]),
snapshot
=
dict
(),
snapshot
=
dict
(),
state
=
dict
(
choices
=
[
'absent'
,
'present'
],
default
=
'present'
)
state
=
dict
(
choices
=
[
'absent'
,
'present'
,
'list'
],
default
=
'present'
)
)
)
)
)
module
=
AnsibleModule
(
argument_spec
=
argument_spec
)
module
=
AnsibleModule
(
argument_spec
=
argument_spec
)
...
@@ -322,6 +339,31 @@ def main():
...
@@ -322,6 +339,31 @@ def main():
ec2
=
ec2_connect
(
module
)
ec2
=
ec2_connect
(
module
)
if
state
==
'list'
:
returned_volumes
=
[]
vols
=
get_volumes
(
module
,
ec2
)
for
v
in
vols
:
attachment
=
v
.
attach_data
returned_volumes
.
append
({
'create_time'
:
v
.
create_time
,
'id'
:
v
.
id
,
'iops'
:
v
.
iops
,
'size'
:
v
.
size
,
'snapshot_id'
:
v
.
snapshot_id
,
'status'
:
v
.
status
,
'type'
:
v
.
type
,
'zone'
:
v
.
zone
,
'attachment_set'
:
{
'attach_time'
:
attachment
.
attach_time
,
'device'
:
attachment
.
device
,
'status'
:
attachment
.
status
}
})
module
.
exit_json
(
changed
=
False
,
volumes
=
returned_volumes
)
if
id
and
name
:
if
id
and
name
:
module
.
fail_json
(
msg
=
"Both id and name cannot be specified"
)
module
.
fail_json
(
msg
=
"Both id and name cannot be specified"
)
...
@@ -353,7 +395,8 @@ def main():
...
@@ -353,7 +395,8 @@ def main():
if
state
==
'absent'
:
if
state
==
'absent'
:
delete_volume
(
module
,
ec2
)
delete_volume
(
module
,
ec2
)
else
:
if
state
==
'present'
:
volume
=
create_volume
(
module
,
ec2
,
zone
)
volume
=
create_volume
(
module
,
ec2
,
zone
)
if
instance
:
if
instance
:
attach_volume
(
module
,
ec2
,
volume
,
inst
)
attach_volume
(
module
,
ec2
,
volume
,
inst
)
...
...
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