Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add crud for Template #17217

Merged
merged 1 commit into from
Apr 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions app/models/manageiq/providers/cloud_manager/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down