Skip to content

Commit

Permalink
Add MiqProvisionOrchWorkflow for content library template.
Browse files Browse the repository at this point in the history
  • Loading branch information
lfu committed Oct 5, 2020
1 parent b254a6a commit 2d5d54f
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
66 changes: 66 additions & 0 deletions app/models/miq_provision_orch_workflow.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class MiqProvisionOrchWorkflow < MiqProvisionVirtWorkflow
def initialize(values, requester, options = {})
initial_pass = values.blank?
initial_pass = true if options[:initial_pass] == true
instance_var_init(values, requester, options)

# Check if the caller passed the source VM as part of the initial call
if initial_pass == true
src_vm_id = get_value(@values[:src_vm_id])
unless src_vm_id.blank?
vm = OrchestrationTemplate.find_by(:id => src_vm_id)
@values[:src_vm_id] = [vm.id, vm.name] unless vm.blank?
end
end

unless options[:skip_dialog_load] == true
# If this is the first time we are called the values hash will be empty
# Also skip if we are being called from a web-service
@dialogs = get_pre_dialogs if initial_pass && options[:use_pre_dialog] != false
if @dialogs.nil?
@dialogs = get_dialogs
else
@running_pre_dialog = true if options[:use_pre_dialog] != false
end
normalize_numeric_fields unless @dialogs.nil?
end

password_helper(@values, false) # Decrypt passwords in the hash for the UI
@last_vm_id = get_value(@values[:src_vm_id]) unless initial_pass == true

return if options[:skip_dialog_load] == true

set_default_values
update_field_visibility

if get_value(values[:service_template_request])
show_dialog(:requester, :hide, "disabled")
show_dialog(:purpose, :hide, "disabled")
end
end

def get_source_and_targets(refresh = false)
return @target_resource if @target_resource && refresh == false

vm_id = get_value(@values[:src_vm_id])
rails_logger('get_source_and_targets', 0)
svm = OrchestrationTemplate.find_by(:id => vm_id)

return @target_resource = {} if svm.nil?

result = {}
result[:vm] = ci_to_hash_struct(svm)
result[:ems] = ci_to_hash_struct(svm.ext_management_system)

result
end

# Run the relationship methods and perform set intersections on the returned values.
# Optional starting set of results maybe passed in.
def allowed_ci(ci, relats, filtered_ids = nil)
return {} if get_value(@values[:placement_auto]) == true
return {} if (sources = resources_for_ui).blank?
get_ems_metadata_tree(sources)
super(ci, relats, sources, filtered_ids)
end
end
2 changes: 1 addition & 1 deletion app/models/miq_provision_virt_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def allowed_provision_types(_options = {})
def allowed_snapshots(_options = {})
result = {}
return result if (vm = get_source_vm).blank?
vm.snapshots.each { |ss| result[ss.id.to_s] = ss.current? ? "#{ss.name} (Active)" : ss.name }
vm.try(:snapshots)&.each { |ss| result[ss.id.to_s] = ss.current? ? "#{ss.name} (Active)" : ss.name }
result["__CURRENT__"] = _(" Use the snapshot that is active at time of provisioning") unless result.blank?
result
end
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/miq_request_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@
factory :miq_provision_virt_workflow_vmware,
:class => "ManageIQ::Providers::Vmware::InfraManager::ProvisionWorkflow",
:parent => :miq_provision_virt_workflow

factory :miq_provision_orch_workflow, :class => "MiqProvisionOrchWorkflow", :parent => :miq_provision_virt_workflow
end
13 changes: 13 additions & 0 deletions spec/models/miq_provision_orch_workflow_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
RSpec.describe MiqProvisionOrchWorkflow do
let(:workflow) { FactoryBot.create(:miq_provision_orch_workflow) }
let(:orch_template) { FactoryBot.create(:orchestration_template) }

context "#new" do
let(:user) { FactoryBot.create(:user_with_email) }

it "calls OrchestrationTemplate" do
expect(OrchestrationTemplate).to receive(:find_by).with(:id => orch_template.id).once
MiqProvisionOrchWorkflow.new({:src_vm_id => [orch_template.id]}, user, :skip_dialog_load => true, :initial_pass => true)
end
end
end

0 comments on commit 2d5d54f

Please sign in to comment.