create and deploy instances for 1 region

pull/27/head
alok 6 years ago
parent 307598fdca
commit a2a3e4434c
  1. 60
      aws-experiment-launch/create_and_deploy.py

@ -19,17 +19,16 @@ APPLICATION_NAME = 'benchmark-experiments'
def run_one_region(config,region_number,number_of_instances,commitId): def run_one_region(config,region_number,number_of_instances,commitId):
region_name = config[region_number][REGION_NAME] region_name = config[region_number][REGION_NAME]
session = boto3.Session(region_name=region_name) session = boto3.Session(region_name=region_name)
# ec2_client = session.client('ec2') ec2_client = session.client('ec2')
# response = create_instances(config,ec2_client,region_number,int(number_of_instances)) response = create_instances(config,ec2_client,region_number,int(number_of_instances))
codedeploy = session.client('codedeploy') codedeploy = session.client('codedeploy')
#commitId = get_commitId(commitId) #commitId = get_commitId(commitId)
application_name = APPLICATION_NAME application_name = APPLICATION_NAME
deployment_group = APPLICATION_NAME + str(commitId) deployment_group = APPLICATION_NAME + "-" + str(commitId)
repo = REPO repo = REPO
response = get_application(codedeploy,application_name) response = get_application(codedeploy,application_name)
response = get_deployment_group(codedeploy,application_name,deployment_group) response = get_deployment_group(codedeploy,application_name,deployment_group)
print(response) deploy(codedeploy, application_name, deployment_group, repo, commitId, wait=True)
# deploy(codedeploy, application_name, deployment_group, repo, commitId, wait=True)
# return response # return response
def get_availability_zones(ec2_client): def get_availability_zones(ec2_client):
@ -80,27 +79,34 @@ def create_instances(config,ec2_client,region_number,number_of_instances):
return response return response
def get_deployment_group(codedeploy,application_name,deployment_group): def get_deployment_group(codedeploy,application_name,deployment_group):
response = codedeploy.create_deployment_group( response = codedeploy.list_deployment_groups(
applicationName = application_name, applicationName = application_name
deploymentGroupName = deployment_group, )
deploymentConfigName='CodeDeployDefault.AllAtAOnce', if deployment_group in response['deploymentGroups']:
serviceRoleArn = 'arn:aws:iam::656503231766:role/BenchMarkCodeDeployServiceRole', return response
deploymentStyle={ else:
'deploymentType': 'IN_PLACE' response = codedeploy.create_deployment_group(
}, applicationName = application_name,
ec2TagSet={ deploymentGroupName = deployment_group,
'ec2TagSetList': [ deploymentConfigName = 'CodeDeployDefault.AllAtOnce',
[ serviceRoleArn = 'arn:aws:iam::656503231766:role/BenchMarkCodeDeployServiceRole',
{ deploymentStyle={
'Key': 'Name', 'deploymentType': 'IN_PLACE',
'Value': 'Node', 'deploymentOption': 'WITHOUT_TRAFFIC_CONTROL'
'Type': 'KEY_AND_VALUE' },
}, ec2TagSet={
], 'ec2TagSetList': [
] [
} {
'Key': 'Name',
'Value': 'Node',
'Type': 'KEY_AND_VALUE'
},
],
]
}
) )
return response return response
def get_commitId(commitId): def get_commitId(commitId):
if commitId is None: if commitId is None:
@ -132,7 +138,7 @@ def deploy(codedeploy, application_name,deployment_group,repo, commitId, wait=Tr
res = codedeploy.create_deployment( res = codedeploy.create_deployment(
applicationName = application_name, applicationName = application_name,
deploymentGroupName = deployment_group, deploymentGroupName = deployment_group,
deploymentConfigName = 'CodeDeployDefault.AllAtAOnce', deploymentConfigName = 'CodeDeployDefault.AllAtOnce',
description = 'benchmark experiments', description = 'benchmark experiments',
revision = { revision = {
'revisionType': 'GitHub', 'revisionType': 'GitHub',
@ -157,7 +163,7 @@ def deploy(codedeploy, application_name,deployment_group,repo, commitId, wait=Tr
start = time.time() start = time.time()
while info['status'] not in ('Succeeded', 'Failed', 'Stopped',) and (time.time() - start < 300.0): while info['status'] not in ('Succeeded', 'Failed', 'Stopped',) and (time.time() - start < 300.0):
info = codedeploy.get_deployment(deploymentId=depId)['deploymentInfo'] info = codedeploy.get_deployment(deploymentId=depId)['deploymentInfo']
print(info) print(info['deploymentOverview'])
print(info['status']) print(info['status'])
time.sleep(15) time.sleep(15)
if info['status'] == 'Succeeded': if info['status'] == 'Succeeded':

Loading…
Cancel
Save