diff --git a/app/models/manageiq/providers/cloud_manager/template.rb b/app/models/manageiq/providers/cloud_manager/template.rb index 84c7f7140ba..54a7e733bef 100644 --- a/app/models/manageiq/providers/cloud_manager/template.rb +++ b/app/models/manageiq/providers/cloud_manager/template.rb @@ -20,6 +20,100 @@ def self.eligible_for_provisioning ManageIQ::Providers::Openstack::CloudManager::VolumeSnapshotTemplate)) end + def self.create_image_queue(userid, ext_management_system, options = {}) + task_opts = { + :action => "Creating Cloud Template for user #{userid}", + :userid => userid + } + + queue_opts = { + :class_name => self.class.name, + :method_name => 'create_image', + :role => 'ems_operations', + :zone => ext_management_system.my_zone, + :args => [ext_management_system.id, options] + } + MiqTask.generic_action_with_callback(task_opts, queue_opts) + end + + def self.raw_create_image(_ext_management_system, _options = {}) + raise NotImplementedError, "raw_create_image must be implemented in a subclass" + end + + def validate_create_image(_ext_management_system, _options = {}) + validate_unsupported(_("Create Image Operation")) + end + + def self.create_image(ems_id, options) + raise ArgumentError, _("ems cannot be nil") if ems_id.nil? + ext_management_system = ExtManagementSystem.find(ems_id) + raise ArgumentError, _("ems cannot be found") if ext_management_system.nil? + + klass = class_by_ems(ext_management_system) + klass.raw_create_image(ext_management_system, options) + end + + def update_image_queue(userid, options = {}) + task_opts = { + :action => "updating Cloud Template for user #{userid}", + :userid => userid + } + queue_opts = { + :class_name => self.class.name, + :method_name => 'update_image', + :instance_id => id, + :role => 'ems_operations', + :zone => ext_management_system.my_zone, + :args => [options] + } + MiqTask.generic_action_with_callback(task_opts, queue_opts) + end + + def update_image(options = {}) + raw_update_image(options) + end + + def validate_update_image + validate_unsupported("Update Image Operation") + end + + def raw_update_image(_options = {}) + raise NotImplementedError, _("raw_update_image must be implemented in a subclass") + end + + def delete_image_queue(userid) + task_opts = { + :action => "Deleting Cloud Template for user #{userid}", + :userid => userid + } + queue_opts = { + :class_name => self.class.name, + :method_name => 'delete_image', + :instance_id => id, + :role => 'ems_operations', + :zone => ext_management_system.my_zone, + :args => [] + } + MiqTask.generic_action_with_callback(task_opts, queue_opts) + end + + def raw_delete_image + raise NotImplementedError, _("raw_delete_image must be implemented in a subclass") + end + + def validate_delete_image + validate_unsupported(_("Delete Cloud Template Operation")) + end + + def delete_image + raw_delete_image + end + + def validate_unsupported(message_prefix) + {:available => false, + :message => _("%{message} is not available for %{name}.") % {:message => message_prefix, :name => name}} + end + private def raise_created_event