Skip to content

Commit

Permalink
Merge 97cd885 into 087b4e5
Browse files Browse the repository at this point in the history
  • Loading branch information
nz285 committed Sep 7, 2016
2 parents 087b4e5 + 97cd885 commit b3032c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion License2Deploy/rolling_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class RollingDeploy(object):

MAX_RETRIES = 10
INSTANCE_NAME = "{0}-{1}{2}-{3}" #e.g. aw1-dnbi-cirrus107-qa

def __init__(self,
env=None,
Expand All @@ -27,6 +28,7 @@ def __init__(self,
only_new_wait=[10, 30]):
self.env = env
self.session = session
self.project_full_name = project
self.project = project.replace('-','')
self.build_number = build_number
self.ami_id = ami_id
Expand All @@ -49,6 +51,11 @@ def __init__(self,
self.ready_wait = ready_wait
self.health_wait = health_wait
self.only_new_wait = only_new_wait

def format_instance_name(self, ip):
region_short = 'aw1' if self.regions_conf == 'us-west-1' else 'ae1'
ip_end = ip.split(".")[3]
return self.INSTANCE_NAME.format(region_short, self.project_full_name, ip_end, self.env)

def get_ami_id_state(self, ami_id):
try:
Expand Down Expand Up @@ -152,7 +159,9 @@ def get_instance_ip_addrs(self, id_list=[]):
try:
instance_data = [ids for instInfo in self.conn_ec2.get_all_instances(instance_ids=id_list) for ids in instInfo.instances]
for instance in instance_data:
ip_dict[instance.id] = instance.private_ip_address
ip = instance.private_ip_address
instance_name = self.format_instance_name(ip)
ip_dict[instance.id] = (ip, instance_name)
return ip_dict
except Exception as e:
logging.error("Unable to get IP Addresses for instances: {0}".format(e))
Expand Down
5 changes: 5 additions & 0 deletions tests/rolling_deploy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ def test_double_autoscale_instance_count(self):

def test_decrease_autoscale_instance_count(self):
self.assertEqual(self.rolling_deploy.decrease_autoscale_instance_count(4), 2)

def test_format_instance_name(self):
expected_instance_name = "ae1-server-gms-extender50-stg"
actual_instance_name = self.rolling_deploy.format_instance_name("10.32.10.50")
self.assertEqual(expected_instance_name, actual_instance_name)

def main():
unittest.main()
Expand Down

0 comments on commit b3032c5

Please sign in to comment.