* Fixed the aws env class to not be static anymore after itay's change.

* Added aws region getter
This commit is contained in:
maor.rayzin 2018-11-27 14:44:39 +02:00
parent 8e6ab5b9f5
commit bf29cddf4d
2 changed files with 11 additions and 7 deletions

View File

@ -7,11 +7,15 @@ class AWS(object):
def __init__(self): def __init__(self):
try: try:
self.instance_id = urllib2.urlopen('http://169.254.169.254/latest/meta-data/instance-id').read() self.instance_id = urllib2.urlopen('http://169.254.169.254/latest/meta-data/instance-id').read()
self.region = urllib2.urlopen('http://169.254.169.254/latest/meta-data/placement/availability-zone').read()[:-1]
except urllib2.URLError: except urllib2.URLError:
self.instance_id = None self.instance_id = None
def get_instance_id(self): def get_instance_id(self):
return self.instance_id return self.instance_id
def get_region(self):
return self.region
def is_aws_instance(self): def is_aws_instance(self):
return self.instance_id is not None return self.instance_id is not None

View File

@ -8,15 +8,15 @@ __author__ = 'itay.mizeretz'
class AwsEnvironment(Environment): class AwsEnvironment(Environment):
def __init__(self): def __init__(self):
super(AwsEnvironment, self).__init__() super(AwsEnvironment, self).__init__()
self._instance_id = AwsEnvironment._get_instance_id() self.aws_info = AWS()
self._instance_id = self._get_instance_id()
self.region = self._get_region()
@staticmethod def _get_instance_id(self):
def _get_instance_id(): return self.aws_info.get_instance_id()
return AWS.get_instance_id()
@staticmethod def _get_region(self):
def _get_region(): return self.aws_info.get_region()
return urllib2.urlopen('http://169.254.169.254/latest/meta-data/placement/availability-zone').read()[:-1]
def is_auth_enabled(self): def is_auth_enabled(self):
return True return True