Beispiel #1
0
def launch_instance(user, provider_uuid, identity_uuid,
                    size_alias, source_alias, deploy=True,
                    **launch_kwargs):
    """
    USE THIS TO LAUNCH YOUR INSTANCE FROM THE REPL!
    Initialization point --> launch_*_instance --> ..
    Required arguments will launch the instance, extras will do
    provider-specific modifications.

    1. Test for available Size (on specific driver!)
    2. Test user has Quota/Allocation (on our DB)
    3. Test user is launching appropriate size (Not below Thresholds)
    4. Perform an 'Instance launch' depending on Boot Source
    5. Return CORE Instance with new 'esh' objects attached.
    """
    now_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    status_logger.debug("%s,%s,%s,%s,%s,%s"
                 % (now_time, user, "No Instance", source_alias, size_alias,
                    "Request Received"))
    identity = CoreIdentity.objects.get(uuid=identity_uuid)
    esh_driver = get_cached_driver(identity=identity)

    #May raise Exception("Size not available")
    size = check_size(esh_driver, size_alias, provider_uuid)

    #May raise Exception("Volume/Machine not available")
    boot_source = get_boot_source(user.username, identity_uuid, source_alias)

    #Raise any other exceptions before launching here
    _pre_launch_validation(user.username, esh_driver, identity_uuid, boot_source, size)

    core_instance = _select_and_launch_source(user, identity_uuid, esh_driver, boot_source, size, deploy=deploy, **launch_kwargs)
    return core_instance
Beispiel #2
0
def _update_status_log(instance, status_update):
    now_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    user = instance._node.extra['metadata']['creator']
    size_alias = instance._node.extra['flavorId']
    machine_alias = instance._node.extra['imageId']
    status_logger.debug("%s,%s,%s,%s,%s,%s"
                        % (now_time, user, instance.alias, machine_alias,
                           size_alias, status_update))
Beispiel #3
0
def _update_status_log(instance, status_update):
    now_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    user = instance._node.extra['metadata']['creator']
    size_alias = instance._node.extra['flavorId']
    machine_alias = instance._node.extra['imageId']
    status_logger.debug("%s,%s,%s,%s,%s,%s"
                 % (now_time, user, instance.alias, machine_alias, size_alias,
                    status_update))
Beispiel #4
0
def launch_instance(user, provider_id, identity_id,
                    size_alias, machine_alias, **kwargs):
    """
    Required arguments will launch the instance, extras will do
    provider-specific modifications.

    Test the quota, Launch the instance,
    creates a core repr and updates status.

    returns a core_instance object after updating core DB.
    """
    now_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    if machine_alias:
        alias = "machine,%s" % machine_alias
    elif 'volume_alias' in kwargs:
        alias = "boot_volume,%s" % kwargs['volume_alias']
    else:
        raise Exception("Not enough data to launch: "
                        "volume_alias/machine_alias is missing")
    status_logger.debug("%s,%s,%s,%s,%s,%s"
                 % (now_time, user, "No Instance", alias, size_alias,
                    "Request Received"))
    core_identity = CoreIdentity.objects.get(id=identity_id)

    esh_driver = get_esh_driver(core_identity, user)
    size = esh_driver.get_size(size_alias)

    #May raise SizeNotAvailable
    check_size(size, provider_id)

    #May raise OverQuotaError or OverAllocationError
    check_quota(user.username, identity_id, size)

    #May raise InvalidCredsError
    (esh_instance, token, password) = launch_esh_instance(esh_driver,
            machine_alias, size_alias, core_identity, **kwargs)
    #Convert esh --> core
    core_instance = convert_esh_instance(
        esh_driver, esh_instance, provider_id, identity_id,
        user, token, password)
    esh_size = esh_driver.get_size(esh_instance.size.id)
    core_size = convert_esh_size(esh_size, provider_id)
    core_instance.update_history(
        core_instance.esh.extra['status'],
        core_size,
        #3rd arg is task OR tmp_status
        core_instance.esh.extra.get('task') or
        core_instance.esh.extra.get('metadata', {}).get('tmp_status'),
        first_update=True)

    return core_instance
Beispiel #5
0
def launch_instance(user, provider_id, identity_id,
                    size_alias, machine_alias, **kwargs):
    """
    Required arguments will launch the instance, extras will do
    provider-specific modifications.

    Test the quota, Launch the instance,
    creates a core repr and updates status.

    returns a core_instance object after updating core DB.
    """
    now_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    if machine_alias:
        alias = "machine,%s" % machine_alias
    elif 'volume_alias' in kwargs:
        alias = "boot_volume,%s" % kwargs['volume_alias']
    else:
        raise Exception("Not enough data to launch: "
                        "volume_alias/machine_alias is missing")
    status_logger.debug("%s,%s,%s,%s,%s,%s"
                 % (now_time, user, "No Instance", alias, size_alias,
                    "Request Received"))
    core_identity = CoreIdentity.objects.get(id=identity_id)

    esh_driver = get_esh_driver(core_identity, user)
    size = esh_driver.get_size(size_alias)

    #May raise SizeNotAvailable
    check_size(size, provider_id)

    #May raise OverQuotaError or OverAllocationError
    check_quota(user.username, identity_id, size)

    #May raise InvalidCredsError, SecurityGroupNotCreated
    (esh_instance, token, password) = launch_esh_instance(esh_driver,
            machine_alias, size_alias, core_identity, **kwargs)
    #Convert esh --> core
    core_instance = convert_esh_instance(
        esh_driver, esh_instance, provider_id, identity_id,
        user, token, password)
    esh_size = esh_driver.get_size(esh_instance.size.id)
    core_size = convert_esh_size(esh_size, provider_id)
    core_instance.update_history(
        core_instance.esh.extra['status'],
        core_size,
        #3rd arg is task OR tmp_status
        core_instance.esh.extra.get('task') or
        core_instance.esh.extra.get('metadata', {}).get('tmp_status'),
        first_update=True)

    return core_instance
Beispiel #6
0
def launch_instance(user, provider_uuid, identity_uuid,
                    size_alias, source_alias, **kwargs):
    """
    Initialization point --> launch_*_instance --> ..
    Required arguments will launch the instance, extras will do
    provider-specific modifications.

    1. Test for available Size (on specific driver!)
    2. Test user has Quota/Allocation (on our DB)
    3. Test user is launching appropriate size (Not below Thresholds)
    4. Perform an 'Instance launch' depending on Boot Source
    5. Return CORE Instance with new 'esh' objects attached.
    """
    now_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    status_logger.debug("%s,%s,%s,%s,%s,%s"
                 % (now_time, user, "No Instance", source_alias, size_alias,
                    "Request Received"))
    identity = CoreIdentity.objects.get(uuid=identity_uuid)
    esh_driver = get_cached_driver(identity=identity)

    #May raise SizeNotAvailable
    size = check_size(esh_driver, size_alias, provider_uuid)

    #May raise OverQuotaError or OverAllocationError
    check_quota(user.username, identity_uuid, size)

    #May raise UnderThresholdError
    check_application_threshold(user.username, identity_uuid, size, source_alias)

    #May raise Exception("Volume/Machine not available")
    boot_source = get_boot_source(user.username, identity_uuid, source_alias)
    if boot_source.is_volume():
        #NOTE: THIS route works when launching an EXISTING volume ONLY
        #      to CREATE a new bootable volume (from an existing volume/image/snapshot)
        #      use service/volume.py 'boot_volume'
        volume = _retrieve_source(esh_driver, boot_source.identifier, "volume")
        core_instance = launch_volume_instance(esh_driver, identity,
                volume, size, **kwargs)
    elif boot_source.is_machine():
        machine = _retrieve_source(esh_driver, boot_source.identifier, "machine")
        core_instance = launch_machine_instance(esh_driver, identity,
                machine, size, **kwargs)
    else:
        raise Exception("Boot source is of an unknown type")
    return core_instance
Beispiel #7
0
from service.driver import get_driver
from service.instance import update_instance_metadata
from service.instance import _create_and_attach_port
from service.networking import _generate_ssh_kwargs


def _update_status_log(instance, status_update):
    now_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    try:
        user = instance._node.extra['metadata']['creator']
    except KeyError, no_user:
        user = "******"
    size_alias = instance._node.extra['flavorId']
    machine_alias = instance._node.extra['imageId']
    status_logger.debug("%s,%s,%s,%s,%s,%s" %
                        (now_time, user, instance.alias, machine_alias,
                         size_alias, status_update))


@task(name="print_debug")
def print_debug():
    log_str = "print_debug task finished at %s." % datetime.now()
    print log_str
    logger.debug(log_str)


@task(name="complete_resize", max_retries=2, default_retry_delay=15)
def complete_resize(driverCls, provider, identity, instance_alias,
                    core_provider_id, core_identity_id, user):
    """
    Confirm the resize of 'instance_alias'
Beispiel #8
0
from service.driver import get_driver
from service.instance import update_instance_metadata
from service.instance import _create_and_attach_port
from service.networking import _generate_ssh_kwargs


def _update_status_log(instance, status_update):
    now_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    try:
        user = instance._node.extra['metadata']['creator']
    except KeyError, no_user:
        user = "******"
    size_alias = instance._node.extra['flavorId']
    machine_alias = instance._node.extra['imageId']
    status_logger.debug("%s,%s,%s,%s,%s,%s"
                        % (now_time, user, instance.alias, machine_alias,
                           size_alias, status_update))


@task(name="print_debug")
def print_debug():
    log_str = "print_debug task finished at %s." % datetime.now()
    print log_str
    logger.debug(log_str)


@task(name="complete_resize", max_retries=2, default_retry_delay=15)
def complete_resize(driverCls, provider, identity, instance_alias,
                    core_provider_id, core_identity_id, user):
    """
    Confirm the resize of 'instance_alias'