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
b0133d9c
Commit
b0133d9c
authored
Jul 27, 2015
by
Will Thames
Committed by
Abhijit Menon-Sen
Sep 28, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move connection handling failure to connect_to_aws
Make use of better error handling mechanism
parent
c08137a3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
17 deletions
+6
-17
contrib/inventory/ec2.py
+6
-17
No files found.
contrib/inventory/ec2.py
View file @
b0133d9c
...
...
@@ -165,8 +165,7 @@ class Ec2Inventory(object):
# as pre 2.24 boto will fall over otherwise
if
self
.
boto_profile
:
if
not
hasattr
(
boto
.
ec2
.
EC2Connection
,
'profile_name'
):
sys
.
stderr
.
write
(
"boto version must be >= 2.24 to use profile
\n
"
)
sys
.
exit
(
1
)
self
.
fail_with_error
(
"boto version must be >= 2.24 to use profile"
)
# Cache
if
self
.
args
.
refresh_cache
:
...
...
@@ -386,7 +385,6 @@ class Ec2Inventory(object):
continue
self
.
ec2_instance_filters
[
filter_key
]
.
append
(
filter_value
)
def
parse_cli_args
(
self
):
''' Command line argument processing '''
...
...
@@ -425,10 +423,7 @@ class Ec2Inventory(object):
conn
=
boto
.
connect_euca
(
host
=
self
.
eucalyptus_host
)
conn
.
APIVersion
=
'2010-08-31'
else
:
conn
=
ec2
.
connect_to_region
(
region
)
# connect_to_region will fail "silently" by returning None if the region name is wrong or not supported
if
conn
is
None
:
self
.
fail_with_error
(
"region name:
%
s likely not supported, or AWS is down. connection to region failed."
%
region
)
conn
=
self
.
connect_to_aws
(
ec2
,
region
)
return
conn
def
boto_fix_security_token_in_profile
(
self
,
connect_args
):
...
...
@@ -438,7 +433,6 @@ class Ec2Inventory(object):
connect_args
[
'security_token'
]
=
boto
.
config
.
get
(
profile
,
'aws_security_token'
)
return
connect_args
def
connect_to_aws
(
self
,
module
,
region
):
connect_args
=
{}
...
...
@@ -448,9 +442,11 @@ class Ec2Inventory(object):
self
.
boto_fix_security_token_in_profile
(
connect_args
)
conn
=
module
.
connect_to_region
(
region
,
**
connect_args
)
# connect_to_region will fail "silently" by returning None if the region name is wrong or not supported
if
conn
is
None
:
self
.
fail_with_error
(
"region name:
%
s likely not supported, or AWS is down. connection to region failed."
%
region
)
return
conn
def
get_instances_by_region
(
self
,
region
):
''' Makes an AWS EC2 API call to the list of instances in a particular
region '''
...
...
@@ -462,14 +458,8 @@ class Ec2Inventory(object):
for
filter_key
,
filter_values
in
self
.
ec2_instance_filters
.
items
():
reservations
.
extend
(
conn
.
get_all_instances
(
filters
=
{
filter_key
:
filter_values
}))
else
:
conn
=
ec2
.
connect_to_region
(
region
,
profile_name
=
self
.
boto_profile
)
# connect_to_region will fail "silently" by returning None if the region name is wrong or not supported
if
conn
is
None
:
print
(
"region name:
%
s likely not supported, or AWS is down. connection to region failed."
%
region
)
sys
.
exit
(
1
)
reservations
=
conn
.
get_all_instances
()
for
reservation
in
reservations
:
for
instance
in
reservation
.
instances
:
self
.
add_instance
(
instance
,
region
)
...
...
@@ -482,7 +472,6 @@ class Ec2Inventory(object):
error
=
"Error connecting to
%
s backend.
\n
%
s"
%
(
backend
,
e
.
message
)
self
.
fail_with_error
(
error
,
'getting EC2 instances'
)
def
get_rds_instances_by_region
(
self
,
region
):
''' Makes an AWS API call to the list of RDS instances in a particular
region '''
...
...
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