forked from p15670423/monkey
changed print to log
and added some doc about exception raised
This commit is contained in:
parent
5bfff88325
commit
ce633af3d1
|
@ -1,3 +1,5 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
import botocore
|
import botocore
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
|
@ -13,6 +15,9 @@ PLATFORM_TYPE_KEY = 'PlatformType'
|
||||||
IP_ADDRESS_KEY = 'IPAddress'
|
IP_ADDRESS_KEY = 'IPAddress'
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def filter_instance_data_from_aws_response(response):
|
def filter_instance_data_from_aws_response(response):
|
||||||
return [{
|
return [{
|
||||||
'instance_id': x[INSTANCE_ID_KEY],
|
'instance_id': x[INSTANCE_ID_KEY],
|
||||||
|
@ -74,6 +79,7 @@ class AwsService(object):
|
||||||
This function will assume that it's running on an EC2 instance with the correct IAM role.
|
This function will assume that it's running on an EC2 instance with the correct IAM role.
|
||||||
See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#iam-role for details.
|
See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#iam-role for details.
|
||||||
|
|
||||||
|
:raises: botocore.exceptions.ClientError if can't describe local instance information.
|
||||||
:return: All visible instances from this instance
|
:return: All visible instances from this instance
|
||||||
"""
|
"""
|
||||||
current_instance = AwsInstance()
|
current_instance = AwsInstance()
|
||||||
|
@ -84,5 +90,5 @@ class AwsService(object):
|
||||||
filtered_instances_data = filter_instance_data_from_aws_response(response)
|
filtered_instances_data = filter_instance_data_from_aws_response(response)
|
||||||
return filtered_instances_data
|
return filtered_instances_data
|
||||||
except botocore.exceptions.ClientError as e:
|
except botocore.exceptions.ClientError as e:
|
||||||
print e.response + " " + e.message + " ... " + e.operation_name
|
logger.info("AWS client error while trying to get instances: " + e.message)
|
||||||
raise e
|
raise e
|
||||||
|
|
Loading…
Reference in New Issue