Skip to content

Commit

Permalink
Add sysprep support for ovirt
Browse files Browse the repository at this point in the history
Add sysprep specification support for vm provisioning from template
for the oVirt provider.

Depends on: ManageIQ/manageiq#17636
Required for: ManageIQ/manageiq-ui-classic#4211
Implements: https://bugzilla.redhat.com/show_bug.cgi?id=1553833
  • Loading branch information
Boris Odnopozov committed Aug 9, 2018
1 parent 824cb70 commit 6313933
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def configure_cloud_init
end

def configure_sysprep
content = get_option(:sysprep_upload_text)

content = sysprep_specification_selected? ? customization_template_content : get_option(:sysprep_upload_text)
return unless content
with_provider_destination { |d| d.update_sysprep!(content) }

Expand All @@ -37,9 +36,8 @@ def configure_container
configure_cpu(rhevm_vm)
configure_host_affinity(rhevm_vm)
configure_network_adapters

sysprep_option = get_option(:sysprep_enabled)
if sysprep_option == 'file'
if sysprep_option == 'file' || sysprep_specification_selected?
configure_sysprep
elsif sysprep_option == 'fields'
configure_cloud_init
Expand All @@ -49,6 +47,10 @@ def configure_container

private

def sysprep_specification_selected?
options.dig(:sysprep_enabled, 1) == "Sysprep Specification"
end

def customization_template_content
return unless customization_template
options = prepare_customization_template_substitution_options
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class ManageIQ::Providers::Redhat::InfraManager::ProvisionWorkflow < MiqProvisionInfraWorkflow
include CloudInitTemplateMixin
include SysprepTemplateMixin

def self.default_dialog_file
'miq_provision_dialogs'
Expand Down Expand Up @@ -55,7 +56,11 @@ def update_field_visibility_linked_clone(_options = {}, f)

def allowed_customization_templates(options = {})
if supports_native_clone?
allowed_cloud_init_customization_templates(options)
if get_source_vm.platform == 'windows'
allowed_sysprep_customization_templates(options)
else
allowed_cloud_init_customization_templates(options)
end
else
super(options)
end
Expand All @@ -73,8 +78,11 @@ def allowed_customization(_options = {})
result = {"disabled" => "<None>"}

case src[:vm].platform
when 'windows' then result["file"] = "Sysprep Answer File"
when 'linux' then result["fields"] = "Specification"
when 'windows'
result["file"] = "Sysprep Answer File"
result["fields"] = "Sysprep Specification"
when 'linux'
result["fields"] = "Specification"
end

result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@

expect(task.phase_context[:boot_with_sysprep]).to eq(true)
end

let(:cust_template) { FactoryGirl.create(:customization_template_sysprep, :script => "the script: <%= evm[:replace_me] %>" ) }

it "provisions sysprep from template with substitutions" do
allow(MiqRegion).to receive_message_chain(:my_region, :remote_ui_url => "1.1.1.1")
task.options[:sysprep_enabled] = ["fields", "Sysprep Specification"]
task.options[:customization_template_id] = cust_template.id
task.options[:replace_me] = "replaced!"

expect(vm_service).to receive(:update).with(OvirtSDK4::Vm.new(
:initialization => {
:custom_script => "the script: replaced!"
}
))

task.configure_sysprep
end
end

context "#configure_container" do
Expand Down Expand Up @@ -115,3 +132,4 @@
end
end
end

0 comments on commit 6313933

Please sign in to comment.