コード例 #1
0
ファイル: machine.py プロジェクト: waterstroke/atmosphere
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
    """

    new_status, _ = StatusType.objects.get_or_create(name="started")
    machine_request.status = new_status
    machine_request.save()

    original_status = machine_request.old_status
    last_run_error, original_status = machine_request._recover_from_error(
        original_status)

    if last_run_error:
        machine_request.old_status = original_status
        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()

    imaging_error_task = machine_request_error.s(machine_request.id)

    # Task 2 = Imaging w/ Chromogenic
    imaging_task = _get_imaging_task(orig_managerCls, orig_creds,
                                     dest_managerCls, dest_creds, imaging_args)
    imaging_task.link_error(imaging_error_task)
    # Assume we are starting from the beginning.
    init_task = imaging_task
    # Task 2 = Process the machine request
    if 'processing' in original_status:
        # If processing, start here..
        image_id = original_status.replace("processing - ", "")
        logger.info("Start with processing:%s" % image_id)
        process_task = process_request.s(image_id, machine_request.id)
        init_task = process_task
    else:
        # Link from imaging to process..
        process_task = process_request.s(machine_request.id)
        imaging_task.link(process_task)
    process_task.link_error(imaging_error_task)

    # Final Task - email the user that their image is ready
    # NOTE: si == Ignore the result of the last task.
    email_task = imaging_complete.si(machine_request.id)
    email_task.link_error(imaging_error_task)

    if getattr(settings, 'ENABLE_IMAGE_VALIDATION', True):
        init_task = enable_image_validation(machine_request, init_task,
                                            email_task, original_status,
                                            imaging_error_task)
    else:
        process_task.link(email_task)

    # Set status to imaging ONLY if our initial task is the imaging task.
    if init_task == imaging_task:
        machine_request.old_status = 'imaging'
        machine_request.save()
    # Start the task.
    logger.info("Machine Chain : %s" % print_chain(init_task, idx=0))
    async = init_task.apply_async()
    if delay:
        async .get()
    return async
コード例 #2
0
ファイル: machine.py プロジェクト: amit4111989/atmosphere
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
    """

    new_status, _ = StatusType.objects.get_or_create(name="started")
    machine_request.status = new_status
    machine_request.save()

    original_status = machine_request.old_status
    last_run_error, original_status = machine_request._recover_from_error(
        original_status)

    if last_run_error:
        machine_request.old_status = original_status
        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 = get_admin_driver(machine_request.new_machine_provider)
    admin_ident = machine_request.new_admin_identity()

    imaging_error_task = machine_request_error.s(machine_request.id)

    # Task 2 = Imaging w/ Chromogenic
    imaging_task = _get_imaging_task(orig_managerCls, orig_creds,
                                     dest_managerCls, dest_creds, imaging_args)
    imaging_task.link_error(imaging_error_task)
    # Assume we are starting from the beginning.
    init_task = imaging_task
    # Task 2 = Process the machine request
    if 'processing' in original_status:
        # If processing, start here..
        image_id = original_status.replace("processing - ", "")
        logger.info("Start with processing:%s" % image_id)
        process_task = process_request.s(image_id, machine_request.id)
        init_task = process_task
    else:
        # Link from imaging to process..
        process_task = process_request.s(machine_request.id)
        imaging_task.link(process_task)
    process_task.link_error(imaging_error_task)

    # Task 3 = Validate the new image by launching an instance
    if 'validating' in original_status:
        image_id = machine_request.new_machine.identifier
        celery_logger.info("Start with validating:%s" % image_id)
        # If validating, seed the image_id and start here..
        validate_task = validate_new_image.s(image_id, machine_request.id)
        init_task = validate_task
    else:
        validate_task = validate_new_image.s(machine_request.id)
        process_task.link(validate_task)
    #Validate task returns an instance_id
    # Task 4 = Wait for new instance to be 'active'
    wait_for_task = wait_for_instance.s(
        # NOTE: 1st arg, instance_id, passed from last task.
        admin_driver.__class__,
        admin_driver.provider,
        admin_driver.identity,
        "active",
        test_tmp_status=True,
        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.created_by, admin_ident.uuid)
    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!
    # NOTE: si == Ignore the result of the last task.
    email_task = imaging_complete.si(machine_request.id)
    destroy_task.link_error(imaging_error_task)
    destroy_task.link(email_task)

    email_task.link_error(imaging_error_task)
    # Set status to imaging ONLY if our initial task is the imaging task.
    if init_task == imaging_task:
        machine_request.old_status = 'imaging'
        machine_request.save()
    # Start the task.
    logger.info("Machine Chain : %s" % print_chain(init_task, idx=0))
    async = init_task.apply_async()
    if delay:
        async .get()
    return async
コード例 #3
0
ファイル: machine.py プロジェクト: xuhang57/atmosphere
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
    """
    new_status, _ = StatusType.objects.get_or_create(name="started")
    machine_request.status = new_status
    machine_request.save()
    
    original_status = machine_request.old_status
    last_run_error, original_status = machine_request._recover_from_error(original_status)

    if last_run_error:
        machine_request.old_status = original_status
        machine_request.save()
    instance_id = machine_request.instance.provider_alias
    identity_id = machine_request.instance.created_by_identity_id

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


    # NOTE: si == (Immutable Subtask) Ignore the result of the last task, all arguments must be passed into these tasks during creation step.
    # NOTE: s == (Subtask) Will use the result of last task as the _first argument_, arguments passed in will start from arg[1]
    imaging_error_task = machine_request_error.s(machine_request.id)

    # Task 1 - prepare the instance
    prep_instance_task = prep_instance_for_snapshot.si(identity_id, instance_id)

    # Task 2 = Imaging w/ Chromogenic
    imaging_task = _get_imaging_task(orig_managerCls, orig_creds,
                                     dest_managerCls, dest_creds,
                                     imaging_args)
    prep_instance_task.link(imaging_task)
    imaging_task.link_error(imaging_error_task)
    # Assume we are starting from the beginning.
    init_task = prep_instance_task
    # Task 3 = Process the machine request
    if 'processing - ' in original_status:
        # If processing, start here..
        image_id = original_status.replace("processing - ", "")
        logger.info("Start with processing:%s" % image_id)
        process_task = process_request.s(image_id, machine_request.id)
        init_task = process_task
    else:
        # Link from imaging to process..
        process_task = process_request.s(machine_request.id)
        imaging_task.link(process_task)
    process_task.link_error(imaging_error_task)

    # Task 4 (Optional) - Validate the image by launching a new instance
    # To skip, set ENABLE_IMAGE_VALIDATION to False

    # Final Task - email the user that their image is ready
    email_task = imaging_complete.si(machine_request.id)
    email_task.link_error(imaging_error_task)
    if getattr(settings, 'ENABLE_IMAGE_VALIDATION', True):
        init_task = enable_image_validation(machine_request, init_task, email_task, original_status, imaging_error_task)
    elif 'validating' == original_status:  # Imaging is complete if ENABLE_IMAGE_VALIDATION is false
        init_task = email_task
    else:
        process_task.link(email_task)

    # Set status to imaging ONLY if our initial task is the imaging task.
    if init_task == imaging_task:
        machine_request.old_status = 'imaging'
        machine_request.save()
    # Start the task.
    logger.info("Machine Chain : %s" % print_chain(init_task, idx=0))
    async = init_task.apply_async()
    if delay:
        async.get()
    return async
コード例 #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
    """
    new_status, _ = StatusType.objects.get_or_create(name="started")
    machine_request.status = new_status
    machine_request.save()

    original_status = machine_request.old_status
    last_run_error, original_status = machine_request._recover_from_error(
        original_status)

    if last_run_error:
        machine_request.old_status = original_status
        machine_request.save()
    instance_id = machine_request.instance.provider_alias
    identity_id = machine_request.instance.created_by_identity_id

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

    # NOTE: si == (Immutable Subtask) Ignore the result of the last task, all arguments must be passed into these tasks during creation step.
    # NOTE: s == (Subtask) Will use the result of last task as the _first argument_, arguments passed in will start from arg[1]
    imaging_error_task = machine_request_error.s(machine_request.id)

    # Task 1 - prepare the instance
    prep_instance_task = prep_instance_for_snapshot.si(identity_id,
                                                       instance_id)

    # Task 2 = Imaging w/ Chromogenic
    imaging_task = _get_imaging_task(orig_managerCls, orig_creds,
                                     dest_managerCls, dest_creds, imaging_args)
    prep_instance_task.link(imaging_task)
    imaging_task.link_error(imaging_error_task)
    # Assume we are starting from the beginning.
    init_task = prep_instance_task
    # Task 3 = Process the machine request
    if 'processing - ' in original_status:
        # If processing, start here..
        image_id = original_status.replace("processing - ", "")
        logger.info("Start with processing:%s" % image_id)
        process_task = process_request.s(image_id, machine_request.id)
        init_task = process_task
    else:
        # Link from imaging to process..
        process_task = process_request.s(machine_request.id)
        imaging_task.link(process_task)
    process_task.link_error(imaging_error_task)

    # Task 4 (Optional) - Validate the image by launching a new instance
    # To skip, set ENABLE_IMAGE_VALIDATION to False

    # Final Task - email the user that their image is ready
    email_task = imaging_complete.si(machine_request.id)
    email_task.link_error(imaging_error_task)
    if getattr(settings, 'ENABLE_IMAGE_VALIDATION', True):
        init_task = enable_image_validation(machine_request, init_task,
                                            email_task, original_status,
                                            imaging_error_task)
    elif 'validating' == original_status:  # Imaging is complete if ENABLE_IMAGE_VALIDATION is false
        init_task = email_task
    else:
        process_task.link(email_task)

    # Set status to imaging ONLY if our initial task is the imaging task.
    if init_task == imaging_task:
        machine_request.old_status = 'imaging'
        machine_request.save()
    # Start the task.
    logger.info("Machine Chain : %s" % print_chain(init_task, idx=0))
    async = init_task.apply_async()
    if delay:
        async .get()
    return async
コード例 #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
    """

    new_status, _ = StatusType.objects.get_or_create(name="started")
    machine_request.status = new_status
    machine_request.save()
    
    original_status = machine_request.old_status
    last_run_error, original_status = _recover_from_error(original_status)

    if last_run_error:
        machine_request.old_status = original_status
        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 = get_admin_driver(machine_request.new_machine_provider)
    admin_ident = machine_request.new_admin_identity()

    imaging_error_task = machine_request_error.s(machine_request.id)

    # Task 2 = Imaging w/ Chromogenic
    imaging_task = _get_imaging_task(orig_managerCls, orig_creds,
                                     dest_managerCls, dest_creds,
                                     imaging_args)
    imaging_task.link_error(imaging_error_task)
    # Assume we are starting from the beginning.
    init_task = imaging_task
    # Task 2 = Process the machine request
    if 'processing' in original_status:
        # If processing, start here..
        image_id = original_status.replace("processing - ", "")
        logger.info("Start with processing:%s" % image_id)
        process_task = process_request.s(image_id, machine_request.id)
        init_task = process_task
    else:
        # Link from imaging to process..
        process_task = process_request.s(machine_request.id)
        imaging_task.link(process_task)
    process_task.link_error(imaging_error_task)

    # Task 3 = Validate the new image by launching an instance
    if 'validating' in original_status:
        image_id = machine_request.new_machine.identifier
        celery_logger.info("Start with validating:%s" % image_id)
        # If validating, seed the image_id and start here..
        validate_task = validate_new_image.s(image_id, machine_request.id)
        init_task = validate_task
    else:
        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_instance.s(
        # NOTE: 1st arg, instance_id, passed from last task.
        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.created_by, admin_ident.uuid)
    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!
    # NOTE: si == Ignore the result of the last task.
    email_task = imaging_complete.si(machine_request.id)
    destroy_task.link_error(imaging_error_task)
    destroy_task.link(email_task)

    email_task.link_error(imaging_error_task)
    # Set status to imaging ONLY if our initial task is the imaging task.
    if init_task == imaging_task:
        machine_request.old_status = 'imaging'
        machine_request.save()
    # Start the task.
    logger.info("Machine Chain : %s" % print_chain(init_task, idx=0))
    async = init_task.apply_async()
    if delay:
        async.get()
    return async