Ejemplo n.º 1
0
def _get_imaging_task(orig_managerCls, orig_creds, dest_managerCls, dest_creds,
                      imaging_args):
    # NOTE: destManagerCls may == origManagerCls,
    #      but creds MUST be different for a migration.
    if dest_managerCls and dest_creds != orig_creds:
        migrate_task = migrate_instance_task.si(orig_managerCls, orig_creds,
                                                dest_managerCls, dest_creds,
                                                **imaging_args)
        return migrate_task
    else:
        image_task = machine_imaging_task.si(orig_managerCls, orig_creds,
                                             imaging_args)
        return image_task
def _get_imaging_task(orig_managerCls, orig_creds,
                      dest_managerCls, dest_creds, imaging_args):
    # NOTE: destManagerCls may == origManagerCls,
    #      but creds MUST be different for a migration.
    if dest_managerCls and dest_creds != orig_creds:
        migrate_task = migrate_instance_task.si(
            orig_managerCls, orig_creds, dest_managerCls, dest_creds,
            **imaging_args)
        return migrate_task
    else:
        image_task = machine_imaging_task.si(
            orig_managerCls, orig_creds, imaging_args)
        return image_task
Ejemplo n.º 3
0
def start_machine_imaging(machine_request, delay=False):
    """
    Builds up a machine imaging task using core.models.machine_request
    delay - If true, wait until task is completed before returning
    """
    machine_request.status = 'imaging'
    machine_request.save()
    instance_id = machine_request.instance.provider_alias

    (orig_managerCls, orig_creds, dest_managerCls,
     dest_creds) = machine_request.prepare_manager()
    imaging_args = machine_request.get_imaging_args()

    #Step 1 - On OpenStack, sync/freeze BEFORE starting migration/imaging
    init_task = None
    #if orig_managerCls == OSImageManager:  # TODO:AND if instance still running
    #    freeze_task = freeze_instance_task.si(
    #        machine_request.instance.created_by_identity_id, instance_id)
    #    init_task = freeze_task
    if dest_managerCls and dest_creds != orig_creds:
        #Will run machine imaging task..
        migrate_task = migrate_instance_task.si(orig_managerCls, orig_creds,
                                                dest_managerCls, dest_creds,
                                                **imaging_args)
        if not init_task:
            init_task = migrate_task
        else:
            init_task.link(migrate_task)
    else:
        image_task = machine_imaging_task.si(orig_managerCls, orig_creds,
                                             imaging_args)
        if not init_task:
            init_task = image_task
        else:
            init_task.link(image_task)
    #The new image ID will be the first argument in process_request
    process_task = process_request.s(machine_request.id)
    if dest_managerCls and dest_creds != orig_creds:
        migrate_task.link(process_task)
    else:
        image_task.link(process_task)

    async = init_task.apply_async(link_error=machine_request_error.s(
        machine_request.id), )
    if delay:
        async .get()
    return async
Ejemplo n.º 4
0
def start_machine_imaging(machine_request, delay=False):
    """
    Builds up a machine imaging task using core.models.machine_request
    delay - If true, wait until task is completed before returning
    """
    machine_request.status = "processing"
    machine_request.save()
    instance_id = machine_request.instance.provider_alias

    (orig_managerCls, orig_creds, dest_managerCls, dest_creds) = machine_request.prepare_manager()
    imaging_args = machine_request.get_imaging_args()

    # Step 1 - On OpenStack, sync/freeze BEFORE starting migration/imaging
    init_task = None
    if orig_managerCls == OSImageManager:  # TODO:AND if instance still running
        freeze_task = freeze_instance_task.si(machine_request.instance.created_by_identity_id, instance_id)
        init_task = freeze_task
    if dest_managerCls and dest_creds != orig_creds:
        # Will run machine imaging task..
        migrate_task = migrate_instance_task.si(
            orig_managerCls, orig_creds, dest_managerCls, dest_creds, **imaging_args
        )
        if not init_task:
            init_task = migrate_task
        else:
            init_task.link(migrate_task)
    else:
        image_task = machine_imaging_task.si(orig_managerCls, orig_creds, imaging_args)
        if not init_task:
            init_task = image_task
        else:
            init_task.link(image_task)
    # The new image ID will be the first argument in process_request
    process_task = process_request.s(machine_request.id)
    if dest_managerCls and dest_creds != orig_creds:
        migrate_task.link(process_task)
    else:
        image_task.link(process_task)

    async = init_task.apply_async(link_error=machine_request_error.s(machine_request.id))
    if delay:
        async.get()
    return async
Ejemplo n.º 5
0
def start_machine_imaging(machine_request, delay=False):
    """
    Builds up a machine imaging task using core.models.machine_request
    delay - If true, wait until task is completed before returning
    """
    machine_request.status = "imaging"
    machine_request.save()
    instance_id = machine_request.instance.provider_alias

    (orig_managerCls, orig_creds, dest_managerCls, dest_creds) = machine_request.prepare_manager()
    imaging_args = machine_request.get_imaging_args()
    admin_driver = machine_request.new_admin_driver()
    admin_ident = machine_request.new_admin_identity()

    imaging_error_task = machine_request_error.s(machine_request.id)

    init_task = None

    if dest_managerCls and dest_creds != orig_creds:
        # Task 1 = Migrate Task
        migrate_task = migrate_instance_task.si(
            orig_managerCls, orig_creds, dest_managerCls, dest_creds, **imaging_args
        )
        if not init_task:
            init_task = migrate_task
        else:
            init_task.link(migrate_task)
    else:
        # Task 1 = Imaging Task
        image_task = machine_imaging_task.si(orig_managerCls, orig_creds, imaging_args)
        if not init_task:
            init_task = image_task
        else:
            init_task.link(image_task)
    # Task 2 = Process the machine request
    # (Save tags, name, description, metadata, etc.)
    process_task = process_request.s(machine_request.id)
    process_task.link_error(imaging_error_task)

    if dest_managerCls and dest_creds != orig_creds:
        migrate_task.link(process_task)
        migrate_task.link_error(imaging_error_task)
    else:
        image_task.link(process_task)
        image_task.link_error(imaging_error_task)
    # Task 3 = Validate the new image by launching an instance
    validate_task = validate_new_image.s(machine_request.id)
    process_task.link(validate_task)
    # Task 4 = Wait for new instance to be 'active'
    wait_for_task = wait_for.s(
        admin_driver.__class__, admin_driver.provider, admin_driver.identity, "active", return_id=True
    )
    validate_task.link(wait_for_task)
    validate_task.link_error(imaging_error_task)

    # Task 5 = Terminate the new instance on completion
    destroy_task = destroy_instance.s(admin_ident.id)
    wait_for_task.link(destroy_task)
    wait_for_task.link_error(imaging_error_task)
    # Task 6 - Finally, email the user that their image is ready!
    email_task = imaging_complete.s(machine_request.id)
    destroy_task.link_error(imaging_error_task)
    destroy_task.link(email_task)

    # Start the task.
    async = init_task.apply_async()
    if delay:
        async.get()
    return async
Ejemplo n.º 6
0
def start_machine_imaging(machine_request, delay=False):
    """
    Builds up a machine imaging task using core.models.machine_request
    delay - If true, wait until task is completed before returning
    """
    machine_request.status = 'imaging'
    machine_request.save()
    instance_id = machine_request.instance.provider_alias

    (orig_managerCls, orig_creds, dest_managerCls,
     dest_creds) = machine_request.prepare_manager()
    imaging_args = machine_request.get_imaging_args()
    admin_driver = machine_request.new_admin_driver()
    admin_ident = machine_request.new_admin_identity()

    imaging_error_task = machine_request_error.s(machine_request.id)

    init_task = None

    if dest_managerCls and dest_creds != orig_creds:
        #Task 1 = Migrate Task
        migrate_task = migrate_instance_task.si(orig_managerCls, orig_creds,
                                                dest_managerCls, dest_creds,
                                                **imaging_args)
        if not init_task:
            init_task = migrate_task
        else:
            init_task.link(migrate_task)
    else:
        #Task 1 = Imaging Task
        image_task = machine_imaging_task.si(orig_managerCls, orig_creds,
                                             imaging_args)
        if not init_task:
            init_task = image_task
        else:
            init_task.link(image_task)
    #Task 2 = Process the machine request
    # (Save tags, name, description, metadata, etc.)
    process_task = process_request.s(machine_request.id)
    process_task.link_error(imaging_error_task)

    if dest_managerCls and dest_creds != orig_creds:
        migrate_task.link(process_task)
        migrate_task.link_error(imaging_error_task)
    else:
        image_task.link(process_task)
        image_task.link_error(imaging_error_task)
    #Task 3 = Validate the new image by launching an instance
    validate_task = validate_new_image.s(machine_request.id)
    process_task.link(validate_task)
    #Task 4 = Wait for new instance to be 'active'
    wait_for_task = wait_for.s(admin_driver.__class__,
                               admin_driver.provider,
                               admin_driver.identity,
                               "active",
                               return_id=True)
    validate_task.link(wait_for_task)
    validate_task.link_error(imaging_error_task)

    #Task 5 = Terminate the new instance on completion
    destroy_task = destroy_instance.s(admin_ident.id)
    wait_for_task.link(destroy_task)
    wait_for_task.link_error(imaging_error_task)
    #Task 6 - Finally, email the user that their image is ready!
    email_task = imaging_complete.s(machine_request.id)
    destroy_task.link_error(imaging_error_task)
    destroy_task.link(email_task)

    # Start the task.
    async = init_task.apply_async()
    if delay:
        async .get()
    return async