From 674d86c7d15e407ede1406df2214b58633ca231a Mon Sep 17 00:00:00 2001 From: Bill Wei Date: Mon, 9 Jul 2018 16:23:37 -0400 Subject: [PATCH] Support cancellation for miq_request and miq_request_task --- app/models/miq_request.rb | 8 ++++++++ app/models/miq_request_task.rb | 8 ++++++++ .../service_template_transformation_plan_request.rb | 10 ++++++++++ .../service_template_transformation_plan_task.rb | 9 +++++++++ 4 files changed, 35 insertions(+) diff --git a/app/models/miq_request.rb b/app/models/miq_request.rb index 8608963093a..8fc7448d07a 100644 --- a/app/models/miq_request.rb +++ b/app/models/miq_request.rb @@ -590,6 +590,14 @@ def self.display_name(number = 1) n_('Request', 'Requests', number) end + def cancel + raise _("Cancel operation is not supported for #{self.class.name}") + end + + def canceling? + false + end + private def clean_up_keys_for_request_task diff --git a/app/models/miq_request_task.rb b/app/models/miq_request_task.rb index 07dae68f7bf..9e4e34ced49 100644 --- a/app/models/miq_request_task.rb +++ b/app/models/miq_request_task.rb @@ -206,6 +206,14 @@ def self.display_name(number = 1) n_('Request Task', 'Request Tasks', number) end + def cancel + raise _("Cancel operation is not supported for #{self.class.name}") + end + + def canceling? + false + end + private def validate_request_type diff --git a/app/models/service_template_transformation_plan_request.rb b/app/models/service_template_transformation_plan_request.rb index 5632a47f315..2026f136a4a 100644 --- a/app/models/service_template_transformation_plan_request.rb +++ b/app/models/service_template_transformation_plan_request.rb @@ -23,4 +23,14 @@ def validate_vm(_vm_id) def approve_vm(vm_id) vm_resources.find_by(:resource_id => vm_id).update_attributes!(:status => ServiceResource::STATUS_APPROVED) end + + def cancel + options['cancel_requested'] = true + save! + miq_request_tasks.each(&:cancel) + end + + def canceling? + options['cancel_requested'] + end end diff --git a/app/models/service_template_transformation_plan_task.rb b/app/models/service_template_transformation_plan_task.rb index 3e5f88f623d..ba3db479472 100644 --- a/app/models/service_template_transformation_plan_task.rb +++ b/app/models/service_template_transformation_plan_task.rb @@ -102,6 +102,15 @@ def transformation_log_queue(userid = nil) MiqTask.generic_action_with_callback(options, queue_options) end + def cancel + options['cancel_requested'] = true + save! + end + + def canceling? + options['cancel_requested'] + end + private def vm_resource