Example #1
0
def increaseCap():
	group = autoscale.get_all_groups(names=['sw-ASG'])[0]
	numInstances = group.desired_capacity
	maxInstances = group.max_size
	if maxInstances >= (numInstances + 1):
		autoscale.set_desired_capacity('sw-ASG', numInstances + 1)
		print("Size increased from "+ str(numInstances) + " to " + str(numInstances+1))
	else: 
		print("You are already at Max capacity")
Example #2
0
def decreaseCap():
	group = autoscale.get_all_groups(names=['sw-ASG'])[0]
	numInstances = group.desired_capacity
	minInstances = group.min_size
	if numInstances -1 >= minInstances:
		autoscale.set_desired_capacity('sw-ASG', numInstances -1)
		print("Size increased from "+ str(numInstances) + " to " + str(numInstances-1))
	else: 
		print("You are already at Min capacity")
Example #3
0
def get_machines(num_instances_to_use, aws_group_name):
    machines = []
    # connect to AWS
    ec2 = boto.ec2.connect_to_region("us-west-2")
    autoscale = boto.ec2.autoscale.AutoScaleConnection()

    # how many machines are currently running?
    group = autoscale.get_all_groups(names=[aws_group_name])[0]
    num_instances = len(group.instances)
    print(GetTime(), "Number of instances online:", len(group.instances))

    # switch on more machines if we need them
    if num_instances < num_instances_to_use:
        print(GetTime(), "Launching instances...")
        autoscale.set_desired_capacity(aws_group_name, num_instances_to_use)

        # tell us status every few seconds
        group = None
        while num_instances < num_instances_to_use:
            group = autoscale.get_all_groups(names=[aws_group_name])[0]
            num_instances = len(group.instances)
            print(GetTime(), "Number of instances online:", len(group.instances))
            sleep(3)

    # grab instance IDs
    instance_ids = [i.instance_id for i in group.instances]
    print(GetTime(), "These instances are online:", instance_ids)

    instances = ec2.get_only_instances(instance_ids)
    for instance in instances:
        print(GetTime(), "Waiting for instance", instance.id, "to boot...")
        while 1:
            instance.update()
            if instance.state == "running":
                print(GetTime(), instance.id, "is running!")
                break
            sleep(3)
    for instance_id in instance_ids:
        print(GetTime(), "Waiting for instance", instance_id, "to report OK...")
        while 1:
            statuses = ec2.get_all_instance_status([instance_id])
            if len(statuses) < 1:
                sleep(3)
                continue
            status = statuses[0]
            if status.instance_status.status == "ok":
                print(GetTime(), instance.id, "reported OK!")
                break
            sleep(3)
    for instance in instances:
        machines.append(Machine(instance.ip_address))
    return machines
Example #4
0
def stop_instances():
    autoscale = boto.ec2.autoscale.AutoScaleConnection()
    group = autoscale.get_all_groups(names=['Daala'])[0]
    autoscale.set_desired_capacity('Daala',0)
    return 'ok'
Example #5
0
    'AWS instances, but the max is',max_num_instances_to_use,'.')
  num_instances_to_use = max_num_instances_to_use

#connect to AWS
ec2 = boto.ec2.connect_to_region('us-west-2');
autoscale = boto.ec2.autoscale.AutoScaleConnection();

#how many machines are currently running?
group = autoscale.get_all_groups(names=['Daala'])[0]
num_instances = len(group.instances)
print(GetTime(),'Number of instances online:',len(group.instances))

#switch on more machines if we need them
if num_instances < num_instances_to_use:
    print(GetTime(),'Launching instances...')
    autoscale.set_desired_capacity('Daala',num_instances_to_use)

    #tell us status every few seconds
    group = None
    while num_instances < num_instances_to_use:
        group = autoscale.get_all_groups(names=['Daala'])[0]
        num_instances = len(group.instances)
        print(GetTime(),'Number of instances online:',len(group.instances))
        sleep(3)

#grab instance IDs
instance_ids = [i.instance_id for i in group.instances]
print(GetTime(),"These instances are online:",instance_ids)

if 1:
    instances = ec2.get_only_instances(instance_ids)