Skip to content

Commit

Permalink
Add crud for Template
Browse files Browse the repository at this point in the history
  • Loading branch information
andyvesel committed Mar 28, 2018
1 parent 7b65536 commit becc3fe
Showing 1 changed file with 94 additions and 0 deletions.
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

0 comments on commit becc3fe

Please sign in to comment.