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
5488bc39
Commit
5488bc39
authored
Mar 15, 2015
by
Steve Gargan
Committed by
Toshio Kuratomi
Mar 16, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix for issue #10422. outputs informative error message when AWS credentials are not available
parent
0898920e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
20 deletions
+33
-20
plugins/inventory/ec2.py
+33
-20
No files found.
plugins/inventory/ec2.py
View file @
5488bc39
...
...
@@ -334,23 +334,24 @@ class Ec2Inventory(object):
self
.
write_to_cache
(
self
.
inventory
,
self
.
cache_path_cache
)
self
.
write_to_cache
(
self
.
index
,
self
.
cache_path_index
)
def
get_instances_by_region
(
self
,
region
):
''' Makes an AWS EC2 API call to the list of instances in a particular
region '''
try
:
def
connect
(
self
,
region
):
''' create connection to api server'''
if
self
.
eucalyptus
:
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
:
print
(
"region name:
%
s likely not supported, or AWS is down. connection to region failed."
%
region
)
sys
.
exit
(
1
)
raise
Exception
(
"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 '''
try
:
conn
=
self
.
connect
(
region
)
reservations
=
[]
if
self
.
ec2_instance_filters
:
for
filter_key
,
filter_values
in
self
.
ec2_instance_filters
.
iteritems
():
...
...
@@ -363,6 +364,9 @@ class Ec2Inventory(object):
self
.
add_instance
(
instance
,
region
)
except
boto
.
exception
.
BotoServerError
,
e
:
if
e
.
error_code
==
'AuthFailure'
:
self
.
display_auth_error
()
if
not
self
.
eucalyptus
:
print
"Looks like AWS is down again:"
print
e
...
...
@@ -379,23 +383,33 @@ class Ec2Inventory(object):
for
instance
in
instances
:
self
.
add_rds_instance
(
instance
,
region
)
except
boto
.
exception
.
BotoServerError
,
e
:
if
e
.
error_code
==
'AuthFailure'
:
self
.
display_auth_error
()
if
not
e
.
reason
==
"Forbidden"
:
print
"Looks like AWS RDS is down: "
print
e
sys
.
exit
(
1
)
def
get_instance
(
self
,
region
,
instance_id
):
'''
Gets details about a specific instance
'''
if
self
.
eucalyptus
:
conn
=
boto
.
connect_euca
(
self
.
eucalyptus_host
)
conn
.
APIVersion
=
'2010-08-31'
def
display_auth_error
(
self
):
'''
Raise an error with an informative message if there is an issue authenticating
'''
errors
=
[
"Authentication error retrieving ec2 inventory."
]
if
None
in
[
os
.
environ
.
get
(
'AWS_ACCESS_KEY_ID'
),
os
.
environ
.
get
(
'AWS_SECRET_ACCESS_KEY'
)]:
errors
.
append
(
' - No AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY environment vars found'
)
else
:
conn
=
ec2
.
connect_to_region
(
region
)
errors
.
append
(
' - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment vars found but may not be correct'
)
# 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
)
boto_paths
=
[
'/etc/boto.cfg'
,
'~/.boto'
,
'~/.aws/credentials'
]
boto_config_found
=
list
(
p
for
p
in
boto_paths
if
os
.
path
.
isfile
(
os
.
path
.
expanduser
(
p
)))
if
len
(
boto_config_found
)
>
0
:
errors
.
append
(
" - Boto configs found at '
%
s', but the credentials contained may not be correct"
%
', '
.
join
(
boto_config_found
))
else
:
errors
.
append
(
" - No Boto config found at any expected location '
%
s'"
%
', '
.
join
(
boto_paths
))
raise
Exception
(
'
\n
'
.
join
(
errors
))
def
get_instance
(
self
,
region
,
instance_id
):
conn
=
self
.
connect
(
region
)
reservations
=
conn
.
get_all_instances
([
instance_id
])
for
reservation
in
reservations
:
...
...
@@ -785,4 +799,3 @@ class Ec2Inventory(object):
# Run the script
Ec2Inventory
()
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