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
98edfa46
Commit
98edfa46
authored
Apr 03, 2014
by
Atlas Health
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ec2: ability to list existing volumes
parent
317c2f4b
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 @
98edfa46
...
...
@@ -120,10 +120,10 @@ options:
version_added: "1.6"
state:
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
default: present
choices: ['absent', 'present']
choices: ['absent', 'present'
, 'list'
]
version_added: "1.6"
requirements: [ "boto" ]
author: Lester Wade
...
...
@@ -193,6 +193,12 @@ EXAMPLES = '''
module: ec2_vol
id: vol-XXXXXXXX
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.
...
...
@@ -232,6 +238,17 @@ def get_volume(module, ec2):
module
.
fail_json
(
msg
=
"Found more than one volume in zone (if specified) with name:
%
s"
%
name
)
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
):
vol
=
get_volume
(
module
,
ec2
)
...
...
@@ -336,7 +353,7 @@ def main():
device_name
=
dict
(),
zone
=
dict
(
aliases
=
[
'availability_zone'
,
'aws_zone'
,
'ec2_zone'
]),
snapshot
=
dict
(),
state
=
dict
(
choices
=
[
'absent'
,
'present'
],
default
=
'present'
)
state
=
dict
(
choices
=
[
'absent'
,
'present'
,
'list'
],
default
=
'present'
)
)
)
module
=
AnsibleModule
(
argument_spec
=
argument_spec
)
...
...
@@ -353,6 +370,31 @@ def main():
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
:
module
.
fail_json
(
msg
=
"Both id and name cannot be specified"
)
...
...
@@ -378,7 +420,8 @@ def main():
if
state
==
'absent'
:
delete_volume
(
module
,
ec2
)
else
:
if
state
==
'present'
:
volume
=
create_volume
(
module
,
ec2
,
zone
)
if
instance
:
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