예제 #1
0
def _complete_launch_instance(driver, identity, instance, user, token, password):
    from service import task
    # call async task to deploy to instance.
    task.deploy_init_task(driver, instance, identity, user.username, password, token)
    #Create the Core/DB for instance
    core_instance = convert_esh_instance(
        driver, instance, identity.provider.uuid, identity.uuid,
        user, token, password)
    #Update InstanceStatusHistory
    _first_update(driver, identity, core_instance, instance)
    #Invalidate and return
    invalidate_cached_instances(identity=identity)
    return core_instance
예제 #2
0
def _complete_launch_instance(driver, identity, instance, user, token, password, deploy=True):
    from service import task
    #Create the Core/DB for instance
    core_instance = convert_esh_instance(
        driver, instance, identity.provider.uuid, identity.uuid,
        user, token, password)
    # call async task to deploy to instance.
    task.deploy_init_task(driver, instance, identity, user.username,
                          password, token, deploy=deploy)
    #Update InstanceStatusHistory
    _first_update(driver, identity, core_instance, instance)
    #Invalidate and return
    invalidate_cached_instances(identity=identity)
    return core_instance
예제 #3
0
def launch_esh_instance(driver,
                        machine_alias,
                        size_alias,
                        core_identity,
                        name=None,
                        username=None,
                        using_admin=False,
                        *args,
                        **kwargs):
    """
    TODO: Remove extras, pass as kwarg_dict instead

    return the esh_instance & instance token
    """
    from service import task
    try:
        #create a reference to this attempted instance launch.
        instance_token = str(uuid.uuid4())
        #create a unique one-time password for instance root user
        instance_password = str(uuid.uuid4())

        #TODO: Mock these for faster launch performance
        #Gather the machine object
        machine = driver.get_machine(machine_alias)
        if not machine:
            raise Exception(
                "Machine %s could not be located with this driver" %
                machine_alias)

        #Gather the size object
        size = driver.get_size(size_alias)
        if not size:
            raise Exception("Size %s could not be located with this driver" %
                            size_alias)

        if not username:
            username = driver.identity.user.username
        if not name:
            name = 'Instance of %s' % machine.alias

        if isinstance(driver.provider, EucaProvider):
            #Create and set userdata
            instance_service_url = "%s" % (settings.INSTANCE_SERVICE_URL, )
            init_file_version = kwargs.get('init_file', "v1")
            # Remove quotes -- Single && Double
            name = name.replace('"', '').replace("'", "")
            userdata_contents = _get_init_script(instance_service_url,
                                                 instance_token,
                                                 instance_password, name,
                                                 username, init_file_version)
            #Create/deploy the instance -- NOTE: Name is passed in extras
            logger.info("EUCA -- driver.create_instance EXTRAS:%s" % kwargs)
            esh_instance = driver\
                .create_instance(name=name, image=machine,
                                 size=size, ex_userdata=userdata_contents,
                                 **kwargs)
        elif isinstance(driver.provider, OSProvider):
            deploy = True
            if not using_admin:
                security_group_init(core_identity)
            network = network_init(core_identity)
            keypair_init(core_identity)
            credentials = core_identity.get_credentials()
            tenant_name = credentials.get('ex_tenant_name')
            ex_metadata = {
                'tmp_status': 'initializing',
                'tenant_name': tenant_name,
                'creator': '%s' % username
            }
            ex_keyname = settings.ATMOSPHERE_KEYPAIR_NAME
            logger.debug("OS driver.create_instance kwargs: %s" % kwargs)
            esh_instance = driver.create_instance(name=name,
                                                  image=machine,
                                                  size=size,
                                                  token=instance_token,
                                                  ex_metadata=ex_metadata,
                                                  ex_keyname=ex_keyname,
                                                  networks=[network],
                                                  deploy=True,
                                                  **kwargs)
            #Used for testing.. Eager ignores countdown
            if app.conf.CELERY_ALWAYS_EAGER:
                logger.debug("Eager Task, wait 1 minute")
                time.sleep(1 * 60)
            # call async task to deploy to instance.
            task.deploy_init_task(driver, esh_instance, username,
                                  instance_password)
        elif isinstance(driver.provider, AWSProvider):
            #TODO:Extra stuff needed for AWS provider here
            esh_instance = driver.deploy_instance(name=name,
                                                  image=machine,
                                                  size=size,
                                                  deploy=True,
                                                  token=instance_token,
                                                  **kwargs)
        else:
            raise Exception("Unable to launch with this provider.")
        return (esh_instance, instance_token, instance_password)
    except Exception as e:
        logger.exception(e)
        raise
예제 #4
0
def launch_esh_instance(driver, machine_alias, size_alias, core_identity,
        name=None, username=None, using_admin=False,
        *args, **kwargs):

    """
    TODO: Remove extras, pass as kwarg_dict instead

    return the esh_instance & instance token
    """
    from service import task
    try:
        #create a reference to this attempted instance launch.
        instance_token = str(uuid.uuid4())
        #create a unique one-time password for instance root user
        instance_password = str(uuid.uuid4())

        #TODO: Mock these for faster launch performance
        #Gather the machine object
        machine = driver.get_machine(machine_alias)
        if not machine:
            raise Exception(
                "Machine %s could not be located with this driver"
                % machine_alias)

        #Gather the size object
        size = driver.get_size(size_alias)
        if not size:
            raise Exception(
                "Size %s could not be located with this driver" % size_alias)

        if not username:
            username = driver.identity.user.username
        if not name:
            name = 'Instance of %s' % machine.alias

        if isinstance(driver.provider, EucaProvider):
            #Create and set userdata
            instance_service_url = "%s" % (settings.INSTANCE_SERVICE_URL,)
            init_file_version = kwargs.get('init_file', "v1")
            # Remove quotes -- Single && Double
            name = name.replace('"', '').replace("'", "")
            userdata_contents = _get_init_script(instance_service_url,
                                                 instance_token,
                                                 instance_password,
                                                 name,
                                                 username, init_file_version)
            #Create/deploy the instance -- NOTE: Name is passed in extras
            logger.info("EUCA -- driver.create_instance EXTRAS:%s" % kwargs)
            esh_instance = driver\
                .create_instance(name=name, image=machine,
                                 size=size, ex_userdata=userdata_contents,
                                 **kwargs)
        elif isinstance(driver.provider, OSProvider):
            deploy = True
            if not using_admin:
                security_group_init(core_identity)
            network = network_init(core_identity)
            keypair_init(core_identity)
            credentials = core_identity.get_credentials()
            tenant_name = credentials.get('ex_tenant_name')
            ex_metadata = {'tmp_status': 'initializing',
                           'tenant_name': tenant_name,
                           'creator': '%s' % username}
            ex_keyname = settings.ATMOSPHERE_KEYPAIR_NAME
            logger.debug("OS driver.create_instance kwargs: %s" % kwargs)
            esh_instance = driver.create_instance(name=name, image=machine,
                                                  size=size,
                                                  token=instance_token,
                                                  ex_metadata=ex_metadata,
                                                  ex_keyname=ex_keyname,
                                                  networks=[network],
                                                  deploy=True, **kwargs)
            #Used for testing.. Eager ignores countdown
            if app.conf.CELERY_ALWAYS_EAGER:
                logger.debug("Eager Task, wait 1 minute")
                time.sleep(1*60)
            # call async task to deploy to instance.
            task.deploy_init_task(driver, esh_instance, username, instance_password)
        elif isinstance(driver.provider, AWSProvider):
            #TODO:Extra stuff needed for AWS provider here
            esh_instance = driver.deploy_instance(name=name, image=machine,
                                                  size=size, deploy=True,
                                                  token=instance_token,
                                                  **kwargs)
        else:
            raise Exception("Unable to launch with this provider.")
        return (esh_instance, instance_token, instance_password)
    except Exception as e:
        logger.exception(e)
        raise