Example #1
0
def provision_instance(itype=None, ami=None, security_group=None, ssh_key=None):
    """
    Provisions and instance and returns the instance object
    """
    print "Launching {} instance with ami {}.".format(itype, ami)
    conn = connect_ec2()
    res = conn.run_instances(ami, key_name=ssh_key, security_groups=[security_group], instance_type=itype,
                             instance_initiated_shutdown_behavior='terminate')
    return res.instances[0]
Example #2
0
def list_instances():
    """
    Lists all instances
    """
    conn = connect_ec2()
    res = conn.get_all_instances()
    if len(res) == 0:
        print('No instances')
    instances = chain.from_iterable([r.instances for r in res])
    for i in instances:
        print('Instance: {}.  Status: {}'.format(i, i.state))
Example #3
0
def list_instances():
    """
    Lists all instances
    """
    conn = connect_ec2()
    res = conn.get_all_instances()
    if len(res) == 0:
        print('No instances')
    instances = chain.from_iterable([r.instances for r in res])
    for i in instances:
        print('Instance: {}.  Status: {}'.format(i, i.state))
Example #4
0
def provision_instance(itype=None,
                       ami=None,
                       security_group=None,
                       ssh_key=None):
    """
    Provisions and instance and returns the instance object
    """
    print "Launching {} instance with ami {}.".format(itype, ami)
    conn = connect_ec2()
    res = conn.run_instances(ami,
                             key_name=ssh_key,
                             security_groups=[security_group],
                             instance_type=itype,
                             instance_initiated_shutdown_behavior='terminate')
    return res.instances[0]
Example #5
0
def _get_existing_instance(instance_id):
    """
    Gets an existing instance object
    """
    conn = connect_ec2()
    res = [r for r in conn.get_all_instances(instance_id)]
    if len(res) == 0:
        print 'Instance not found. Aborting'
        sys.exit(1)
    elif len(res) > 1:
        print 'Multiple instances found.  Aborting'
        sys.exit(1)
    elif len(res) == 1:
        # We're assuming that each reservation only has one instance
        # Not considering the case where a reservation can have multiple instances
        instance = res[0].instances[0]
    return instance
Example #6
0
def _get_existing_instance(instance_id):
    """
    Gets an existing instance object
    """
    conn = connect_ec2()
    res = [r for r in conn.get_all_instances(instance_id)]
    if len(res) == 0:
        print 'Instance not found. Aborting'
        sys.exit(1)
    elif len(res) > 1:
        print 'Multiple instances found.  Aborting'
        sys.exit(1)
    elif len(res) == 1:
        # We're assuming that each reservation only has one instance
        # Not considering the case where a reservation can have multiple instances
        instance = res[0].instances[0]
    return instance