예제 #1
0
def launch_instance(args):
	default = {
	'instance_type': required(),
	'image_id': required(),
	'min_count': 1,
	'max_count': 1,
	'key_name': 'scalacity-dev1',
	'security_groups': ['SSH'],
	'user_data': '',
	'placement': 'us-east-1b',
	'placement_group': '',
	'instance_initiated_shutdown_behavior': 'terminate',
	'ebs_optimized': False
	}

	kwargs = process_args_or_defaults(args, default)

	reservation = None
	if assert_required_args(kwargs):
		conn = connection()
		arg = kwargs.pop('image_id')
		try:
			reservation = conn.run_instances(arg, **kwargs)
		except EC2ResponseError, e:
			ret = {'status': 408, 'body': 'Error while trying to run instance.  Possible malformed request or unavailable endpoint.'}
예제 #2
0
def change_run_state_instance(instance_id, action, args):
	default = {
	'force': False
	}
	kwargs = process_args_or_defaults(args, default)

	i = get_instance_obj(instance_id)
	
	if not i:
		return {'status': 404, 'body': 'Instance not found'}

	try:
		if action == 'stop':
			i.stop()
		elif action == 'terminate':
			i.terminate()
		elif action == 'reboot':
			i.reboot()
		elif action == 'start':
			i.start()
		else:
			pass	
	except Exception, e:
		return {'status': 408, 'body': 'Error while trying to stop instance via EC2 API. ' + str(e) }