def restore_ip_chain(esh_driver, esh_instance, redeploy=False, core_identity_uuid=None): """ Returns: a task, chained together task chain: wait_for("active") --> AddFixed --> AddFloating --> reDeploy start with: task.apply_async() """ from service.tasks.driver import \ wait_for_instance, add_fixed_ip, add_floating_ip, deploy_init_to init_task = wait_for_instance.s( esh_instance.id, esh_driver.__class__, esh_driver.provider, esh_driver.identity, "active", #TODO: DELETEME below. no_tasks=True) #Step 1: Add fixed fixed_ip_task = add_fixed_ip.si( esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id, core_identity_uuid) init_task.link(fixed_ip_task) #Add float and re-deploy OR just add floating IP... if redeploy: deploy_task = deploy_init_to.si(esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id, redeploy=True) fixed_ip_task.link(deploy_task) else: logger.info("Skip deployment, Add floating IP only") floating_ip_task = add_floating_ip.si(esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id) fixed_ip_task.link(floating_ip_task) return init_task
def restore_ip_chain(esh_driver, esh_instance, redeploy=False, core_identity_uuid=None): """ Returns: a task, chained together task chain: wait_for("active") --> AddFixed --> AddFloating --> reDeploy start with: task.apply_async() """ from service.tasks.driver import \ wait_for_instance, add_fixed_ip, add_floating_ip, deploy_init_to init_task = wait_for_instance.s( esh_instance.id, esh_driver.__class__, esh_driver.provider, esh_driver.identity, "active", #TODO: DELETEME below. no_tasks=True) #Step 1: Add fixed fixed_ip_task = add_fixed_ip.si( esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id, core_identity_uuid) init_task.link(fixed_ip_task) #Add float and re-deploy OR just add floating IP... if redeploy: deploy_task = deploy_init_to.si(esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id, redeploy=True) fixed_ip_task.link(deploy_task) else: logger.info("Skip deployment, Add floating IP only") floating_ip_task = add_floating_ip.si(esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id) fixed_ip_task.link(floating_ip_task) return init_task
def resize_and_redeploy(esh_driver, esh_instance, core_identity_uuid): """ TODO: Remove this and use the 'deploy_init' tasks already written instead! -Steve 2/2015 Use this function to kick off the async task when you ONLY want to deploy (No add fixed, No add floating) """ from service.tasks.driver import deploy_init_to, deploy_script from service.tasks.driver import wait_for_instance, complete_resize from service.deploy import deploy_test touch_script = deploy_test() core_identity = CoreIdentity.objects.get(uuid=core_identity_uuid) task_one = wait_for_instance.s( esh_instance.id, esh_driver.__class__, esh_driver.provider, esh_driver.identity, "verify_resize") task_two = deploy_script.si( esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id, touch_script) task_three = complete_resize.si( esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id, core_identity.provider.id, core_identity.id, core_identity.created_by) task_four = deploy_init_to.si( esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id, redeploy=True) #Link em all together! task_one.link(task_two) task_two.link(task_three) task_three.link(task_four) return task_one
def resize_and_redeploy(esh_driver, esh_instance, core_identity_uuid): """ Use this function to kick off the async task when you ONLY want to deploy (No add fixed, No add floating) """ from service.tasks.driver import deploy_init_to, deploy_script from service.tasks.driver import wait_for_instance, complete_resize from service.deploy import deploy_test touch_script = deploy_test() core_identity = CoreIdentity.objects.get(uuid=core_identity_uuid) task_one = wait_for_instance.s( esh_instance.id, esh_driver.__class__, esh_driver.provider, esh_driver.identity, "verify_resize") task_two = deploy_script.si( esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id, touch_script) task_three = complete_resize.si( esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id, core_identity.provider.id, core_identity.id, core_identity.created_by) task_four = deploy_init_to.si( esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id, redeploy=True) #Link em all together! task_one.link(task_two) task_two.link(task_three) task_three.link(task_four) #TODO: Add an appropriate link_error and track/handle failures. return task_one
def enable_image_validation(machine_request, init_task, final_task, original_status="", error_handler_task=None): if not error_handler_task: error_handler_task = machine_request_error.s(machine_request.id) # Task 3 = Validate the new image by launching an instance admin_ident = machine_request.new_admin_identity() admin_driver = get_admin_driver(machine_request.new_machine_provider) if 'validating' == 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) init_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(error_handler_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(error_handler_task) destroy_task.link_error(error_handler_task) destroy_task.link(final_task) return init_task
def enable_image_validation(machine_request, init_task, final_task, original_status="", error_handler_task=None): if not error_handler_task: error_handler_task = machine_request_error.s(machine_request.id) # Task 3 = Validate the new image by launching an instance admin_ident = machine_request.new_admin_identity() admin_driver = get_admin_driver(machine_request.new_machine_provider) 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) init_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(error_handler_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(error_handler_task) destroy_task.link_error(error_handler_task) destroy_task.link(final_task) return init_task
def _repair_instance_networking( esh_driver, esh_instance, provider_uuid, identity_uuid): from service.tasks.driver import \ add_floating_ip, wait_for_instance, \ deploy_init_to, deploy_failed, update_metadata logger.info("Instance %s needs to create and attach port instead" % esh_instance.id) core_identity = CoreIdentity.objects.get(uuid=identity_uuid) provider = Provider.objects.get(uuid=provider_uuid) logger.info("Attaching interface manually, Instance %s" % esh_instance.id) attached_intf = _create_and_attach_port(provider, esh_driver, esh_instance, core_identity) logger.info("Attached Interface: %s" % attached_intf) logger.info("Adding floating IP manually, Instance %s" % esh_instance.id) add_floating_ip(esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id) logger.info("Instance %s needs to hard reboot instead of resume" % esh_instance.id) esh_driver.reboot_instance(esh_instance, 'HARD') # Custom task-chain.. Wait for active then redeploy scripts #(Adding IP is done).. Then remove metadata init_task = wait_for_instance.s( esh_instance.id, esh_driver.__class__, esh_driver.provider, esh_driver.identity, "active") deploy_task = deploy_init_to.si(esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id, redeploy=True) deploy_task.link_error( deploy_failed.s(esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id)) final_update = esh_instance.extra['metadata'] final_update.pop('tmp_status', None) final_update.pop('iplant_suspend_fix', None) remove_status_task = update_metadata.si( esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id, final_update, replace_metadata=True) deploy_task.link(remove_status_task) # Attempt to redeploy after the restart.. init_task.link(deploy_task) init_task.apply_async() return
def _repair_instance_networking(esh_driver, esh_instance, provider_uuid, identity_uuid): from service.tasks.driver import \ add_floating_ip, wait_for_instance, \ deploy_init_to, deploy_failed, update_metadata logger.info("Instance %s needs to create and attach port instead" % esh_instance.id) core_identity = CoreIdentity.objects.get(uuid=identity_uuid) provider = Provider.objects.get(uuid=provider_uuid) logger.info("Attaching interface manually, Instance %s" % esh_instance.id) attached_intf = _create_and_attach_port(provider, esh_driver, esh_instance, core_identity) logger.info("Attached Interface: %s" % attached_intf) logger.info("Adding floating IP manually, Instance %s" % esh_instance.id) add_floating_ip(esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id) logger.info("Instance %s needs to hard reboot instead of resume" % esh_instance.id) esh_driver.reboot_instance(esh_instance,'HARD') #Custom task-chain.. Wait for active then redeploy scripts #(Adding IP is done).. Then remove metadata init_task = wait_for_instance.s( esh_instance.id, esh_driver.__class__, esh_driver.provider, esh_driver.identity, "active") deploy_task = deploy_init_to.si(esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id, redeploy=True) deploy_task.link_error( deploy_failed.s(esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id)) final_update = esh_instance.extra['metadata'] final_update.pop('tmp_status') final_update.pop('iplant_suspend_fix') remove_status_task = update_metadata.si( esh_driver.__class__, esh_driver.provider, esh_driver.identity, esh_instance.id, final_update, replace_metadata=True) deploy_task.link(remove_status_task) #Attempt to redeploy after the restart.. init_task.link(deploy_task) init_task.apply_async() return
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. async = init_task.apply_async() if delay: async .get() return async
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.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. async = init_task.apply_async() if delay: async.get() return async