Example #1
0
def _select_and_launch_source(
        user,
        identity_uuid,
        esh_driver,
        boot_source,
        size,
        deploy=True,
        **launch_kwargs):
    """
    Select launch route based on whether boot_source is-a machine/volume
    """
    identity = CoreIdentity.objects.get(uuid=identity_uuid)
    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,
            deploy=deploy, **launch_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,
            deploy=deploy, **launch_kwargs)
    else:
        raise Exception("Boot source is of an unknown type")
    return core_instance
Example #2
0
def create_bootable_volume(
        user,
        provider_uuid,
        identity_uuid,
        name,
        size_alias,
        new_source_alias,
        source_hint=None,
        **kwargs):
    """
    **kwargs passed as data to boot_volume_instance
    """

    identity = Identity.objects.get(uuid=identity_uuid)
    if not identity:
        raise Exception("Identity UUID %s does not exist." % identity_uuid)

    driver = get_cached_driver(identity=identity)
    if not driver:
        raise Exception(
            "Driver could not be initialized. Invalid Credentials?")

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

    # Return source or raises an Exception
    source = _retrieve_source(driver, new_source_alias, source_hint)

    core_instance = boot_volume_instance(driver, identity,
                                         source, size, name, **kwargs)

    return core_instance
Example #3
0
def create_bootable_volume(
        user,
        provider_uuid,
        identity_uuid,
        name,
        size_alias,
        new_source_alias,
        source_hint=None,
        **kwargs):
    """
    **kwargs passed as data to boot_volume_instance
    """

    identity = Identity.objects.get(uuid=identity_uuid)
    if not identity:
        raise Exception("Identity UUID %s does not exist." % identity_uuid)

    driver = get_cached_driver(identity=identity)
    if not driver:
        raise Exception(
            "Driver could not be initialized. Invalid Credentials?")

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

    # Return source or raises an Exception
    source = _retrieve_source(driver, new_source_alias, source_hint)

    core_instance = boot_volume_instance(driver, identity,
                                         source, size, name, **kwargs)

    return core_instance
Example #4
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
Example #5
0
def _pre_launch_validation(username, esh_driver, identity_uuid, boot_source, size):
    """
    Used BEFORE launching a volume/instance .. Raise exceptions here to be dealt with by the caller.
    """
    identity = CoreIdentity.objects.get(uuid=identity_uuid)

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

    #May raise UnderThresholdError
    check_application_threshold(username, identity_uuid, size, boot_source)

    if boot_source.is_machine():
        machine = _retrieve_source(esh_driver, boot_source.identifier, "machine")
        #may raise an exception if licensing doesnt match identity
        _test_for_licensing(machine, identity)