in EC2/QuickInstanceEC2/qi.py [0:0]
def launch(opts, stack_name):
prop = get_instance_properties(opts, stack_name)
region = prop['region']
print('Launching instance %s... ' % stack_name)
output = create_stack(stack_name, get_template(prop, stack_name), region)
if output == 'STACK_ALREADY_EXISTS':
status = get_stack_state(stack_name, region).stack_status
if status == 'CREATE_COMPLETE':
get_instance_detail(get_instance_id(stack_name, region), stack_name, prop['key'], prop['user'], region)
if sys.version_info[0] < 3:
prompt = raw_input('Instance \'%s\' already exists. Would you like to terminate it? ' % stack_name)
else:
prompt = input('Instance \'%s\' already exists. Would you like to terminate it? ' % stack_name)
if prompt in ['Y', 'y']:
delete_stack(stack_name, region)
elif 'arn:aws:cloudformation' in output:
while True:
status = get_stack_state(stack_name, region).stack_status
if status == 'CREATE_COMPLETE':
print('\nInstance created successfully.')
get_instance_detail(get_instance_id(stack_name, region), stack_name, prop['key'], prop['user'], region)
break
elif status == 'CREATE_FAILED' or 'ROLLBACK' in status:
print('\nFailed to create instance \'%s\'.' % stack_name)
get_stack_events(stack_name, region)
break
sys.stdout.write('.')
sys.stdout.flush()
sleep(5)