From e425566552e1e3568b694cec29c4edc0210bac4c Mon Sep 17 00:00:00 2001 From: Scott Seago Date: Wed, 1 Feb 2017 10:32:57 -0500 Subject: [PATCH] Use task queue for VM actions Uses task queue instead of making direct provider API calls from the UI. The following model actions are affected: resize evacuate associate_floating_ip disassociate_floating_ip This commit contains the necessary model changes. --- .../manageiq/providers/cloud_manager/vm.rb | 53 ++++++++++++++++++- .../vm_or_template/operations/relocation.rb | 16 ++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/app/models/manageiq/providers/cloud_manager/vm.rb b/app/models/manageiq/providers/cloud_manager/vm.rb index 0b31ce0793f..cedc1d6b1cf 100644 --- a/app/models/manageiq/providers/cloud_manager/vm.rb +++ b/app/models/manageiq/providers/cloud_manager/vm.rb @@ -107,7 +107,26 @@ def cpu_percent_available? true end - def resize(new_flavor) + def resize_queue(userid, new_flavor) + task_opts = { + :action => "resizing Instance for user #{userid}", + :userid => userid + } + queue_opts = { + :class_name => self.class.name, + :method_name => 'resize', + :instance_id => id, + :role => 'ems_operations', + :zone => my_zone, + :args => [new_flavor.id] + } + MiqTask.generic_action_with_callback(task_opts, queue_opts) + end + + def resize(new_flavor_id) + raise ArgumentError, _("new_flavor_id cannot be nil") if new_flavor_id.nil? + new_flavor = Flavor.find(new_flavor_id) + raise ArgumentError, _("flavor cannot be found") if new_flavor.nil? raw_resize(new_flavor) end @@ -128,6 +147,22 @@ def raw_associate_floating_ip(_ip_address) raise NotImplementedError, _("raw_associate_floating_ip must be implemented in a subclass") end + def associate_floating_ip_queue(userid, ip_address) + task_opts = { + :action => "associating floating IP with Instance for user #{userid}", + :userid => userid + } + queue_opts = { + :class_name => self.class.name, + :method_name => 'associate_floating_ip', + :instance_id => id, + :role => 'ems_operations', + :zone => my_zone, + :args => [ip_address] + } + MiqTask.generic_action_with_callback(task_opts, queue_opts) + end + def associate_floating_ip(ip_address) raw_associate_floating_ip(ip_address) end @@ -136,6 +171,22 @@ def raw_disassociate_floating_ip(_ip_address) raise NotImplementedError, _("raw_disassociate_floating_ip must be implemented in a subclass") end + def disassociate_floating_ip_queue(userid, ip_address) + task_opts = { + :action => "disassociating floating IP with Instance for user #{userid}", + :userid => userid + } + queue_opts = { + :class_name => self.class.name, + :method_name => 'disassociate_floating_ip', + :instance_id => id, + :role => 'ems_operations', + :zone => my_zone, + :args => [ip_address] + } + MiqTask.generic_action_with_callback(task_opts, queue_opts) + end + def disassociate_floating_ip(ip_address) raw_disassociate_floating_ip(ip_address) end diff --git a/app/models/vm_or_template/operations/relocation.rb b/app/models/vm_or_template/operations/relocation.rb index 0b94fa463a6..aebaa6f28ff 100644 --- a/app/models/vm_or_template/operations/relocation.rb +++ b/app/models/vm_or_template/operations/relocation.rb @@ -11,6 +11,22 @@ def raw_evacuate(_options = nil) raise NotImplementedError, _("raw_evacuate must be implemented in a subclass") end + def evacuate_queue(userid, options) + task_opts = { + :action => "evacuating VM for user #{userid}", + :userid => userid + } + queue_opts = { + :class_name => self.class.name, + :method_name => 'evacuate', + :instance_id => id, + :role => 'ems_operations', + :zone => my_zone, + :args => [options] + } + MiqTask.generic_action_with_callback(task_opts, queue_opts) + end + def evacuate(options = {}) raw_evacuate(options) end