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
4350585a
Commit
4350585a
authored
Apr 22, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2747 from lwade/ec2_vol_region
Add region support to ec2 volume module.
parents
5cced79c
e90f313c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
9 deletions
+25
-9
library/ec2_vol
+25
-9
No files found.
library/ec2_vol
View file @
4350585a
...
...
@@ -40,6 +40,12 @@ options:
required: false
default: null
aliases: []
region:
description:
- region in which to create the volume
required: false
default: null
aliases: []
zone:
description:
- zone in which to create the volume, if unset uses the zone the instance is in (if set)
...
...
@@ -71,7 +77,7 @@ import sys
import
time
try
:
import
boto
import
boto
.ec2
except
ImportError
:
print
"failed=True msg='boto required for this module'"
sys
.
exit
(
1
)
...
...
@@ -82,6 +88,7 @@ def main():
instance
=
dict
(),
volume_size
=
dict
(
required
=
True
),
device_name
=
dict
(),
region
=
dict
(),
zone
=
dict
(),
ec2_url
=
dict
(
aliases
=
[
'EC2_URL'
]),
ec2_secret_key
=
dict
(
aliases
=
[
'EC2_SECRET_KEY'
]),
...
...
@@ -92,6 +99,7 @@ def main():
instance
=
module
.
params
.
get
(
'instance'
)
volume_size
=
module
.
params
.
get
(
'volume_size'
)
device_name
=
module
.
params
.
get
(
'device_name'
)
region
=
module
.
params
.
get
(
'region'
)
zone
=
module
.
params
.
get
(
'zone'
)
ec2_url
=
module
.
params
.
get
(
'ec2_url'
)
ec2_secret_key
=
module
.
params
.
get
(
'ec2_secret_key'
)
...
...
@@ -104,14 +112,22 @@ def main():
ec2_secret_key
=
os
.
environ
[
'EC2_SECRET_KEY'
]
if
not
ec2_access_key
and
'EC2_ACCESS_KEY'
in
os
.
environ
:
ec2_access_key
=
os
.
environ
[
'EC2_ACCESS_KEY'
]
try
:
if
ec2_url
:
# if we have an URL set, connect to the specified endpoint
ec2
=
boto
.
connect_ec2_endpoint
(
ec2_url
,
ec2_access_key
,
ec2_secret_key
)
else
:
# otherwise it's Amazon.
ec2
=
boto
.
connect_ec2
(
ec2_access_key
,
ec2_secret_key
)
except
boto
.
exception
.
NoAuthHandlerFound
,
e
:
module
.
fail_json
(
msg
=
str
(
e
))
# If we have a region specified, connect to its endpoint.
if
region
:
try
:
ec2
=
boto
.
ec2
.
connect_to_region
(
region
,
aws_access_key_id
=
ec2_access_key
,
aws_secret_access_key
=
ec2_secret_key
)
except
boto
.
exception
.
NoAuthHandlerFound
,
e
:
module
.
fail_json
(
msg
=
str
(
e
))
# Otherwise, no region so we fallback to the old connection method
else
:
try
:
if
ec2_url
:
# if we have an URL set, connect to the specified endpoint
ec2
=
boto
.
connect_ec2_endpoint
(
ec2_url
,
ec2_access_key
,
ec2_secret_key
)
else
:
# otherwise it's Amazon.
ec2
=
boto
.
connect_ec2
(
ec2_access_key
,
ec2_secret_key
)
except
boto
.
exception
.
NoAuthHandlerFound
,
e
:
module
.
fail_json
(
msg
=
str
(
e
))
# Here we need to get the zone info for the instance. This covers situation where
# instance is specified but zone isn't.
...
...
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