From b9469bf497536e80e0b6a74e990b387e2d71c433 Mon Sep 17 00:00:00 2001 From: fdupont-redhat Date: Wed, 23 May 2018 14:49:59 +0200 Subject: [PATCH 01/12] Add V2V code for gaprindashvili-3 release --- .../__methods__/weightedupdatestatus.rb | 140 +++++++++++++ .../__methods__/weightedupdatestatus.yaml | 73 +++++++ .../Cloud/VM/Common.class/__class__.yaml | 33 +++ .../Cloud/VM/Common.class/_missing.yaml | 12 ++ .../Cloud/VM/__namespace__.yaml | 10 + .../Cloud/VM/azure.class/__class__.yaml | 33 +++ .../Cloud/VM/azure.class/_missing.yaml | 12 ++ .../Cloud/VM/openstack.class/__class__.yaml | 33 +++ .../VM/openstack.class/__methods__/utils.rb | 17 ++ .../VM/openstack.class/__methods__/utils.yaml | 13 ++ .../Cloud/VM/openstack.class/_missing.yaml | 12 ++ .../Transformation/Cloud/__namespace__.yaml | 10 + .../Common.class/__class__.yaml | 33 +++ .../__methods__/acquiretransformationhost.rb | 49 +++++ .../acquiretransformationhost.yaml | 15 ++ .../__methods__/assesstransformation.rb | 89 ++++++++ .../__methods__/assesstransformation.yaml | 13 ++ .../Transformation/Common.class/_missing.yaml | 12 ++ .../VM/Common.class/__class__.yaml | 33 +++ .../VM/Common.class/__methods__/poweroff.rb | 48 +++++ .../VM/Common.class/__methods__/poweroff.yaml | 13 ++ .../VM/Common.class/__methods__/poweron.rb | 32 +++ .../VM/Common.class/__methods__/poweron.yaml | 13 ++ .../VM/Common.class/_missing.yaml | 12 ++ .../Infrastructure/VM/__namespace__.yaml | 10 + .../VM/rhevm.class/__class__.yaml | 33 +++ .../rhevm.class/__methods__/checkpoweredon.rb | 38 ++++ .../__methods__/checkpoweredon.yaml | 15 ++ .../__methods__/checkvmininventory.rb | 57 ++++++ .../__methods__/checkvmininventory.yaml | 15 ++ .../__methods__/enablevirtioscsi.rb | 33 +++ .../__methods__/enablevirtioscsi.yaml | 15 ++ .../rhevm.class/__methods__/setdescription.rb | 35 ++++ .../__methods__/setdescription.yaml | 15 ++ .../VM/rhevm.class/__methods__/utils.rb | 190 ++++++++++++++++++ .../VM/rhevm.class/__methods__/utils.yaml | 13 ++ .../VM/rhevm.class/_missing.yaml | 12 ++ .../VM/vmwarews.class/__class__.yaml | 33 +++ .../__methods__/collapsesnapshots.rb | 41 ++++ .../__methods__/collapsesnapshots.yaml | 15 ++ .../vmwarews.class/__methods__/setmigrated.rb | 55 +++++ .../__methods__/setmigrated.yaml | 15 ++ .../VM/vmwarews.class/__methods__/utils.rb | 100 +++++++++ .../VM/vmwarews.class/__methods__/utils.yaml | 13 ++ .../VM/vmwarews.class/_missing.yaml | 12 ++ .../Infrastructure/__namespace__.yaml | 10 + .../transformation.yaml | 37 ++-- .../vmwarews2rhevm_vddk.yaml | 94 ++++----- .../Common.class/__methods__/utils.rb | 58 ++++++ .../Common.class/__methods__/utils.yaml | 13 ++ .../ovirt_host.class/__methods__/rolecheck.rb | 27 +++ .../__methods__/rolecheck.yaml | 39 +--- .../__methods__/roledisable.rb | 28 +++ .../__methods__/roledisable.yaml | 17 +- .../__methods__/roleenable.rb | 35 ++++ .../__methods__/roleenable.yaml | 159 +-------------- .../ovirt_host.class/__methods__/utils.rb | 77 +++++++ .../ovirt_host.class/__methods__/utils.yaml | 13 ++ .../vmchecktransformed_vmwarews2rhevm_vddk.rb | 90 +++++++++ ...mchecktransformed_vmwarews2rhevm_vddk.yaml | 15 ++ .../vmtransform_vmwarews2rhevm_vddk.rb | 110 ++++++++++ .../vmtransform_vmwarews2rhevm_vddk.yaml | 17 ++ 62 files changed, 2090 insertions(+), 274 deletions(-) create mode 100644 content/automate/ManageIQ/System/CommonMethods/MiqAe.class/__methods__/weightedupdatestatus.rb create mode 100644 content/automate/ManageIQ/System/CommonMethods/MiqAe.class/__methods__/weightedupdatestatus.yaml create mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/Common.class/__class__.yaml create mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/Common.class/_missing.yaml create mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/__namespace__.yaml create mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/azure.class/__class__.yaml create mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/azure.class/_missing.yaml create mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__class__.yaml create mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__methods__/utils.rb create mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__methods__/utils.yaml create mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/_missing.yaml create mode 100644 content/automate/ManageIQ/Transformation/Cloud/__namespace__.yaml create mode 100644 content/automate/ManageIQ/Transformation/Common.class/__class__.yaml create mode 100644 content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.rb create mode 100644 content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.yaml create mode 100644 content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb create mode 100644 content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.yaml create mode 100644 content/automate/ManageIQ/Transformation/Common.class/_missing.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__class__.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweroff.rb create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweroff.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.rb create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/_missing.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/__namespace__.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__class__.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkpoweredon.rb create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkpoweredon.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkvmininventory.rb create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkvmininventory.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.rb create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/setdescription.rb create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/setdescription.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/utils.rb create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/utils.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/_missing.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__class__.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/collapsesnapshots.rb create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/collapsesnapshots.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/setmigrated.rb create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/setmigrated.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.rb create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/_missing.yaml create mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/__namespace__.yaml create mode 100644 content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.rb create mode 100644 content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.yaml create mode 100644 content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.rb create mode 100644 content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roledisable.rb create mode 100644 content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roleenable.rb create mode 100644 content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/utils.rb create mode 100644 content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/utils.yaml create mode 100644 content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb create mode 100644 content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.yaml create mode 100644 content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb create mode 100644 content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.yaml diff --git a/content/automate/ManageIQ/System/CommonMethods/MiqAe.class/__methods__/weightedupdatestatus.rb b/content/automate/ManageIQ/System/CommonMethods/MiqAe.class/__methods__/weightedupdatestatus.rb new file mode 100644 index 000000000..7ea2f7182 --- /dev/null +++ b/content/automate/ManageIQ/System/CommonMethods/MiqAe.class/__methods__/weightedupdatestatus.rb @@ -0,0 +1,140 @@ +module ManageIQ + module Automate + module System + module CommonMethods + module MiqAe + class WeightedUpdateStatus + def initialize(handle = $evm) + @handle = handle + end + + # This method gets the current state, even in the context of nested + # state machines. Where running a nested state machines, there can be + # more than one active states: one per level of nesting. The real + # active state is the one with the deepest ancestry. + def current_state(states) + active_states = states.select { |_, v| v['status'] == 'active' }.keys + states_depth = active_states.map { |state| state.split('/').length } + active_states[states_depth.index(states_depth.max)] + end + + # This method recusrively collects the progress of children states + # and weight them, to finally weight the result with the current state + # weight. + def reconcile_states_percent(path, states) + direct_children = states.reject { |k, _| k.gsub(/^#{path}\//, '').include?('/') } + return states[path]['percent'] if direct_children.empty? + percent = 0 + direct_children.each_key { |dc_path| percent += reconcile_states_percent(dc_path, states).to_f * states[dc_path]['weight'].to_f / 100.0 } + percent + end + + def on_entry(state_hash, _, _, state_weight, state_description) + # Initiate the state hash if it doesn't exist yet + state_hash ||= { 'status' => 'active', 'weight' => state_weight, 'description' => state_description, 'message' => state_description } + # Add the start date and set percentage to 0 if entering the + # state for the first time (retries count == 0) + if @handle.root['ae_state_retries'].to_i.zero? + state_hash['started_on'] = Time.now.utc + state_hash['percent'] = 0.0 + end + state_hash + end + + def on_exit(state_hash, state_progress, state_name, _, _) + # If the state is retrying, we leave the status to 'active'. + if @handle.root['ae_result'] == 'retry' + # If the method provides progress info, it is merged, otherwise we set + # it based on current retry and max retries. + if state_progress.nil? + state_hash['message'] = "#{state_name} is not finished yet [#{@handle.root['ae_state_retries']}/#{@handle.root['ae_state_max_retries']} retries]." + state_hash['percent'] = @handle.root['ae_state_retries'].to_f / @handle.root['ae_state_max_retries'].to_f * 100.0 + else + # We also merge the potential message from method. + state_hash.merge!(state_progress) + end + # If we don't retry, it means that the state is finished, so We also merge + # the potential message from method. + else + # We set status to 'finished' and percentage to 100. + state_hash['status'] = 'finished' + state_hash['percent'] = 100.0 + state_hash['message'] = state_progress.nil? ? "#{state_name} is finished." : state_progress['message'] + end + # Then, we set the update time to now, which is also finish time + # when the state is finished. + state_hash['updated_on'] = Time.now.utc + state_hash + end + + def on_error(state_hash, state_progress, _, _, state_description) + # The state has failed, so we consider it as finished and 100%. + state_hash['status'] = 'failed' + state_hash['percent'] = 100.0 + # We merge the potential message from method and set the update time. + state_hash['message'] = state_progress.nil? ? "Failed to #{state_description}." : state_progress['message'] + state_hash['updated_on'] = Time.now.utc + state_hash + end + + def main + vmdb_object_type = @handle.root['vmdb_object_type'] + if vmdb_object_type =~ /^service_template_[\w\d]+_task$/ + task = @handle.root[vmdb_object_type] + raise @handle.root.attributes.inspect if task.nil? + unless task.nil? + # Initiate the task progress hash if it doesn't exist yet + progress = task.get_option(:progress) || { 'current_state' => '', 'current_description' => '', 'percent' => 0.0, 'states' => {} } + + # Collect the state details + state_name = @handle.root['ae_state'] + state_ancestry = @handle.object['state_ancestry'].to_s + state_description = @handle.inputs['description'] || state_name + state_weight = @handle.inputs['weight'] || 0 + + # Updating the current state hash with method progress + state_hash = send( + @handle.root['ae_state_step'], + progress['states']["#{state_ancestry}/#{state_name}"], + @handle.get_state_var('ae_state_progress'), + state_name, + state_weight, + state_description + ) + @handle.log(:info, "State Hash: #{state_hash.inspect}") + + # We record the state hash in the task progress + progress['states']["#{state_ancestry}/#{state_name}"] = state_hash + # If we enter the state, we update the task progress with current + # state and description. + if @handle.root['ae_status_state'] == 'on_entry' + progress['current_state'] = current_state(progress['states']) + progress['current_description'] = progress['states'][progress['current_state']]['description'] + # End if we exit/error the state, we update the percentage based on + # children states and current state weight. + else + progress['percent'] = reconcile_states_percent('', progress['states']).round(2) + end + # We clear the ae_state_progress state var + @handle.set_state_var('ae_state_progress', nil) + # We record the progress as a task option. + task.update_transformation_progress(progress) + # We set the task message. + if @handle.root['ae_state_step'] == 'on_error' + task.message = 'Failed' + else + task.message = @handle.inputs['task_message'] unless @handle.inputs['task_message'] == '_' + end + end + end + end + end + end + end + end + end +end + +if $PROGRAM_NAME == __FILE__ + ManageIQ::Automate::System::CommonMethods::MiqAe::WeightedUpdateStatus.new.main +end diff --git a/content/automate/ManageIQ/System/CommonMethods/MiqAe.class/__methods__/weightedupdatestatus.yaml b/content/automate/ManageIQ/System/CommonMethods/MiqAe.class/__methods__/weightedupdatestatus.yaml new file mode 100644 index 000000000..ea013aa6c --- /dev/null +++ b/content/automate/ManageIQ/System/CommonMethods/MiqAe.class/__methods__/weightedupdatestatus.yaml @@ -0,0 +1,73 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: WeightedUpdateStatus + display_name: + description: + scope: instance + language: ruby + location: inline + options: {} + inputs: + - field: + aetype: + name: weight + display_name: + datatype: integer + priority: 1 + owner: + default_value: '0' + substitute: false + message: create + visibility: + collect: + scope: + description: + condition: + on_entry: + on_exit: + on_error: + max_retries: + max_time: + - field: + aetype: + name: description + display_name: + datatype: string + priority: 2 + owner: + default_value: _ + substitute: false + message: create + visibility: + collect: + scope: + description: + condition: + on_entry: + on_exit: + on_error: + max_retries: + max_time: + - field: + aetype: + name: task_message + display_name: + datatype: + priority: 3 + owner: + default_value: _ + substitute: false + message: create + visibility: + collect: + scope: + description: + condition: + on_entry: + on_exit: + on_error: + max_retries: + max_time: diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/Common.class/__class__.yaml b/content/automate/ManageIQ/Transformation/Cloud/VM/Common.class/__class__.yaml new file mode 100644 index 000000000..b7fe6fdbf --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Cloud/VM/Common.class/__class__.yaml @@ -0,0 +1,33 @@ +--- +object_type: class +version: 1.0 +object: + attributes: + description: + display_name: + name: Common + type: + inherits: + visibility: + owner: + schema: + - field: + aetype: method + name: execute + display_name: + datatype: + priority: 1 + owner: + default_value: + substitute: true + message: create + visibility: + collect: + scope: + description: + condition: + on_entry: + on_exit: + on_error: + max_retries: + max_time: diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/Common.class/_missing.yaml b/content/automate/ManageIQ/Transformation/Cloud/VM/Common.class/_missing.yaml new file mode 100644 index 000000000..31e5fff8b --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Cloud/VM/Common.class/_missing.yaml @@ -0,0 +1,12 @@ +--- +object_type: instance +version: 1.0 +object: + attributes: + display_name: + name: ".missing" + inherits: + description: + fields: + - execute: + value: "${#_missing_instance}" diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/__namespace__.yaml b/content/automate/ManageIQ/Transformation/Cloud/VM/__namespace__.yaml new file mode 100644 index 000000000..56812dc20 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Cloud/VM/__namespace__.yaml @@ -0,0 +1,10 @@ +--- +object_type: namespace +version: 1.0 +object: + attributes: + name: VM + description: + display_name: + priority: + enabled: diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/azure.class/__class__.yaml b/content/automate/ManageIQ/Transformation/Cloud/VM/azure.class/__class__.yaml new file mode 100644 index 000000000..283a84c09 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Cloud/VM/azure.class/__class__.yaml @@ -0,0 +1,33 @@ +--- +object_type: class +version: 1.0 +object: + attributes: + description: + display_name: Azure + name: azure + type: + inherits: + visibility: + owner: + schema: + - field: + aetype: method + name: execute + display_name: + datatype: + priority: 1 + owner: + default_value: + substitute: true + message: create + visibility: + collect: + scope: + description: + condition: + on_entry: + on_exit: + on_error: + max_retries: + max_time: diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/azure.class/_missing.yaml b/content/automate/ManageIQ/Transformation/Cloud/VM/azure.class/_missing.yaml new file mode 100644 index 000000000..31e5fff8b --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Cloud/VM/azure.class/_missing.yaml @@ -0,0 +1,12 @@ +--- +object_type: instance +version: 1.0 +object: + attributes: + display_name: + name: ".missing" + inherits: + description: + fields: + - execute: + value: "${#_missing_instance}" diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__class__.yaml b/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__class__.yaml new file mode 100644 index 000000000..6978e9065 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__class__.yaml @@ -0,0 +1,33 @@ +--- +object_type: class +version: 1.0 +object: + attributes: + description: + display_name: Openstack + name: openstack + type: + inherits: + visibility: + owner: + schema: + - field: + aetype: method + name: execute + display_name: + datatype: + priority: 1 + owner: + default_value: + substitute: true + message: create + visibility: + collect: + scope: + description: + condition: + on_entry: + on_exit: + on_error: + max_retries: + max_time: diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__methods__/utils.rb b/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__methods__/utils.rb new file mode 100644 index 000000000..97d00329f --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__methods__/utils.rb @@ -0,0 +1,17 @@ +module ManageIQ + module Automate + module Transformation + module Cloud + module VM + module OpenStack + class Utils + + + end + end + end + end + end + end +end + diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__methods__/utils.yaml b/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__methods__/utils.yaml new file mode 100644 index 000000000..94612ce92 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__methods__/utils.yaml @@ -0,0 +1,13 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: Utils + display_name: + description: + scope: instance + language: ruby + location: inline + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/_missing.yaml b/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/_missing.yaml new file mode 100644 index 000000000..31e5fff8b --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/_missing.yaml @@ -0,0 +1,12 @@ +--- +object_type: instance +version: 1.0 +object: + attributes: + display_name: + name: ".missing" + inherits: + description: + fields: + - execute: + value: "${#_missing_instance}" diff --git a/content/automate/ManageIQ/Transformation/Cloud/__namespace__.yaml b/content/automate/ManageIQ/Transformation/Cloud/__namespace__.yaml new file mode 100644 index 000000000..66f0a2a4a --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Cloud/__namespace__.yaml @@ -0,0 +1,10 @@ +--- +object_type: namespace +version: 1.0 +object: + attributes: + name: Cloud + description: + display_name: + priority: + enabled: diff --git a/content/automate/ManageIQ/Transformation/Common.class/__class__.yaml b/content/automate/ManageIQ/Transformation/Common.class/__class__.yaml new file mode 100644 index 000000000..b7fe6fdbf --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Common.class/__class__.yaml @@ -0,0 +1,33 @@ +--- +object_type: class +version: 1.0 +object: + attributes: + description: + display_name: + name: Common + type: + inherits: + visibility: + owner: + schema: + - field: + aetype: method + name: execute + display_name: + datatype: + priority: 1 + owner: + default_value: + substitute: true + message: create + visibility: + collect: + scope: + description: + condition: + on_entry: + on_exit: + on_error: + max_retries: + max_time: diff --git a/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.rb b/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.rb new file mode 100644 index 000000000..7652e7324 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.rb @@ -0,0 +1,49 @@ +module ManageIQ + module Automate + module Transformation + module Common + class AcquireTransformationHost + def initialize(handle = $evm) + @handle = handle + end + + def main + begin + factory_config = @handle.get_state_var(:factory_config) + raise "No factory config found. Aborting." if factory_config.nil? + + task = @handle.root['service_template_transformation_plan_task'] + @handle.log(:info, "Task: #{task.inspect}") + source_vm = task.source + @handle.log(:info, "Source VM: #{source_vm.name}") + source_cluster = source_vm.ems_cluster + @handle.log(:info, "Source Cluster: #{source_cluster.name}") + @handle.log(:info, "Destination Cluster: #{task.transformation_destination(source_cluster).name}") + destination_ems = task.transformation_destination(source_cluster).ext_management_system + raise "Invalid destination EMS type: #{destination_ems.emstype}. Aborting." unless destination_ems.emstype == "rhevm" + + transformation_host = ManageIQ::Automate::Transformation::TransformationHosts::Common::Utils.get_transformation_host(destination_ems, 'vddk', factory_config) + if transformation_host.nil? + @handle.log(:info, "No transformation host available. Retrying.") + @handle.root['ae_result'] = 'retry' + @handle.root['ae_retry_server_affinity'] = true + @handle.root['ae_retry_interval'] = $evm.object['check_convert_interval'] || '1.minutes' + else + @handle.log(:info, "Transformation Host: #{transformation_host.name}.") + task.set_option(:transformation_host_id, transformation_host.id) + task.set_option(:transformation_host_name, transformation_host.name) + end + rescue Exception => e + @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + raise + end + end + end + end + end + end +end + +if $PROGRAM_NAME == __FILE__ + ManageIQ::Automate::Transformation::Common::AcquireTransformationHost.new.main +end diff --git a/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.yaml b/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.yaml new file mode 100644 index 000000000..7f20ae1d7 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.yaml @@ -0,0 +1,15 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: AcquireTransformationHost + display_name: + description: + scope: instance + language: ruby + location: inline + embedded_methods: + - "/Transformation/TransformationHosts/Common/Utils" + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb b/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb new file mode 100644 index 000000000..7eca004ac --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb @@ -0,0 +1,89 @@ +module ManageIQ + module Automate + module Transformation + module Common + class AssessTransformation + SUPPORTED_SOURCE_EMS_TYPES = ['vmwarews'].freeze + SUPPORTED_DESTINATION_EMS_TYPES = ['rhevm'].freeze + REQUIRED_CUSTOM_ATTRIBUTES = { + 'rhevm' => [:rhv_export_domain_id, :rhv_cluster_id, :rhv_storage_domain_id] + }.freeze + + def initialize(handle = $evm) + @handle = handle + end + + def main + begin + task = @handle.root['service_template_transformation_plan_task'] + raise 'No task found. Exiting' if task.nil? + @handle.log(:info, "Task: #{task.inspect}") if @debug + + source_vm ||= task.source + raise 'No VM found. Exiting' if source_vm.nil? + + source_cluster = source_vm.ems_cluster + destination_cluster = task.transformation_destination(source_cluster) + raise "No destination cluster for '#{source_vm.name}'. Exiting." if destination_cluster.nil? + + source_ems = source_vm.ext_management_system + destination_ems = destination_cluster.ext_management_system + + virtv2v_networks = [] + source_vm.hardware.nics.select { |n| n.device_type == 'ethernet' }.each do |nic| + source_network = nic.lan + destination_network = task.transformation_destination(source_network) + raise "[#{source_vm.name}] NIC #{nic.device_name} [#{source_network.name}] has no mapping. Aborting." if destination_network.nil? + virtv2v_networks << { source: source_network.name, destination: destination_network.name } + end + @handle.log(:info, "Network mappings: #{virtv2v_networks}") + task.set_option(:virtv2v_networks, virtv2v_networks) + + virtv2v_disks = [] + source_vm.hardware.disks.select { |d| d.device_type == 'disk' }.each do |disk| + source_storage = disk.storage + destination_storage = task.transformation_destination(disk.storage) + raise "[#{source_vm.name}] Disk #{disk.device_name} [#{source_storage.name}] has no mapping. Aborting." if destination_storage.nil? + virtv2v_disks << { path: disk.filename, size: disk.size, percent: 0, weight: disk.size / source_vm.allocated_disk_storage * 100 } + end + @handle.log(:info, "Source VM Disks #{virtv2v_disks}") + task.set_option(:virtv2v_disks, virtv2v_disks) + + raise "Unsupported source EMS type: #{source_ems.emstype}." unless SUPPORTED_SOURCE_EMS_TYPES.include?(source_ems.emstype) + @handle.set_state_var(:source_ems_type, source_ems.emstype) + + raise "Unsupported destination EMS type: #{destination_ems.emstype}." unless SUPPORTED_DESTINATION_EMS_TYPES.include?(destination_ems.emstype) + @handle.set_state_var(:destination_ems_type, destination_ems.emstype) + + transformation_type = "#{source_ems.emstype}2#{destination_ems.emstype}" + @handle.set_state_var(:transformation_type, transformation_type) + + transformation_method = "vddk" + @handle.set_state_var(:transformation_method, transformation_method) + + transformation_host_type = "ovirt_host" + @handle.set_state_var(:transformation_host_type, transformation_host_type) + + factory_config = { + 'vmtransformation_check_interval' => @handle.object['vmtransformation_check_interval'] || '15.seconds', + 'vmpoweroff_check_interval' => @handle.object['vmpoweroff_check_interval'] || '30.seconds' + } + @handle.set_state_var(:factory_config, factory_config) + + # Force VM shutdown and snapshots collapse by default + task.set_option(:collapse_snapshots, true) + task.set_option(:power_off, true) + rescue Exception => e + @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + raise + end + end + end + end + end + end +end + +if $PROGRAM_NAME == __FILE__ + ManageIQ::Automate::Transformation::Common::AssessTransformation.new.main +end diff --git a/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.yaml b/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.yaml new file mode 100644 index 000000000..bdbb37b38 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.yaml @@ -0,0 +1,13 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: AssessTransformation + display_name: + description: + scope: instance + language: ruby + location: inline + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/Common.class/_missing.yaml b/content/automate/ManageIQ/Transformation/Common.class/_missing.yaml new file mode 100644 index 000000000..31e5fff8b --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Common.class/_missing.yaml @@ -0,0 +1,12 @@ +--- +object_type: instance +version: 1.0 +object: + attributes: + display_name: + name: ".missing" + inherits: + description: + fields: + - execute: + value: "${#_missing_instance}" diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__class__.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__class__.yaml new file mode 100644 index 000000000..b7fe6fdbf --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__class__.yaml @@ -0,0 +1,33 @@ +--- +object_type: class +version: 1.0 +object: + attributes: + description: + display_name: + name: Common + type: + inherits: + visibility: + owner: + schema: + - field: + aetype: method + name: execute + display_name: + datatype: + priority: 1 + owner: + default_value: + substitute: true + message: create + visibility: + collect: + scope: + description: + condition: + on_entry: + on_exit: + on_error: + max_retries: + max_time: diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweroff.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweroff.rb new file mode 100644 index 000000000..e381b0297 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweroff.rb @@ -0,0 +1,48 @@ +module ManageIQ + module Automate + module Transformation + module Infrastructure + module VM + module Common + class PowerOff + def initialize(handle = $evm) + @handle = handle + end + + def main + begin + task = @handle.root['service_template_transformation_plan_task'] + source_vm = task.source + + if source_vm.power_state == 'off' + @handle.log(:info, "VM '#{source_vm.name}' is already off. Nothing to do.") + else + if task.get_option(:power_off) + @handle.log(:info, "VM '#{source_vm.name} is powered on. Let's shut it down.") + if @handle.state_var_exist?(:vm_shutdown_in_progress) + source_vm.stop if @handle.root['ae_state_retries'].to_i > 10 + else + source_vm.shutdown_guest + @handle.set_state_var(:vm_shutdown_in_progress, true) + end + @handle.root['ae_result'] = 'retry' + else + raise "VM '#{source_vm.name} is powered on, but we are not allowed to shut it down. Aborting." + end + end + rescue Exception => e + @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + raise + end + end + end + end + end + end + end + end +end + +if $PROGRAM_NAME == __FILE__ + ManageIQ::Automate::Transformation::Infrastructure::VM::Common::PowerOff.new.main +end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweroff.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweroff.yaml new file mode 100644 index 000000000..57c96587a --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweroff.yaml @@ -0,0 +1,13 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: PowerOff + display_name: + description: + scope: instance + language: ruby + location: inline + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.rb new file mode 100644 index 000000000..8bfd7cf1e --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.rb @@ -0,0 +1,32 @@ +module ManageIQ + module Automate + module Transformation + module Infrastructure + module VM + module Common + class PowerOn + def initialize(handle = $evm) + @handle = handle + end + + def main + begin + task = @handle.root['service_template_transformation_plan_task'] + destination_vm = @handle.vmdb(:vm).find_by(:id => task.get_option(:destination_vm_id)) + destination_vm.start + rescue Exception => e + @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + raise + end + end + end + end + end + end + end + end +end + +if $PROGRAM_NAME == __FILE__ + ManageIQ::Automate::Transformation::Infrastructure::VM::Common::PowerOn.new.main +end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.yaml new file mode 100644 index 000000000..aa10bf7bb --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.yaml @@ -0,0 +1,13 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: PowerOn + display_name: + description: + scope: instance + language: ruby + location: inline + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/_missing.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/_missing.yaml new file mode 100644 index 000000000..31e5fff8b --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/_missing.yaml @@ -0,0 +1,12 @@ +--- +object_type: instance +version: 1.0 +object: + attributes: + display_name: + name: ".missing" + inherits: + description: + fields: + - execute: + value: "${#_missing_instance}" diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/__namespace__.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/__namespace__.yaml new file mode 100644 index 000000000..56812dc20 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/__namespace__.yaml @@ -0,0 +1,10 @@ +--- +object_type: namespace +version: 1.0 +object: + attributes: + name: VM + description: + display_name: + priority: + enabled: diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__class__.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__class__.yaml new file mode 100644 index 000000000..9123cb0f1 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__class__.yaml @@ -0,0 +1,33 @@ +--- +object_type: class +version: 1.0 +object: + attributes: + description: + display_name: Red Hat + name: rhevm + type: + inherits: + visibility: + owner: + schema: + - field: + aetype: method + name: execute + display_name: + datatype: + priority: 1 + owner: + default_value: + substitute: true + message: create + visibility: + collect: + scope: + description: + condition: + on_entry: + on_exit: + on_error: + max_retries: + max_time: diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkpoweredon.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkpoweredon.rb new file mode 100644 index 000000000..287ba811d --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkpoweredon.rb @@ -0,0 +1,38 @@ +module ManageIQ + module Automate + module Transformation + module Infrastructure + module VM + module RedHat + class CheckPoweredOn + def initialize(handle = $evm) + @handle = handle + end + + def main + begin + task = @handle.root['service_template_transformation_plan_task'] + destination_vm = @handle.vmdb(:vm).find_by(:id => task.get_option(:destination_vm_id)) + destination_ems = destination_vm.ext_management_system + destination_vm_sdk = ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::Utils.new(destination_ems).vm_find_by_name(destination_vm.name) + @handle.log(:info, "Status of VM '#{destination_vm.name}': #{destination_vm_sdk.status}") + unless destination_vm_sdk.status == OvirtSDK4::VmStatus::UP + @handle.root["ae_result"] = "retry" + @handle.root["ae_retry_interval"] = "15.seconds" + end + rescue Exception => e + @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + raise + end + end + end + end + end + end + end + end +end + +if $PROGRAM_NAME == __FILE__ + ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::CheckPoweredOn.new.main +end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkpoweredon.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkpoweredon.yaml new file mode 100644 index 000000000..4501d42b5 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkpoweredon.yaml @@ -0,0 +1,15 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: CheckPoweredOn + display_name: + description: + scope: instance + language: ruby + location: inline + embedded_methods: + - "/Transformation/Infrastructure/VM/rhevm/Utils" + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkvmininventory.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkvmininventory.rb new file mode 100644 index 000000000..0b63a4b90 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkvmininventory.rb @@ -0,0 +1,57 @@ +module ManageIQ + module Automate + module Transformation + module Infrastructure + module VM + module RedHat + class CheckVmInInventory + def initialize(handle = $evm) + @handle = handle + end + + def main + begin + task = @handle.root['service_template_transformation_plan_task'] + source_vm = task.source + destination_ems = task.transformation_destination(source_vm.ems_cluster).ext_management_system + destination_vm = ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::Utils.new(destination_ems).vm_find_by_name(source_vm.name) + raise "VM #{source_vm.name} not found in destination provider #{destination_ems.name}" if destination_vm.nil? + + finished = false + + destination_vm_vmdb = @handle.vmdb(:vm).where(["ems_ref = ?", destination_vm.href.gsub(/^\/ovirt-engine/, '')]).first + if destination_vm_vmdb.blank? + @handle.log(:info, "VM '#{source_vm.name}' not found in VMDB.") + if @handle.state_var_exist?(:ems_refresh_in_progress) + @handle.log(:info, "Refresh of '#{destination_ems.name}' is in progress. Nothing to do.") + else + @handle.log(:info, "Forcing refresh of provider '#{destination_ems.name}'") + destination_ems.refresh + @handle.set_state_var(:ems_refresh_in_progress, true) + end + else + @handle.log(:info, "VM '#{source_vm.name}' found in VMDB with id '#{destination_vm_vmdb.id}'") + task.set_option(:destination_vm_id, destination_vm_vmdb.id) + finished = true + end + + unless finished + @handle.root['ae_result'] = 'retry' + @handle.root['ae_retry_interval'] = '15.seconds' + end + rescue Exception => e + @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + raise + end + end + end + end + end + end + end + end +end + +if $PROGRAM_NAME == __FILE__ + ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::CheckVmInInventory.new.main +end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkvmininventory.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkvmininventory.yaml new file mode 100644 index 000000000..93aa55ffc --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkvmininventory.yaml @@ -0,0 +1,15 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: CheckVmInInventory + display_name: + description: + scope: instance + language: ruby + location: inline + embedded_methods: + - "/Transformation/Infrastructure/VM/rhevm/Utils" + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.rb new file mode 100644 index 000000000..f7d3f0294 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.rb @@ -0,0 +1,33 @@ +module ManageIQ + module Automate + module Transformation + module Infrastructure + module VM + module RedHat + class EnableVirtIOSCSI + def initialize(handle = $evm) + @handle = handle + end + + def main + begin + task = @handle.root['service_template_transformation_plan_task'] + destination_vm = @handle.vmdb(:vm).find_by(:id => task.get_option(:destination_vm_id)) + destination_ems = destination_vm.ext_management_system + ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::Utils.new(destination_ems).vm_enable_virtio_scsi(destination_vm) + rescue Exception => e + @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + raise + end + end + end + end + end + end + end + end +end + +if $PROGRAM_NAME == __FILE__ + ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::EnableVirtIOSCSI.new.main +end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.yaml new file mode 100644 index 000000000..1d4984f45 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.yaml @@ -0,0 +1,15 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: EnableVirtIOSCSI + display_name: + description: + scope: instance + language: ruby + location: inline + embedded_methods: + - "/Transformation/Infrastructure/VM/rhevm/Utils" + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/setdescription.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/setdescription.rb new file mode 100644 index 000000000..c0f719a1e --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/setdescription.rb @@ -0,0 +1,35 @@ +module ManageIQ + module Automate + module Transformation + module Infrastructure + module VM + module RedHat + class SetDescription + def initialize(handle = $evm) + @handle = handle + end + + def main + begin + task = @handle.root['service_template_transformation_plan_task'] + destination_vm = @handle.vmdb(:vm).find_by(:id => task.get_option(:destination_vm_id)) + destination_ems = destination_vm.ext_management_system + + description = "Migrated by Cloudforms on #{Time.now}." + ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::Utils.new(destination_ems).vm_set_description(destination_vm, description) + rescue Exception => e + @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + raise + end + end + end + end + end + end + end + end +end + +if $PROGRAM_NAME == __FILE__ + ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::SetDescription.new.main +end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/setdescription.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/setdescription.yaml new file mode 100644 index 000000000..095fa0e43 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/setdescription.yaml @@ -0,0 +1,15 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: SetDescription + display_name: + description: + scope: instance + language: ruby + location: inline + embedded_methods: + - "/Transformation/Infrastructure/VM/rhevm/Utils" + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/utils.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/utils.rb new file mode 100644 index 000000000..ef1dc084c --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/utils.rb @@ -0,0 +1,190 @@ +# +# Utility library for Red Hat Virtualization +# +require 'ovirtsdk4' + +module ManageIQ + module Automate + module Transformation + module Infrastructure + module VM + module RedHat + class Utils + + def initialize(ems, handle = $evm) + @debug = true + @handle = handle + @ems = ems_to_service_model(ems) + @connection = connection(@ems) + end + + def get_export_domain + storage_domains_service.list.select { |domain_service| + domain_service.type == OvirtSDK4::StorageDomainType::EXPORT + }.first + end + + def vm_import(vm_name, cluster, storage_domain) + target_domain = storage_domains_service.list(search: "name=#{storage_domain}").first + raise "Can't find storage domain #{storage_domain}" if target_domain.blank? + target_cluster = clusters_service.list(search: "name=#{cluster}").first + raise "Can't find cluster #{cluster}" if target_cluster.blank? + vm = vm_find_in_export_domain(vm_name) + raise "Can't find VM #{vm_name} on export domain" if vm.blank? + export_domain_vm_service(vm.id).import( + storage_domain: OvirtSDK4::StorageDomain.new( + id: target_domain.id + ), + cluster: OvirtSDK4::Cluster.new( + id: target_cluster.id + ), + vm: OvirtSDK4::Vm.new( + id: vm.id + ) + ) + end + + def vm_delete_from_export_domain(vm_name) + vm = vm_find_in_export_domain(vm_name) + raise "Can't find VM #{vm_name} on export domain" if vm.blank? + @handle.log(:info, "About to remove VM: #{vm_name}") + export_domain_vm_service(vm.id).remove + end + + def vm_find_by_name(vm_name) + vms_service.list(search: "name=#{vm_name}").first + end + + def vm_set_description(vm, description) + vm_sdk = vm_find_by_name(vm.name) + raise "Can't find VM #{vm_name} in RHV provider" if vm_sdk.blank? + vm_service(vm_sdk.id).update(description: description) + true + end + + def vm_get_description(vm) + vm_sdk = vm_find_by_name(vm.name) + raise "Can't find VM #{vm_name} in RHV provider" if vm_sdk.blank? + vm_sdk.description + end + + def vm_enable_virtio_scsi(vm) + vm_sdk = vm_find_by_name(vm.name) + raise "Can't find VM #{vm_name}" if vm_sdk.blank? + # Enable virtio_scsi in the VM + vm_service(vm_sdk.id).update(virtio_scsi: {enabled: true}) + if vm_sdk.status == OvirtSDK4::VmStatus::DOWN + attachments_service = disk_attachments_service(vm_sdk.id) + attachments_service.list.each do | attachment | + attachments_service.attachment_service(attachment.id).update( + interface: OvirtSDK4::DiskInterface::VIRTIO_SCSI + ) + end + else + raise "VM must be down to enable virtio_scsi" + end + end + + def vm_set_nic_network(vm, nic, lan) + vm_sdk = vm_find_by_name(vm.name) + raise "Can't find VM #{vm_name} in RHV provider" if vm_sdk.blank? + target_network = vnic_profiles_service.list.select { |vnic_profile| + vnic_profile.network.id == lan.uid_ems + }.first + raise "Can't find network #{lan.name} in RHV provider" if target_network.blank? + nics_service = vm_nics_service(vm_sdk.id) + target_nic = nics_service.list.select { |nic_sdk| + nic_sdk.name == nic.device_name + }.first + raise "Can't find nic #{nic.name} for VM #{vm_name}" if target_nic.blank? + nics_service.nic_service(target_nic.id).update( + vnic_profile: target_network + ) + end + + def vm_get_disk_interfaces(vm) + disks = [] + vm_sdk = vm_find_by_name(vm.name) + raise "Can't find VM #{vm.name} in RHV provider" if vm_sdk.blank? + disk_attachments_service(vm_sdk.id).list.each do | attachment | + disks << attachment.interface + end + disks + end + + private + + def ems_to_service_model(ems) + raise "Invalid EMS" if ems.nil? + # ems could be a numeric id or the ems object itself + unless ems.is_a?(DRb::DRbObject) && /Manager/.match(ems.type.demodulize) + if /^\d{1,13}$/.match(ems.to_s) + ems = @handle.vmdb(:ems, ems) + end + end + ems + end + + def vm_find_in_export_domain(vm_name) + export_domain_vms_service.list.select { | export_vm | export_vm.name == vm_name }.first + end + + def storage_domains_service + @connection.system_service.storage_domains_service + end + + def clusters_service + @connection.system_service.clusters_service + end + + def export_domain_vms_service + export_domain = get_export_domain + raise "No export domain found!" if export_domain.blank? + storage_domains_service.storage_domain_service(export_domain.id).vms_service + end + + def export_domain_vm_service(id) + export_domain_vms_service.vm_service(id) + end + + def vms_service + @connection.system_service.vms_service + end + + def networks_service + @connection.system_service.networks_service + end + + def vnic_profiles_service + @connection.system_service.vnic_profiles_service + end + + def vm_nics_service(id) + vm_service(id).nics_service + end + + def vm_service(id) + vms_service.vm_service(id) + end + + def disk_attachments_service(id) + vm_service(id).disk_attachments_service + end + + def connection(ems) + connection = OvirtSDK4::Connection.new( + url: "https://#{ems.hostname}/ovirt-engine/api", + username: ems.authentication_userid, + password: ems.authentication_password, + insecure: true) + connection if connection.test(true) + end + + end + end + end + end + end + end +end + diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/utils.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/utils.yaml new file mode 100644 index 000000000..94612ce92 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/utils.yaml @@ -0,0 +1,13 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: Utils + display_name: + description: + scope: instance + language: ruby + location: inline + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/_missing.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/_missing.yaml new file mode 100644 index 000000000..31e5fff8b --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/_missing.yaml @@ -0,0 +1,12 @@ +--- +object_type: instance +version: 1.0 +object: + attributes: + display_name: + name: ".missing" + inherits: + description: + fields: + - execute: + value: "${#_missing_instance}" diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__class__.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__class__.yaml new file mode 100644 index 000000000..6d886911f --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__class__.yaml @@ -0,0 +1,33 @@ +--- +object_type: class +version: 1.0 +object: + attributes: + description: + display_name: VMware + name: vmwarews + type: + inherits: + visibility: + owner: + schema: + - field: + aetype: method + name: execute + display_name: + datatype: + priority: 1 + owner: + default_value: + substitute: true + message: create + visibility: + collect: + scope: + description: + condition: + on_entry: + on_exit: + on_error: + max_retries: + max_time: diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/collapsesnapshots.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/collapsesnapshots.rb new file mode 100644 index 000000000..08eeb0794 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/collapsesnapshots.rb @@ -0,0 +1,41 @@ +module ManageIQ + module Automate + module Transformation + module Infrastructure + module VM + module VMware + class CollapseSnapshots + def initialize(handle = $evm) + @handle = handle + end + + def main + begin + task = @handle.root['service_template_transformation_plan_task'] + source_vm = task.source + + if source_vm.snapshots.empty? + @handle.log(:info, "VM '#{source_vm.name}' has no snapshot. Nothing to do.") + elsif task.get_option(:collapse_snapshots) + @handle.log(:info, "VM '#{source_vm.name}' has snapshots and we need to collapse them.") + @handle.log(:info, "Collapsing snapshots for #{source_vm.name}") + source_vm.remove_all_snapshots + else + raise "VM '#{source_vm.name}' has snapshots, but we are not allowed to collapse them. Exiting." + end + rescue Exception => e + @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + raise + end + end + end + end + end + end + end + end +end + +if $PROGRAM_NAME == __FILE__ + ManageIQ::Automate::Transformation::Infrastructure::VM::VMware::CollapseSnapshots.new.main +end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/collapsesnapshots.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/collapsesnapshots.yaml new file mode 100644 index 000000000..098568861 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/collapsesnapshots.yaml @@ -0,0 +1,15 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: CollapseSnapshots + display_name: + description: + scope: instance + language: ruby + location: inline + embedded_methods: + - "/Transformation/Infrastructure/VM/vmwarews/Utils" + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/setmigrated.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/setmigrated.rb new file mode 100644 index 000000000..1b29ed62c --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/setmigrated.rb @@ -0,0 +1,55 @@ +module ManageIQ + module Automate + module Transformation + module Infrastructure + module VM + module VMware + class SetMigrated + def initialize(handle = $evm) + @handle = handle + end + + # Taken from / Service / Provisioning / StateMachines / Methods / configure_vm_hostname. + def check_name_collisions(vm, new_name) + name_collisions = Hash.new(0) + @handle.vmdb(:vm).where("name = '#{new_name}'").each do |vm| + name_collisions[:active] += 1 if vm.active + name_collisions[:template] += 1 if vm.template + name_collisions[:retired] += 1 if vm.retired? + name_collisions[:archived] += 1 if vm.archived + name_collisions[:orphaned] += 1 if vm.orphaned + end + name_collisions_summary = "" + name_collisions.each { |k, v| name_collisions_summary += " - #{k}: #{v}" } + return name_collisions_summary + end + + def main + begin + exit MIQ_OK + task = @handle.root['service_template_transformation_plan_task'] + source_vm = task.source + new_name = "#{source_vm.name}_migrated" + + name_collisions = check_name_collisions(source_vm, new_name) + raise "ERROR: #{new_name} already exists #{name_collisions}." unless name_collisions.blank? + + @handle.log(:info, "Renaming VM #{source_vm.name} to #{new_name}") + result = ManageIQ::Automate::Transformation::Infrastructure::VM::VMware::Utils.vm_rename(source_vm, new_name) + raise "VM rename for #{source_vm.name} to #{new_name} failed" unless result + rescue Exception => e + @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + raise + end + end + end + end + end + end + end + end +end + +if $PROGRAM_NAME == __FILE__ + ManageIQ::Automate::Transformation::Infrastructure::VM::VMware::SetMigrated.new.main +end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/setmigrated.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/setmigrated.yaml new file mode 100644 index 000000000..51ff96a32 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/setmigrated.yaml @@ -0,0 +1,15 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: SetMigrated + display_name: + description: + scope: instance + language: ruby + location: inline + embedded_methods: + - "/Transformation/Infrastructure/VM/vmwarews/Utils" + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.rb new file mode 100644 index 000000000..8fda4600c --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.rb @@ -0,0 +1,100 @@ +module ManageIQ + module Automate + module Transformation + module Infrastructure + module VM + module VMware + class Utils + require 'rbvmomi' + + def initialize(handle = $evm) + @handle = handle + end + + def main + end + + def connect_to_provider(ems) + ipaddress = ems.ipaddress + ipaddress ||= ems.hostname + RbVmomi::VIM.connect(host: ipaddress, user: ems.authentication_userid, password: ems.authentication_password, insecure: true) + end + + def vm_get_ref(vim, vm) + dc = vim.serviceInstance.find_datacenter(vm.v_owning_datacenter) + raise "Datacenter '#{vm.datacenter.name}' not found in vCenter" unless dc + vim.serviceInstance.content.searchIndex.FindByUuid(datacenter: dc, uuid: vm.uid_ems, vmSearch: true, instanceUuid: false) + end + + def self.get_vcenter_fingerprint(ems, handle=$evm) + command = "openssl s_client -connect #{ems.hostname}:443 2>\/dev\/null | openssl x509 -noout -fingerprint -sha1" + ssl_fingerprint = `#{command}` + fingerprint = ssl_fingerprint[17..ssl_fingerprint.size-2] + handle.log(:info, "vCenter fingerprint: #{fingerprint}") + return fingerprint + end + + def self.vm_rename_bill(vm, new_name, handle=$evm) + ems = vm.ext_management_system + ems_endpoint = ems.ipaddress || ems.hostname + vim = RbVmomi::VIM.connect(host: ems_endpoint, user: ems.authentication_userid, password: ems.authentication_password, insecure: true) + vm_ref = vm_get_ref(vim, vm) + + spec = RbVmomi::VIM::VirtualMachineConfigSpec(name: new_name) + task = vm_ref.ReconfigVM_Task(spec: spec) + + # Seems using the task.info.state returned by the ReconfigVM_Task is not trust worthy. It will return 'state' = 'running' + # and the later polls by the taskManager returns 'error', 'Another task is already in progress'... + # ...so lets wait for 5 seconds and ask then task manager what it thinks the real state is. + handle.log(:info, "task.info.state = #{task.info.state}") + handle.log(:info, "task.info.error.localMessage = #{task.info.error.localizedMessage}") if task.info.state == 'error' + + sleep(5) + tm = vim.serviceInstance.content.taskManager + tasks = tm.recentTask.select { |t| t.info.key == task.info.key } + raise "Cannot find task key #{task.info.key} in vCenter" unless tasks.any? + task = tasks.first + + handle.log(:info, "task manager says: task.info.state = #{task.info.state}") + handle.log(:info, "task manager says: task.info.error.localMessage = #{task.info.error.localizedMessage}") if task.info.state == 'error' + + if task.info.state == 'error' + raise "Delete disk error: #{task.info.error.localizedMessage}" unless task.info.error.localizedMessage.include?('Another task is already in progress') + handle.log(:info, "Delete disk cannot start due to another vCenter task running, Will retry in 30 seconds") + handle.root['ae_result'] = 'retry' + handle.root['ae_retry_interval'] = '30.seconds' + end + true + end + + def self.vm_rename(vm, new_name, handle = $evm) + ems = vm.ext_management_system + ems_endpoint = ems.ipaddress || ems.hostname + vim = RbVmomi::VIM.connect(host: ems_endpoint, user: ems.authentication_userid, password: ems.authentication_password, insecure: true) + + sleep 2 + dc = vim.serviceInstance.find_datacenter(vm.v_owning_datacenter) + raise "Datacenter '#{vm.v_owning_datacenter}' not found in vCenter" unless dc + + sleep 2 + vim_vm = dc.find_vm(vm.name) + raise "Unable to locate #{vm.name} in data center #{dc}" + begin + sleep 2 + vim_vm.ReconfigVM_Task(:spec => RbVmomi::VIM::VirtualMachineConfigSpec(:name=> new_name)).wait_for_completion + sleep 2 + dc.find_vm(new_name) + puts "Successfully renamed #{options[:source_vm]} to #{options[:new_name]}." + rescue + return false + end + true + end + + end + end + end + end + end + end +end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.yaml new file mode 100644 index 000000000..94612ce92 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.yaml @@ -0,0 +1,13 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: Utils + display_name: + description: + scope: instance + language: ruby + location: inline + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/_missing.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/_missing.yaml new file mode 100644 index 000000000..31e5fff8b --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/_missing.yaml @@ -0,0 +1,12 @@ +--- +object_type: instance +version: 1.0 +object: + attributes: + display_name: + name: ".missing" + inherits: + description: + fields: + - execute: + value: "${#_missing_instance}" diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/__namespace__.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/__namespace__.yaml new file mode 100644 index 000000000..58e960d61 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/Infrastructure/__namespace__.yaml @@ -0,0 +1,10 @@ +--- +object_type: namespace +version: 1.0 +object: + attributes: + name: Infrastructure + description: + display_name: + priority: + enabled: diff --git a/content/automate/ManageIQ/Transformation/StateMachines/VMTransformation.class/transformation.yaml b/content/automate/ManageIQ/Transformation/StateMachines/VMTransformation.class/transformation.yaml index 4a185ddbc..f83a8cc7f 100644 --- a/content/automate/ManageIQ/Transformation/StateMachines/VMTransformation.class/transformation.yaml +++ b/content/automate/ManageIQ/Transformation/StateMachines/VMTransformation.class/transformation.yaml @@ -11,35 +11,35 @@ object: - State1: value: "/Transformation/Common/AssessTransformation" on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Assess Migration") + => "Assess Migration", task_message => "Validating") on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Assess Migration") + => "Assess Migration", task_message => "Validating") on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Assess Migration") + => "Assess Migration", task_message => "Validating") - State2: - value: "/Transformation/Infrastructure/VM/${state_var#source_ems_type}/CollapseSnapshots" + value: "/Transformation/Common/AcquireTransformationHost" on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Collapse Snapshots") + => "Acquire Transformation Host", task_message => "Pre-migration") on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Collapse Snapshots") + => "Acquire Transformation Host", task_message => "Pre-migration") on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Collapse Snapshots") + => "Acquire Transformation Host", task_message => "Pre-migration") - State3: value: "/Transformation/Infrastructure/VM/Common/PowerOff" on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Power off") + => "Power off", task_message => "Pre-migration") on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Power off") + => "Power off", task_message => "Pre-migration") on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Power off") + => "Power off", task_message => "Pre-migration") - State4: - value: "/Transformation/Common/AcquireTransformationHost" + value: "/Transformation/Infrastructure/VM/${state_var#source_ems_type}/CollapseSnapshots" on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Acquire Transformation Host") + => "Collapse Snapshots", task_message => "Pre-migration") on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Acquire Transformation Host") + => "Collapse Snapshots", task_message => "Pre-migration") on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Acquire Transformation Host") + => "Collapse Snapshots", task_message => "Pre-migration") - State5: value: "/Transformation/StateMachines/VMTransformation/${state_var#transformation_type}_${state_var#transformation_method}?state_ancestry=${#state_ancestry}/${#ae_state}" on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 95, description @@ -51,8 +51,11 @@ object: - State6: value: "/Transformation/Infrastructure/VM/${state_var#source_ems_type}/SetMigrated" on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Mark source as migrated") + => "Mark source as migrated", task_message => "Migrating") on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Mark source as migrated") + => "Mark source as migrated", task_message => "Migrating") on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Mark source as migrated") + => "Mark source as migrated", task_message => "Migrating") + - State7: + on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description + => "Virtual machine migrated", task_message => "Migration complete") diff --git a/content/automate/ManageIQ/Transformation/StateMachines/VMTransformation.class/vmwarews2rhevm_vddk.yaml b/content/automate/ManageIQ/Transformation/StateMachines/VMTransformation.class/vmwarews2rhevm_vddk.yaml index 06958e30c..139474bb4 100644 --- a/content/automate/ManageIQ/Transformation/StateMachines/VMTransformation.class/vmwarews2rhevm_vddk.yaml +++ b/content/automate/ManageIQ/Transformation/StateMachines/VMTransformation.class/vmwarews2rhevm_vddk.yaml @@ -11,83 +11,59 @@ object: - State1: value: "/Transformation/TransformationHosts/${state_var#transformation_host_type}/VMTransform_${state_var#source_ems_type}2${state_var#destination_ems_type}_${state_var#transformation_method}" on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Convert disks") + => "Convert disks", task_message => "Migrating") on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Convert disks") + => "Convert disks", task_message => "Migrating") on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Convert disks") + => "Convert disks", task_message => "Migrating") - State2: value: "/Transformation/TransformationHosts/${state_var#transformation_host_type}/VMCheckTransformed_${state_var#source_ems_type}2${state_var#destination_ems_type}_${state_var#transformation_method}" - on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 70, description - => "Convert disks") - on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 70, description - => "Convert disks") - on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 70, description - => "Convert disks") + on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 85, description + => "Convert disks", task_message => "Migrating") + on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 85, description + => "Convert disks", task_message => "Migrating") + on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 85, description + => "Convert disks", task_message => "Migrating") max_retries: '1500' - State3: - value: "/Transformation/Infrastructure/VM/${state_var#destination_ems_type}/Import" - on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Import VM") - on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Import VM") - on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Import VM") + value: "/Transformation/Infrastructure/VM/${state_var#destination_ems_type}/CheckVmInInventory" + on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 4, description + => "Refresh inventory", task_message => "Migrating") + on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 4, description + => "Refresh inventory", task_message => "Migrating") + on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 4, description + => "Refresh inventory", task_message => "Migrating") + max_retries: '200' - State4: - value: "/Transformation/Infrastructure/VM/${state_var#destination_ems_type}/CheckImported" - on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 18, description - => "Import VM") - on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 18, description - => "Import VM") - on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 18, description - => "Import VM") - max_retries: '400' - - State5: value: "/Transformation/Infrastructure/VM/${state_var#destination_ems_type}/SetDescription" on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Update description of VM") + => "Update description of VM", task_message => "Migrating") on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Update description of VM") + => "Update description of VM", task_message => "Migrating") on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Update description of VM") - - State6: + => "Update description of VM", task_message => "Migrating") + - State5: value: "/Transformation/Infrastructure/VM/${state_var#destination_ems_type}/EnableVirtIOSCSI" on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Enable Virtio-SCSI for VM") - on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Enable Virtio-SCSI for VM") - on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Enable Virtio-SCSI for VM") - - State7: - value: "/Transformation/Infrastructure/VM/${state_var#destination_ems_type}/RewireNetworks" - on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Configure network of VM") + => "Enable Virtio-SCSI for VM", task_message => "Migrating") on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Configure network of VM") + => "Enable Virtio-SCSI for VM", task_message => "Migrating") on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Configure network of VM") - - State8: + => "Enable Virtio-SCSI for VM", task_message => "Migrating") + - State6: value: "/Transformation/Infrastructure/VM/Common/PowerOn" on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Power-on VM") + => "Power-on VM", task_message => "Migrating") on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Power-on VM") + => "Power-on VM", task_message => "Migrating") on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Power-on VM") - - State9: + => "Power-on VM", task_message => "Migrating") + - State7: value: "/Transformation/Infrastructure/VM/${state_var#destination_ems_type}/CheckPoweredOn" - on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 5, description - => "Power-on VM") - on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 5, description - => "Power-on VM") - on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 5, description - => "Power-on VM") + on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 7, description + => "Power-on VM", task_message => "Migrating") + on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 7, description + => "Power-on VM", task_message => "Migrating") + on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 7, description + => "Power-on VM", task_message => "Migrating") max_retries: '200' - - State10: - value: "/Transformation/Infrastructure/VM/${state_var#destination_ems_type}/DeleteFromExportDomain" - on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Clean up temporary assets") - on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Clean up temporary assets") - on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Clean up temporary assets") diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.rb new file mode 100644 index 000000000..a8f552f7e --- /dev/null +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.rb @@ -0,0 +1,58 @@ +module ManageIQ + module Automate + module Transformation + module TransformationHosts + module Common + class Utils + def initialize(handle = $evm) + @debug = true + @handle = handle + end + + def main + end + + def self.get_runners_count_by_host(host, handle=$evm) + handle.vmdb(:service_template_transformation_plan_task).where(:state => 'active').select { |task| task.get_option(:transformation_host) == host }.size + end + + def self.transformation_hosts(ems, method, factory_config) + thosts = [] + ems.hosts.each do |host| + if host.tagged_with?('v2v_transformation_host', 'true') && host.tagged_with?('v2v_transformation_method', method) + thosts << { + :host => host, + :runners => { + :current => self.get_runners_count_by_host(host), + :maximum => host.custom_get('Max Transformation Runners') || factory_config['transformation_host_max_runners'] || 1 + } + } + end + end + thosts.sort_by! { |th| th[:runners][:current] } + end + + def self.eligible_transformation_hosts(ems, method, factory_config) + self.transformation_hosts(ems, method, factory_config).select { |thost| thost[:runners][:current] < thost[:runners][:maximum] } + end + + def self.get_runners_count_by_ems(ems, method, factory_config) + self.transformation_hosts(ems, method, factory_config).inject(0) { |sum, thost| sum + thost[:runners][:current] } + end + + def self.get_transformation_host(ems, method, factory_config, max_runners=nil) + ems_max_runners = ems.custom_get('Max Transformation Runners') || factory_config['ems_max_runners'] || 1 + ems_cur_runners = self.get_runners_count_by_ems(ems, method, factory_config) + transformation_host = ems_cur_runners < ems_max_runners ? self.eligible_transformation_hosts(ems, method, factory_config).first[:host] : nil + return transformation_host + end + end + end + end + end + end +end + +if $PROGRAM_NAME == __FILE__ + ManageIQ::Automate::Transformation::TransformationHosts::Common::Utils.new.main +end diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.yaml b/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.yaml new file mode 100644 index 000000000..94612ce92 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.yaml @@ -0,0 +1,13 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: Utils + display_name: + description: + scope: instance + language: ruby + location: inline + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.rb new file mode 100644 index 000000000..d716769b4 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.rb @@ -0,0 +1,27 @@ +module ManageIQ + module Automate + module Transformation + module TransformationHost + module OVirtHost + class RoleCheck + def initialize(handle = $evm) + @handle = handle + end + + def main + playbook = "/usr/share/doc/ovirt-ansible-v2v-conversion-host-1.0.0/examples/conversion_host_check.yml" + extra_vars = { v2v_manageiq_conversion_host_check: true } + + result = Transformation::TransformationHosts::OVirtHost::Utils.ansible_playbook(@handle.root['host'], playbook, extra_vars) + raise 'Conversion Host role is not enabled.' unless result[:rc].zero? + end + end + end + end + end + end +end + +if $PROGRAM_NAME == __FILE__ + ManageIQ::Automate::Transformation::TransformationHost::OVirtHost::RoleCheck.new.main +end diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.yaml b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.yaml index 432952a39..4f233d034 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.yaml +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.yaml @@ -4,39 +4,12 @@ version: 1.0 object: attributes: name: RoleCheck - display_name: '' + display_name: description: scope: instance language: ruby - location: playbook - data: - options: - :repository_id: '1' - :playbook_id: '1' - :credential_id: '11' - :verbosity: '0' - :execution_ttl: '5' - :hosts: "${/#host.name}" - :log_output: on_error - :become_enabled: true - inputs: - - field: - aetype: - name: v2v_manageiq_conversion_host_check - display_name: - datatype: string - priority: 0 - owner: - default_value: 'true' - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: + location: inline + embedded_methods: + - "/Transformation/TransformationHosts/ovirt_host/Utils" + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roledisable.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roledisable.rb new file mode 100644 index 000000000..1752ac226 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roledisable.rb @@ -0,0 +1,28 @@ +module ManageIQ + module Automate + module Transformation + module TransformationHost + module OVirtHost + class RoleDisable + def initialize(handle = $evm) + @handle = handle + end + + def main + host = @handle.root['host'] + playbook = "/usr/share/doc/ovirt-ansible-v2v-conversion-host-1.0.0/examples/conversion_host_disable.yml" + extra_vars = {} + + result = Transformation::TransformationHosts::OVirtHost::Utils.ansible_playbook(host, playbook, extra_vars) + @handle.log(:error, "Failed to disable Conversion Host role for '#{host.name}'.") unless result[:rc].zero? + end + end + end + end + end + end +end + +if $PROGRAM_NAME == __FILE__ + ManageIQ::Automate::Transformation::TransformationHost::OVirtHost::RoleDisable.new.main +end diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roledisable.yaml b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roledisable.yaml index 3ddac72ad..4a30eb7c6 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roledisable.yaml +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roledisable.yaml @@ -4,19 +4,12 @@ version: 1.0 object: attributes: name: RoleDisable - display_name: '' + display_name: description: scope: instance language: ruby - location: playbook - data: - options: - :repository_id: '1' - :playbook_id: '2' - :credential_id: '11' - :verbosity: '' - :execution_ttl: '10' - :hosts: "${/#host.name}" - :log_output: on_error - :become_enabled: true + location: inline + embedded_methods: + - "/Transformation/TransformationHosts/ovirt_host/Utils" + options: {} inputs: [] diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roleenable.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roleenable.rb new file mode 100644 index 000000000..21d0e5566 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roleenable.rb @@ -0,0 +1,35 @@ +module ManageIQ + module Automate + module Transformation + module TransformationHost + module OVirtHost + class RoleEnable + def initialize(handle = $evm) + @handle = handle + end + + def main + host = @handle.root['host'] + playbook = "/usr/share/doc/ovirt-ansible-v2v-conversion-host-1.0.0/examples/conversion_host_enable.yml" + extra_vars = {} + extra_vars[:v2v_vddk_package_name] = "VMware-vix-disklib-stable.tar.gz" + extra_vars[:v2v_vddk_package_url] = "http://#{host.ext_management_system.hostname}/vddk/#{extra_vars[:v2v_vddk_package_name]}" + # TODO: Remove the RPM repositories as they are provided by oVirt/RHV + extra_vars[:v2v_repo_rpms_name] = "v2v-nbdkit-rpms" + extra_vars[:v2v_repo_rpms_url] = "http://#{host.ext_management_system.hostname}/rpms/#{extra_vars[:v2v_repo_rpms_name]}" + extra_vars[:v2v_repo_srpms_name] = "v2v-nbdkit-src-rpms" + extra_vars[:v2v_repo_srpms_url] = "http://#{host.ext_management_system.hostname}/rpms/#{extra_vars[:v2v_repo_srpms_name]}" + + result = Transformation::TransformationHosts::OVirtHost::Utils.ansible_playbook(host, playbook, extra_vars) + @handle.log(:error, "Failed to enable Conversion Host role for '#{host.name}'.") unless result[:rc].zero? + end + end + end + end + end + end +end + +if $PROGRAM_NAME == __FILE__ + ManageIQ::Automate::Transformation::TransformationHost::OVirtHost::RoleEnable.new.main +end diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roleenable.yaml b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roleenable.yaml index 9a03cc4bd..78708cd5f 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roleenable.yaml +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roleenable.yaml @@ -4,159 +4,12 @@ version: 1.0 object: attributes: name: RoleEnable - display_name: '' + display_name: description: scope: instance language: ruby - location: playbook - data: - options: - :repository_id: '1' - :playbook_id: '3' - :credential_id: '11' - :verbosity: '' - :execution_ttl: '20' - :hosts: "${/#host.name}" - :log_output: on_error - :become_enabled: true - inputs: - - field: - aetype: - name: v2v_content_server - display_name: - datatype: string - priority: 0 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: - name: v2v_vddk_package_url - display_name: - datatype: string - priority: 1 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: - name: v2v_vddk_package_name - display_name: - datatype: string - priority: 2 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: - name: v2v_repo_rpms_url - display_name: - datatype: string - priority: 3 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: - name: v2v_repo_rpms_name - display_name: - datatype: string - priority: 4 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: - name: v2v_repo_srpms_url - display_name: - datatype: string - priority: 5 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: - name: v2v_repo_srpms_name - display_name: - datatype: string - priority: 6 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: + location: inline + embedded_methods: + - "/Transformation/TransformationHosts/ovirt_host/Utils" + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/utils.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/utils.rb new file mode 100644 index 000000000..12e5c381b --- /dev/null +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/utils.rb @@ -0,0 +1,77 @@ +module ManageIQ + module Automate + module Transformation + module TransformationHosts + module OVirtHost + class Utils + def initialize(handle = $evm) + @handle = handle + end + + def self.remote_command(host, command, stdin=nil, run_as=nil) + require "net/ssh" + command = "sudo -u #{run_as} #{command}" unless run_as.nil? + success, stdout, stderr, exit_code = true, '', '', nil + Net::SSH.start(host.name, host.authentication_userid, :password => host.authentication_password) do |ssh| + channel = ssh.open_channel do |channel| + channel.request_pty unless run_as.nil? + channel.exec(command) do |channel, success| + if success + channel.on_data do |_, data| + stdout += data.to_s + end + channel.on_extended_data do |_, data| + stderr += data.to_s + end + channel.on_request("exit-status") do |ch,data| + exit_code = data.read_long + end + unless stdin.nil? + channel.send_data(stdin) + channel.eof! + end + else + success = false + stderr = "Could not execute command." + end + end + end + channel.wait + end + return { :success => success, :stdout => stdout, :stderr => stderr, :rc => exit_code } + end + + def self.ansible_playbook(host, playbook, extra_vars) + require "net/ssh" + command = "ansible-playbook -i #{host.name}, #{playbook}" + extra_vars.each { |k,v| command += " -e '#{k}=#{v}'" } + success, stdout, stderr, exit_code = true, '', '', nil + Net::SSH.start(host.ext_management_system.hostname, 'root') do |ssh| + channel = ssh.open_channel do |channel| + channel.exec(command) do |channel, success| + if success + channel.on_data do |_, data| + stdout += data.to_s + end + channel.on_extended_data do |_, data| + stderr += data.to_s + end + channel.on_request("exit-status") do |ch,data| + exit_code = data.read_long + end + else + success = false + stderr = "Could not execute command." + end + end + end + channel.wait + end + return { :success => success, :stdout => stdout, :stderr => stderr, :rc => exit_code } + end + end + end + end + end + end +end diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/utils.yaml b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/utils.yaml new file mode 100644 index 000000000..94612ce92 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/utils.yaml @@ -0,0 +1,13 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: Utils + display_name: + description: + scope: instance + language: ruby + location: inline + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb new file mode 100644 index 000000000..f501c57b5 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb @@ -0,0 +1,90 @@ +module ManageIQ + module Automate + module Transformation + module TransformationHost + module OVirtHost + class VMCheckTransformed_vmwarews2rhevm_vddk + def initialize(handle = $evm) + @debug = true + @handle = handle + end + + def main + begin + require 'json' + + factory_config = @handle.get_state_var(:factory_config) + raise "No factory config found. Aborting." if factory_config.nil? + + task = @handle.root['service_template_transformation_plan_task'] + source_vm = task.source + + # Get the virt-v2v start timestamp + start_timestamp = task.get_option(:virtv2v_started_on) + + # Retrieve transformation host + transformation_host = @handle.vmdb(:host).find_by(:id => task.get_option(:transformation_host_id)) + + # Retrieve state of virt-v2v + result = Transformation::TransformationHosts::OVirtHost::Utils.remote_command(transformation_host, "cat '#{task.get_option(:virtv2v_wrapper)['state_file']}'") + raise result[:stderr] unless result[:success] and not result[:stdout].empty? + virtv2v_state = JSON.parse(result[:stdout]) + @handle.log(:info, "VirtV2V State: #{virtv2v_state.inspect}") + + # Retrieve disks array + virtv2v_disks = task.get_option(:virtv2v_disks) + virtv2v_disks = [virtv2v_disks] if virtv2v_disks.is_a?(Hash) + @handle.log(:info, "Disks: #{virtv2v_disks.inspect}") + + if virtv2v_state['finished'].nil? + # Update the progress of each disk + virtv2v_disks.each do |disk| + matching_disks = virtv2v_state['disks'].select { |d| d['path'] == disk[:path] } + raise "No disk matches '#{disk[:path]}'. Aborting." if matching_disks.length.zero? + raise "More than one disk matches '#{disk[:path]}'. Aborting." if matching_disks.length > 1 + disk[:percent] = matching_disks.first['progress'] + end + converted_disks = virtv2v_disks.select { |d| not d[:percent].zero? } + @handle.log(:info, "Converted disks: #{converted_disks.inspect}") + if converted_disks.empty? + @handle.set_state_var(:ae_state_progress, { 'message' => "Disks transformation is initializing.", 'percent' => 1 }) + else + percent = 0 + converted_disks.each { |disk| percent += ( disk[:percent].to_f * disk[:weight].to_f / 100.0 ) } + message = "Converting disk #{converted_disks.length} / #{virtv2v_disks.length} [#{percent.round(2)}%]." + @handle.set_state_var(:ae_state_progress, { 'message' => message, 'percent' => percent.round(2) }) + end + else + task.set_option(:virtv2v_finished_on, Time.now.strftime('%Y%m%d_%H%M')) + if virtv2v_state['return_code'].zero? + virtv2v_disks.each { |d| d[:percent] = 100 } + @handle.set_state_var(:ae_state_progress, { 'message' => 'Disks transformation succeeded.', 'percent' => 100 }) + else + @handle.set_state_var(:ae_state_progress, { 'message' => 'Disks transformation succeeded.'}) + raise "Disks transformation failed." + end + end + + task.set_option(:virtv2v_disks, virtv2v_disks) + + if task.get_option(:virtv2v_finished_on).nil? + @handle.root['ae_result'] = 'retry' + @handle.root['ae_retry_server_affinity'] = true + @handle.root['ae_retry_interval'] = factory_config['vmtransformation_check_interval'] || '15.seconds' + @handle.log(:info, "Disk transformation is not finished. Checking in #{@handle.root['ae_retry_interval']}") + end + rescue Exception => e + @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + raise + end + end + end + end + end + end + end +end + +if $PROGRAM_NAME == __FILE__ + ManageIQ::Automate::Transformation::TransformationHost::OVirtHost::VMCheckTransformed_vmwarews2rhevm_vddk.new.main +end diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.yaml b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.yaml new file mode 100644 index 000000000..9ea4155ee --- /dev/null +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.yaml @@ -0,0 +1,15 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: VMCheckTransformed_vmwarews2rhevm_vddk + display_name: + description: + scope: instance + language: ruby + location: inline + embedded_methods: + - "/Transformation/TransformationHosts/ovirt_host/Utils" + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb new file mode 100644 index 000000000..56c6ea780 --- /dev/null +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb @@ -0,0 +1,110 @@ +module ManageIQ + module Automate + module Transformation + module TransformationHost + module OVirtHost + class VMTransform_vmwarews2rhevm_vddk + def initialize(handle = $evm) + @debug = true + @handle = handle + end + + def main + begin + require 'json' + + factory_config = @handle.get_state_var(:factory_config) + raise "No factory config found. Aborting." if factory_config.nil? + + task = @handle.root['service_template_transformation_plan_task'] + source_vm = task.source + source_cluster = source_vm.ems_cluster + source_ems = source_vm.ext_management_system + destination_cluster = task.transformation_destination(source_cluster) + destination_ems = destination_cluster.ext_management_system + destination_storage = task.transformation_destination(source_vm.hardware.disks.select { |d| d.device_type == 'disk' }.first.storage) + raise "Invalid destination EMS type: #{destination_ems.emstype}. Aborting." unless destination_ems.emstype == "rhevm" + + # Get or create the virt-v2v start timestamp + start_timestamp = task.get_option(:virtv2v_started_on) || Time.now.strftime('%Y-%m-%d %H:%M:%S') + + # Retrieve transformation host + transformation_host = @handle.vmdb(:host).find_by(:id => task.get_option(:transformation_host_id)) + + @handle.log(:info, "Transformation - Started On: #{start_timestamp}") + + max_runners = destination_ems.custom_get('Max Transformation Runners') || factory_config['max_transformation_runners_by_ems'] || 1 + if Transformation::TransformationHosts::Common::Utils.get_runners_count_by_ems(destination_ems, @handle.get_state_var(:transformation_method), factory_config) >= max_runners + @handle.log("Too many transformations running: (#{max_runners}). Retrying.") + else + # Identify the RHV export domain + export_domain = destination_ems.storages.select { |s| s.storage_domain_type == 'export' }.first + task.set_option(:export_domain_id, export_domain.id) + + # Collect the VMware connection information + vmware_uri = "vpx://" + vmware_uri += "#{source_ems.authentication_userid.gsub('@', '%40')}@#{source_ems.hostname}/" + vmware_uri += "#{source_cluster.v_parent_datacenter.gsub(' ', '%20')}/#{source_cluster.name.gsub(' ', '%20')}/#{source_vm.host.uid_ems}" + vmware_uri += "?no_verify=1" + + # Collect information about the disks to convert + virtv2v_disks = task.get_option(:virtv2v_disks) + virtv2v_disks = [virtv2v_disks] if virtv2v_disks.is_a?(Hash) + source_disks = virtv2v_disks.map { |disk| disk[:path] } + @handle.log(:info, "Source VM Disks: #{source_disks}") + + # Collect information about the network mappings + virtv2v_networks = task.get_option(:virtv2v_networks) + virtv2v_networks = [virtv2v_networks] if virtv2v_networks.is_a?(Hash) + @handle.log(:info, "Network mappings: #{virtv2v_networks}") + + wrapper_options = { + vm_name: source_vm.name, + transport_method: 'vddk', + vmware_fingerprint: Transformation::Infrastructure::VM::VMware::Utils.get_vcenter_fingerprint(source_ems), + vmware_uri: vmware_uri, + vmware_password: source_ems.authentication_password, +# rhv_url: "https://#{destination_ems.authentication_userid.gsub('@', '%40')}@#{destination_ems.hostname}/ovirt-engine/api", + rhv_url: "https://#{destination_ems.hostname}/ovirt-engine/api", + rhv_cluster: destination_cluster.name, + rhv_storage: destination_storage.name, + rhv_password: destination_ems.authentication_password, + source_disks: source_disks, + network_mappings: virtv2v_networks + } + @handle.log(:info, "JSON Input:\n#{JSON.pretty_generate(wrapper_options)}") if @debug + + @handle.log(:info, "Connecting to #{transformation_host.name} as #{transformation_host.authentication_userid}") if @debug + @handle.log(:info, "Executing '/usr/bin/virt-v2v-wrapper.py'") + result = Transformation::TransformationHosts::OVirtHost::Utils.remote_command(transformation_host, "/usr/bin/virt-v2v-wrapper.py", stdin = wrapper_options.to_json) + raise result[:stderr] unless result[:success] + + # Record the wrapper files path + @handle.log(:info, "Command stdout: #{result[:stdout]}") if @debug + task.set_option(:virtv2v_wrapper, JSON.parse(result[:stdout])) + + # Record the status in the task object + task.set_option(:virtv2v_started_on, start_timestamp) + task.set_option(:virtv2v_status, 'active') + end + + if task.get_option(:virtv2v_started_on).nil? + @handle.root['ae_result'] = 'retry' + @handle.root['ae_retry_server_affinity'] = true + @handle.root['ae_retry_interval'] = $evm.object['check_convert_interval'] || '1.minutes' + end + rescue Exception => e + @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + raise + end + end + end + end + end + end + end +end + +if $PROGRAM_NAME == __FILE__ + ManageIQ::Automate::Transformation::TransformationHost::OVirtHost::VMTransform_vmwarews2rhevm_vddk.new.main +end diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.yaml b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.yaml new file mode 100644 index 000000000..7bac229bb --- /dev/null +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.yaml @@ -0,0 +1,17 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: VMTransform_vmwarews2rhevm_vddk + display_name: + description: + scope: instance + language: ruby + location: inline + embedded_methods: + - "/Transformation/TransformationHosts/Common/Utils" + - "/Transformation/TransformationHosts/ovirt_host/Utils" + - "/Transformation/Infrastructure/VM/vmwarews/Utils" + options: {} + inputs: [] From aac64a8303fd7fcf0cf6658d0261ee1f2f2a8eac Mon Sep 17 00:00:00 2001 From: fdupont-redhat Date: Wed, 23 May 2018 14:52:00 +0200 Subject: [PATCH 02/12] Remove empty scaffold of cloud conversion --- .../Cloud/VM/Common.class/__class__.yaml | 33 ------------------- .../Cloud/VM/Common.class/_missing.yaml | 12 ------- .../Cloud/VM/__namespace__.yaml | 10 ------ .../Cloud/VM/azure.class/__class__.yaml | 33 ------------------- .../Cloud/VM/azure.class/_missing.yaml | 12 ------- .../Cloud/VM/openstack.class/__class__.yaml | 33 ------------------- .../VM/openstack.class/__methods__/utils.rb | 17 ---------- .../VM/openstack.class/__methods__/utils.yaml | 13 -------- .../Cloud/VM/openstack.class/_missing.yaml | 12 ------- .../Transformation/Cloud/__namespace__.yaml | 10 ------ 10 files changed, 185 deletions(-) delete mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/Common.class/__class__.yaml delete mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/Common.class/_missing.yaml delete mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/__namespace__.yaml delete mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/azure.class/__class__.yaml delete mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/azure.class/_missing.yaml delete mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__class__.yaml delete mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__methods__/utils.rb delete mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__methods__/utils.yaml delete mode 100644 content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/_missing.yaml delete mode 100644 content/automate/ManageIQ/Transformation/Cloud/__namespace__.yaml diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/Common.class/__class__.yaml b/content/automate/ManageIQ/Transformation/Cloud/VM/Common.class/__class__.yaml deleted file mode 100644 index b7fe6fdbf..000000000 --- a/content/automate/ManageIQ/Transformation/Cloud/VM/Common.class/__class__.yaml +++ /dev/null @@ -1,33 +0,0 @@ ---- -object_type: class -version: 1.0 -object: - attributes: - description: - display_name: - name: Common - type: - inherits: - visibility: - owner: - schema: - - field: - aetype: method - name: execute - display_name: - datatype: - priority: 1 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/Common.class/_missing.yaml b/content/automate/ManageIQ/Transformation/Cloud/VM/Common.class/_missing.yaml deleted file mode 100644 index 31e5fff8b..000000000 --- a/content/automate/ManageIQ/Transformation/Cloud/VM/Common.class/_missing.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -object_type: instance -version: 1.0 -object: - attributes: - display_name: - name: ".missing" - inherits: - description: - fields: - - execute: - value: "${#_missing_instance}" diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/__namespace__.yaml b/content/automate/ManageIQ/Transformation/Cloud/VM/__namespace__.yaml deleted file mode 100644 index 56812dc20..000000000 --- a/content/automate/ManageIQ/Transformation/Cloud/VM/__namespace__.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -object_type: namespace -version: 1.0 -object: - attributes: - name: VM - description: - display_name: - priority: - enabled: diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/azure.class/__class__.yaml b/content/automate/ManageIQ/Transformation/Cloud/VM/azure.class/__class__.yaml deleted file mode 100644 index 283a84c09..000000000 --- a/content/automate/ManageIQ/Transformation/Cloud/VM/azure.class/__class__.yaml +++ /dev/null @@ -1,33 +0,0 @@ ---- -object_type: class -version: 1.0 -object: - attributes: - description: - display_name: Azure - name: azure - type: - inherits: - visibility: - owner: - schema: - - field: - aetype: method - name: execute - display_name: - datatype: - priority: 1 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/azure.class/_missing.yaml b/content/automate/ManageIQ/Transformation/Cloud/VM/azure.class/_missing.yaml deleted file mode 100644 index 31e5fff8b..000000000 --- a/content/automate/ManageIQ/Transformation/Cloud/VM/azure.class/_missing.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -object_type: instance -version: 1.0 -object: - attributes: - display_name: - name: ".missing" - inherits: - description: - fields: - - execute: - value: "${#_missing_instance}" diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__class__.yaml b/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__class__.yaml deleted file mode 100644 index 6978e9065..000000000 --- a/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__class__.yaml +++ /dev/null @@ -1,33 +0,0 @@ ---- -object_type: class -version: 1.0 -object: - attributes: - description: - display_name: Openstack - name: openstack - type: - inherits: - visibility: - owner: - schema: - - field: - aetype: method - name: execute - display_name: - datatype: - priority: 1 - owner: - default_value: - substitute: true - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__methods__/utils.rb b/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__methods__/utils.rb deleted file mode 100644 index 97d00329f..000000000 --- a/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__methods__/utils.rb +++ /dev/null @@ -1,17 +0,0 @@ -module ManageIQ - module Automate - module Transformation - module Cloud - module VM - module OpenStack - class Utils - - - end - end - end - end - end - end -end - diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__methods__/utils.yaml b/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__methods__/utils.yaml deleted file mode 100644 index 94612ce92..000000000 --- a/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/__methods__/utils.yaml +++ /dev/null @@ -1,13 +0,0 @@ ---- -object_type: method -version: 1.0 -object: - attributes: - name: Utils - display_name: - description: - scope: instance - language: ruby - location: inline - options: {} - inputs: [] diff --git a/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/_missing.yaml b/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/_missing.yaml deleted file mode 100644 index 31e5fff8b..000000000 --- a/content/automate/ManageIQ/Transformation/Cloud/VM/openstack.class/_missing.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -object_type: instance -version: 1.0 -object: - attributes: - display_name: - name: ".missing" - inherits: - description: - fields: - - execute: - value: "${#_missing_instance}" diff --git a/content/automate/ManageIQ/Transformation/Cloud/__namespace__.yaml b/content/automate/ManageIQ/Transformation/Cloud/__namespace__.yaml deleted file mode 100644 index 66f0a2a4a..000000000 --- a/content/automate/ManageIQ/Transformation/Cloud/__namespace__.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -object_type: namespace -version: 1.0 -object: - attributes: - name: Cloud - description: - display_name: - priority: - enabled: From 9a4de235d6a750a8b8de191f0e3c89d632494e5f Mon Sep 17 00:00:00 2001 From: fdupont-redhat Date: Wed, 23 May 2018 15:32:01 +0200 Subject: [PATCH 03/12] Replace the 'puts' call with 'handle.log'. --- .../VM/vmwarews.class/__methods__/utils.rb | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.rb index 8fda4600c..2cdcfcb9a 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.rb @@ -6,26 +6,26 @@ module VM module VMware class Utils require 'rbvmomi' - + def initialize(handle = $evm) @handle = handle end - + def main end - + def connect_to_provider(ems) ipaddress = ems.ipaddress ipaddress ||= ems.hostname RbVmomi::VIM.connect(host: ipaddress, user: ems.authentication_userid, password: ems.authentication_password, insecure: true) end - + def vm_get_ref(vim, vm) dc = vim.serviceInstance.find_datacenter(vm.v_owning_datacenter) raise "Datacenter '#{vm.datacenter.name}' not found in vCenter" unless dc vim.serviceInstance.content.searchIndex.FindByUuid(datacenter: dc, uuid: vm.uid_ems, vmSearch: true, instanceUuid: false) end - + def self.get_vcenter_fingerprint(ems, handle=$evm) command = "openssl s_client -connect #{ems.hostname}:443 2>\/dev\/null | openssl x509 -noout -fingerprint -sha1" ssl_fingerprint = `#{command}` @@ -33,31 +33,31 @@ def self.get_vcenter_fingerprint(ems, handle=$evm) handle.log(:info, "vCenter fingerprint: #{fingerprint}") return fingerprint end - + def self.vm_rename_bill(vm, new_name, handle=$evm) ems = vm.ext_management_system ems_endpoint = ems.ipaddress || ems.hostname vim = RbVmomi::VIM.connect(host: ems_endpoint, user: ems.authentication_userid, password: ems.authentication_password, insecure: true) vm_ref = vm_get_ref(vim, vm) - + spec = RbVmomi::VIM::VirtualMachineConfigSpec(name: new_name) task = vm_ref.ReconfigVM_Task(spec: spec) - + # Seems using the task.info.state returned by the ReconfigVM_Task is not trust worthy. It will return 'state' = 'running' # and the later polls by the taskManager returns 'error', 'Another task is already in progress'... # ...so lets wait for 5 seconds and ask then task manager what it thinks the real state is. handle.log(:info, "task.info.state = #{task.info.state}") handle.log(:info, "task.info.error.localMessage = #{task.info.error.localizedMessage}") if task.info.state == 'error' - + sleep(5) tm = vim.serviceInstance.content.taskManager tasks = tm.recentTask.select { |t| t.info.key == task.info.key } raise "Cannot find task key #{task.info.key} in vCenter" unless tasks.any? task = tasks.first - + handle.log(:info, "task manager says: task.info.state = #{task.info.state}") handle.log(:info, "task manager says: task.info.error.localMessage = #{task.info.error.localizedMessage}") if task.info.state == 'error' - + if task.info.state == 'error' raise "Delete disk error: #{task.info.error.localizedMessage}" unless task.info.error.localizedMessage.include?('Another task is already in progress') handle.log(:info, "Delete disk cannot start due to another vCenter task running, Will retry in 30 seconds") @@ -66,12 +66,12 @@ def self.vm_rename_bill(vm, new_name, handle=$evm) end true end - + def self.vm_rename(vm, new_name, handle = $evm) ems = vm.ext_management_system ems_endpoint = ems.ipaddress || ems.hostname vim = RbVmomi::VIM.connect(host: ems_endpoint, user: ems.authentication_userid, password: ems.authentication_password, insecure: true) - + sleep 2 dc = vim.serviceInstance.find_datacenter(vm.v_owning_datacenter) raise "Datacenter '#{vm.v_owning_datacenter}' not found in vCenter" unless dc @@ -84,13 +84,13 @@ def self.vm_rename(vm, new_name, handle = $evm) vim_vm.ReconfigVM_Task(:spec => RbVmomi::VIM::VirtualMachineConfigSpec(:name=> new_name)).wait_for_completion sleep 2 dc.find_vm(new_name) - puts "Successfully renamed #{options[:source_vm]} to #{options[:new_name]}." + handle.log(:info, "Successfully renamed #{options[:source_vm]} to #{options[:new_name]}.") rescue return false end true end - + end end end From eb7f09225506f7c5abf7528bb2e1a50da6d5e4f7 Mon Sep 17 00:00:00 2001 From: fdupont-redhat Date: Fri, 25 May 2018 11:08:27 +0200 Subject: [PATCH 04/12] Fix rubcocop errors --- .../__methods__/acquiretransformationhost.rb | 2 +- .../__methods__/assesstransformation.rb | 14 +-- .../VM/Common.class/__methods__/poweroff.rb | 26 ++--- .../VM/Common.class/__methods__/poweron.rb | 4 +- .../rhevm.class/__methods__/checkpoweredon.rb | 4 +- .../__methods__/checkvmininventory.rb | 10 +- .../__methods__/enablevirtioscsi.rb | 4 +- .../rhevm.class/__methods__/setdescription.rb | 6 +- .../VM/rhevm.class/__methods__/utils.rb | 107 ++++++++---------- .../__methods__/collapsesnapshots.rb | 6 +- .../vmwarews.class/__methods__/setmigrated.rb | 18 +-- .../VM/vmwarews.class/__methods__/utils.rb | 49 ++------ .../Common.class/__methods__/utils.rb | 35 +++--- .../ovirt_host.class/__methods__/rolecheck.rb | 4 +- .../__methods__/roledisable.rb | 2 +- .../__methods__/roleenable.rb | 2 +- .../vmchecktransformed_vmwarews2rhevm_vddk.rb | 26 ++--- .../vmtransform_vmwarews2rhevm_vddk.rb | 48 ++++---- 18 files changed, 154 insertions(+), 213 deletions(-) diff --git a/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.rb b/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.rb index 7652e7324..fe118648f 100644 --- a/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.rb +++ b/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.rb @@ -34,7 +34,7 @@ def main task.set_option(:transformation_host_name, transformation_host.name) end rescue Exception => e - @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + @handle.set_state_var(:ae_state_progress, 'message' => e.message) raise end end diff --git a/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb b/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb index 7eca004ac..1001c09b3 100644 --- a/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb +++ b/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb @@ -6,7 +6,7 @@ class AssessTransformation SUPPORTED_SOURCE_EMS_TYPES = ['vmwarews'].freeze SUPPORTED_DESTINATION_EMS_TYPES = ['rhevm'].freeze REQUIRED_CUSTOM_ATTRIBUTES = { - 'rhevm' => [:rhv_export_domain_id, :rhv_cluster_id, :rhv_storage_domain_id] + 'rhevm' => %i[rhv_export_domain_id, rhv_cluster_id, rhv_storage_domain_id] }.freeze def initialize(handle = $evm) @@ -34,21 +34,21 @@ def main source_network = nic.lan destination_network = task.transformation_destination(source_network) raise "[#{source_vm.name}] NIC #{nic.device_name} [#{source_network.name}] has no mapping. Aborting." if destination_network.nil? - virtv2v_networks << { source: source_network.name, destination: destination_network.name } + virtv2v_networks << { :source => source_network.name, :destination => destination_network.name } end @handle.log(:info, "Network mappings: #{virtv2v_networks}") task.set_option(:virtv2v_networks, virtv2v_networks) - + virtv2v_disks = [] source_vm.hardware.disks.select { |d| d.device_type == 'disk' }.each do |disk| source_storage = disk.storage destination_storage = task.transformation_destination(disk.storage) raise "[#{source_vm.name}] Disk #{disk.device_name} [#{source_storage.name}] has no mapping. Aborting." if destination_storage.nil? - virtv2v_disks << { path: disk.filename, size: disk.size, percent: 0, weight: disk.size / source_vm.allocated_disk_storage * 100 } + virtv2v_disks << { :path => disk.filename, :size => disk.size, percent: 0, :weight => disk.size / source_vm.allocated_disk_storage * 100 } end @handle.log(:info, "Source VM Disks #{virtv2v_disks}") task.set_option(:virtv2v_disks, virtv2v_disks) - + raise "Unsupported source EMS type: #{source_ems.emstype}." unless SUPPORTED_SOURCE_EMS_TYPES.include?(source_ems.emstype) @handle.set_state_var(:source_ems_type, source_ems.emstype) @@ -66,7 +66,7 @@ def main factory_config = { 'vmtransformation_check_interval' => @handle.object['vmtransformation_check_interval'] || '15.seconds', - 'vmpoweroff_check_interval' => @handle.object['vmpoweroff_check_interval'] || '30.seconds' + 'vmpoweroff_check_interval' => @handle.object['vmpoweroff_check_interval'] || '30.seconds' } @handle.set_state_var(:factory_config, factory_config) @@ -74,7 +74,7 @@ def main task.set_option(:collapse_snapshots, true) task.set_option(:power_off, true) rescue Exception => e - @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + @handle.set_state_var(:ae_state_progress, 'message' => e.message) raise end end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweroff.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweroff.rb index e381b0297..e5070011a 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweroff.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweroff.rb @@ -8,30 +8,28 @@ class PowerOff def initialize(handle = $evm) @handle = handle end - + def main begin task = @handle.root['service_template_transformation_plan_task'] source_vm = task.source - + if source_vm.power_state == 'off' @handle.log(:info, "VM '#{source_vm.name}' is already off. Nothing to do.") - else - if task.get_option(:power_off) - @handle.log(:info, "VM '#{source_vm.name} is powered on. Let's shut it down.") - if @handle.state_var_exist?(:vm_shutdown_in_progress) - source_vm.stop if @handle.root['ae_state_retries'].to_i > 10 - else - source_vm.shutdown_guest - @handle.set_state_var(:vm_shutdown_in_progress, true) - end - @handle.root['ae_result'] = 'retry' + elsif task.get_option(:power_off) + @handle.log(:info, "VM '#{source_vm.name} is powered on. Let's shut it down.") + if @handle.state_var_exist?(:vm_shutdown_in_progress) + source_vm.stop if @handle.root['ae_state_retries'].to_i > 10 else - raise "VM '#{source_vm.name} is powered on, but we are not allowed to shut it down. Aborting." + source_vm.shutdown_guest + @handle.set_state_var(:vm_shutdown_in_progress, true) end + @handle.root['ae_result'] = 'retry' + else + raise "VM '#{source_vm.name} is powered on, but we are not allowed to shut it down. Aborting." end rescue Exception => e - @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + @handle.set_state_var(:ae_state_progress, 'message' => e.message) raise end end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.rb index 8bfd7cf1e..a2e05f95f 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.rb @@ -8,14 +8,14 @@ class PowerOn def initialize(handle = $evm) @handle = handle end - + def main begin task = @handle.root['service_template_transformation_plan_task'] destination_vm = @handle.vmdb(:vm).find_by(:id => task.get_option(:destination_vm_id)) destination_vm.start rescue Exception => e - @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + @handle.set_state_var(:ae_state_progress, 'message' => e.message) raise end end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkpoweredon.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkpoweredon.rb index 287ba811d..5bd7bfcec 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkpoweredon.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkpoweredon.rb @@ -8,7 +8,7 @@ class CheckPoweredOn def initialize(handle = $evm) @handle = handle end - + def main begin task = @handle.root['service_template_transformation_plan_task'] @@ -21,7 +21,7 @@ def main @handle.root["ae_retry_interval"] = "15.seconds" end rescue Exception => e - @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + @handle.set_state_var(:ae_state_progress, 'message' => e.message) raise end end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkvmininventory.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkvmininventory.rb index 0b63a4b90..244171a93 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkvmininventory.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkvmininventory.rb @@ -8,7 +8,7 @@ class CheckVmInInventory def initialize(handle = $evm) @handle = handle end - + def main begin task = @handle.root['service_template_transformation_plan_task'] @@ -16,9 +16,9 @@ def main destination_ems = task.transformation_destination(source_vm.ems_cluster).ext_management_system destination_vm = ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::Utils.new(destination_ems).vm_find_by_name(source_vm.name) raise "VM #{source_vm.name} not found in destination provider #{destination_ems.name}" if destination_vm.nil? - + finished = false - + destination_vm_vmdb = @handle.vmdb(:vm).where(["ems_ref = ?", destination_vm.href.gsub(/^\/ovirt-engine/, '')]).first if destination_vm_vmdb.blank? @handle.log(:info, "VM '#{source_vm.name}' not found in VMDB.") @@ -34,13 +34,13 @@ def main task.set_option(:destination_vm_id, destination_vm_vmdb.id) finished = true end - + unless finished @handle.root['ae_result'] = 'retry' @handle.root['ae_retry_interval'] = '15.seconds' end rescue Exception => e - @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + @handle.set_state_var(:ae_state_progress, 'message' => e.message) raise end end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.rb index f7d3f0294..7a8d48b53 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.rb @@ -8,7 +8,7 @@ class EnableVirtIOSCSI def initialize(handle = $evm) @handle = handle end - + def main begin task = @handle.root['service_template_transformation_plan_task'] @@ -16,7 +16,7 @@ def main destination_ems = destination_vm.ext_management_system ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::Utils.new(destination_ems).vm_enable_virtio_scsi(destination_vm) rescue Exception => e - @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + @handle.set_state_var(:ae_state_progress, 'message' => e.message) raise end end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/setdescription.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/setdescription.rb index c0f719a1e..8986bc593 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/setdescription.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/setdescription.rb @@ -8,17 +8,17 @@ class SetDescription def initialize(handle = $evm) @handle = handle end - + def main begin task = @handle.root['service_template_transformation_plan_task'] destination_vm = @handle.vmdb(:vm).find_by(:id => task.get_option(:destination_vm_id)) destination_ems = destination_vm.ext_management_system - description = "Migrated by Cloudforms on #{Time.now}." + description = "Migrated by Cloudforms on #{Time.now.utc}." ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::Utils.new(destination_ems).vm_set_description(destination_vm, description) rescue Exception => e - @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + @handle.set_state_var(:ae_state_progress, 'message' => e.message) raise end end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/utils.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/utils.rb index ef1dc084c..a677bf134 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/utils.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/utils.rb @@ -10,7 +10,7 @@ module Infrastructure module VM module RedHat class Utils - + def initialize(ems, handle = $evm) @debug = true @handle = handle @@ -19,167 +19,152 @@ def initialize(ems, handle = $evm) end def get_export_domain - storage_domains_service.list.select { |domain_service| - domain_service.type == OvirtSDK4::StorageDomainType::EXPORT - }.first + storage_domains_service.list.select { |domain_service| domain_service.type == OvirtSDK4::StorageDomainType::EXPORT }.first end - + def vm_import(vm_name, cluster, storage_domain) - target_domain = storage_domains_service.list(search: "name=#{storage_domain}").first + target_domain = storage_domains_service.list(:search => "name=#{storage_domain}").first raise "Can't find storage domain #{storage_domain}" if target_domain.blank? - target_cluster = clusters_service.list(search: "name=#{cluster}").first + target_cluster = clusters_service.list(:search => "name=#{cluster}").first raise "Can't find cluster #{cluster}" if target_cluster.blank? vm = vm_find_in_export_domain(vm_name) raise "Can't find VM #{vm_name} on export domain" if vm.blank? export_domain_vm_service(vm.id).import( - storage_domain: OvirtSDK4::StorageDomain.new( - id: target_domain.id - ), - cluster: OvirtSDK4::Cluster.new( - id: target_cluster.id - ), - vm: OvirtSDK4::Vm.new( - id: vm.id - ) + :storage_domain => OvirtSDK4::StorageDomain.new(:id => target_domain.id), + :cluster => OvirtSDK4::Cluster.new(:id => target_cluster.id), + :vm => OvirtSDK4::Vm.new(:id => vm.id) ) end - + def vm_delete_from_export_domain(vm_name) vm = vm_find_in_export_domain(vm_name) raise "Can't find VM #{vm_name} on export domain" if vm.blank? @handle.log(:info, "About to remove VM: #{vm_name}") export_domain_vm_service(vm.id).remove end - + def vm_find_by_name(vm_name) vms_service.list(search: "name=#{vm_name}").first end - + def vm_set_description(vm, description) vm_sdk = vm_find_by_name(vm.name) raise "Can't find VM #{vm_name} in RHV provider" if vm_sdk.blank? - vm_service(vm_sdk.id).update(description: description) + vm_service(vm_sdk.id).update(:description => description) true end - + def vm_get_description(vm) vm_sdk = vm_find_by_name(vm.name) raise "Can't find VM #{vm_name} in RHV provider" if vm_sdk.blank? vm_sdk.description end - + def vm_enable_virtio_scsi(vm) vm_sdk = vm_find_by_name(vm.name) raise "Can't find VM #{vm_name}" if vm_sdk.blank? # Enable virtio_scsi in the VM - vm_service(vm_sdk.id).update(virtio_scsi: {enabled: true}) + vm_service(vm_sdk.id).update(:virtio_scsi => { :enabled => true }) if vm_sdk.status == OvirtSDK4::VmStatus::DOWN attachments_service = disk_attachments_service(vm_sdk.id) - attachments_service.list.each do | attachment | - attachments_service.attachment_service(attachment.id).update( - interface: OvirtSDK4::DiskInterface::VIRTIO_SCSI - ) + attachments_service.list.each do |attachment| + attachments_service.attachment_service(attachment.id).update(:interface => OvirtSDK4::DiskInterface::VIRTIO_SCSI) end else raise "VM must be down to enable virtio_scsi" end end - + def vm_set_nic_network(vm, nic, lan) vm_sdk = vm_find_by_name(vm.name) raise "Can't find VM #{vm_name} in RHV provider" if vm_sdk.blank? - target_network = vnic_profiles_service.list.select { |vnic_profile| - vnic_profile.network.id == lan.uid_ems - }.first + target_network = vnic_profiles_service.list.select { |vnic_profile| vnic_profile.network.id == lan.uid_ems }.first raise "Can't find network #{lan.name} in RHV provider" if target_network.blank? nics_service = vm_nics_service(vm_sdk.id) - target_nic = nics_service.list.select { |nic_sdk| - nic_sdk.name == nic.device_name - }.first + target_nic = nics_service.list.select { |nic_sdk| nic_sdk.name == nic.device_name }.first raise "Can't find nic #{nic.name} for VM #{vm_name}" if target_nic.blank? - nics_service.nic_service(target_nic.id).update( - vnic_profile: target_network - ) + nics_service.nic_service(target_nic.id).update(:vnic_profile => target_network) end - + def vm_get_disk_interfaces(vm) disks = [] vm_sdk = vm_find_by_name(vm.name) raise "Can't find VM #{vm.name} in RHV provider" if vm_sdk.blank? - disk_attachments_service(vm_sdk.id).list.each do | attachment | + disk_attachments_service(vm_sdk.id).list.each do |attachment| disks << attachment.interface end disks end - + private - + def ems_to_service_model(ems) raise "Invalid EMS" if ems.nil? # ems could be a numeric id or the ems object itself unless ems.is_a?(DRb::DRbObject) && /Manager/.match(ems.type.demodulize) - if /^\d{1,13}$/.match(ems.to_s) + if ems.to_s =~ /^\d{1,13}$/ ems = @handle.vmdb(:ems, ems) end end ems end - + def vm_find_in_export_domain(vm_name) - export_domain_vms_service.list.select { | export_vm | export_vm.name == vm_name }.first + export_domain_vms_service.list.select { |export_vm| export_vm.name == vm_name }.first end - + def storage_domains_service @connection.system_service.storage_domains_service end - + def clusters_service @connection.system_service.clusters_service end - + def export_domain_vms_service export_domain = get_export_domain raise "No export domain found!" if export_domain.blank? storage_domains_service.storage_domain_service(export_domain.id).vms_service end - + def export_domain_vm_service(id) export_domain_vms_service.vm_service(id) end - + def vms_service @connection.system_service.vms_service end - + def networks_service @connection.system_service.networks_service end - - def vnic_profiles_service + + def vnic_profiles_service @connection.system_service.vnic_profiles_service end - + def vm_nics_service(id) vm_service(id).nics_service end - + def vm_service(id) vms_service.vm_service(id) end - + def disk_attachments_service(id) vm_service(id).disk_attachments_service end - + def connection(ems) connection = OvirtSDK4::Connection.new( - url: "https://#{ems.hostname}/ovirt-engine/api", - username: ems.authentication_userid, - password: ems.authentication_password, - insecure: true) + :url => "https://#{ems.hostname}/ovirt-engine/api", + :username => ems.authentication_userid, + :password => ems.authentication_password, + :insecure => true + ) connection if connection.test(true) end - + end end end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/collapsesnapshots.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/collapsesnapshots.rb index 08eeb0794..69a2702f6 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/collapsesnapshots.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/collapsesnapshots.rb @@ -8,12 +8,12 @@ class CollapseSnapshots def initialize(handle = $evm) @handle = handle end - + def main begin task = @handle.root['service_template_transformation_plan_task'] source_vm = task.source - + if source_vm.snapshots.empty? @handle.log(:info, "VM '#{source_vm.name}' has no snapshot. Nothing to do.") elsif task.get_option(:collapse_snapshots) @@ -24,7 +24,7 @@ def main raise "VM '#{source_vm.name}' has snapshots, but we are not allowed to collapse them. Exiting." end rescue Exception => e - @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + @handle.set_state_var(:ae_state_progress, 'message' => e.message) raise end end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/setmigrated.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/setmigrated.rb index 1b29ed62c..5cf311036 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/setmigrated.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/setmigrated.rb @@ -8,9 +8,9 @@ class SetMigrated def initialize(handle = $evm) @handle = handle end - + # Taken from / Service / Provisioning / StateMachines / Methods / configure_vm_hostname. - def check_name_collisions(vm, new_name) + def check_name_collisions(new_name) name_collisions = Hash.new(0) @handle.vmdb(:vm).where("name = '#{new_name}'").each do |vm| name_collisions[:active] += 1 if vm.active @@ -21,24 +21,24 @@ def check_name_collisions(vm, new_name) end name_collisions_summary = "" name_collisions.each { |k, v| name_collisions_summary += " - #{k}: #{v}" } - return name_collisions_summary + name_collisions_summary end - + def main begin exit MIQ_OK task = @handle.root['service_template_transformation_plan_task'] source_vm = task.source new_name = "#{source_vm.name}_migrated" - - name_collisions = check_name_collisions(source_vm, new_name) - raise "ERROR: #{new_name} already exists #{name_collisions}." unless name_collisions.blank? - + + name_collisions = check_name_collisions(new_name) + raise "ERROR: #{new_name} already exists #{name_collisions}." if name_collisions.present? + @handle.log(:info, "Renaming VM #{source_vm.name} to #{new_name}") result = ManageIQ::Automate::Transformation::Infrastructure::VM::VMware::Utils.vm_rename(source_vm, new_name) raise "VM rename for #{source_vm.name} to #{new_name} failed" unless result rescue Exception => e - @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + @handle.set_state_var(:ae_state_progress, 'message' => e.message) raise end end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.rb index 2cdcfcb9a..301548c04 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.rb @@ -17,60 +17,27 @@ def main def connect_to_provider(ems) ipaddress = ems.ipaddress ipaddress ||= ems.hostname - RbVmomi::VIM.connect(host: ipaddress, user: ems.authentication_userid, password: ems.authentication_password, insecure: true) + RbVmomi::VIM.connect(:host => ipaddress, :user => ems.authentication_userid, :password => ems.authentication_password, :insecure => true) end def vm_get_ref(vim, vm) dc = vim.serviceInstance.find_datacenter(vm.v_owning_datacenter) raise "Datacenter '#{vm.datacenter.name}' not found in vCenter" unless dc - vim.serviceInstance.content.searchIndex.FindByUuid(datacenter: dc, uuid: vm.uid_ems, vmSearch: true, instanceUuid: false) + vim.serviceInstance.content.searchIndex.FindByUuid(:datacenter => dc, :uuid => vm.uid_ems, :vmSearch => true, :instanceUuid => false) end - def self.get_vcenter_fingerprint(ems, handle=$evm) + def self.get_vcenter_fingerprint(ems, handle = $evm) command = "openssl s_client -connect #{ems.hostname}:443 2>\/dev\/null | openssl x509 -noout -fingerprint -sha1" ssl_fingerprint = `#{command}` - fingerprint = ssl_fingerprint[17..ssl_fingerprint.size-2] + fingerprint = ssl_fingerprint[17..ssl_fingerprint.size - 2] handle.log(:info, "vCenter fingerprint: #{fingerprint}") - return fingerprint - end - - def self.vm_rename_bill(vm, new_name, handle=$evm) - ems = vm.ext_management_system - ems_endpoint = ems.ipaddress || ems.hostname - vim = RbVmomi::VIM.connect(host: ems_endpoint, user: ems.authentication_userid, password: ems.authentication_password, insecure: true) - vm_ref = vm_get_ref(vim, vm) - - spec = RbVmomi::VIM::VirtualMachineConfigSpec(name: new_name) - task = vm_ref.ReconfigVM_Task(spec: spec) - - # Seems using the task.info.state returned by the ReconfigVM_Task is not trust worthy. It will return 'state' = 'running' - # and the later polls by the taskManager returns 'error', 'Another task is already in progress'... - # ...so lets wait for 5 seconds and ask then task manager what it thinks the real state is. - handle.log(:info, "task.info.state = #{task.info.state}") - handle.log(:info, "task.info.error.localMessage = #{task.info.error.localizedMessage}") if task.info.state == 'error' - - sleep(5) - tm = vim.serviceInstance.content.taskManager - tasks = tm.recentTask.select { |t| t.info.key == task.info.key } - raise "Cannot find task key #{task.info.key} in vCenter" unless tasks.any? - task = tasks.first - - handle.log(:info, "task manager says: task.info.state = #{task.info.state}") - handle.log(:info, "task manager says: task.info.error.localMessage = #{task.info.error.localizedMessage}") if task.info.state == 'error' - - if task.info.state == 'error' - raise "Delete disk error: #{task.info.error.localizedMessage}" unless task.info.error.localizedMessage.include?('Another task is already in progress') - handle.log(:info, "Delete disk cannot start due to another vCenter task running, Will retry in 30 seconds") - handle.root['ae_result'] = 'retry' - handle.root['ae_retry_interval'] = '30.seconds' - end - true + fingerprint end def self.vm_rename(vm, new_name, handle = $evm) ems = vm.ext_management_system ems_endpoint = ems.ipaddress || ems.hostname - vim = RbVmomi::VIM.connect(host: ems_endpoint, user: ems.authentication_userid, password: ems.authentication_password, insecure: true) + vim = RbVmomi::VIM.connect(:host => ems_endpoint, :user => ems.authentication_userid, :password => ems.authentication_password, :insecure => true) sleep 2 dc = vim.serviceInstance.find_datacenter(vm.v_owning_datacenter) @@ -78,10 +45,10 @@ def self.vm_rename(vm, new_name, handle = $evm) sleep 2 vim_vm = dc.find_vm(vm.name) - raise "Unable to locate #{vm.name} in data center #{dc}" + raise "Unable to locate #{vm.name} in data center #{dc}" unless vim_vm begin sleep 2 - vim_vm.ReconfigVM_Task(:spec => RbVmomi::VIM::VirtualMachineConfigSpec(:name=> new_name)).wait_for_completion + vim_vm.ReconfigVM_Task(:spec => RbVmomi::VIM::VirtualMachineConfigSpec(:name => new_name)).wait_for_completion sleep 2 dc.find_vm(new_name) handle.log(:info, "Successfully renamed #{options[:source_vm]} to #{options[:new_name]}.") diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.rb index a8f552f7e..4295e2762 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.rb @@ -8,43 +8,42 @@ def initialize(handle = $evm) @debug = true @handle = handle end - + def main end - def self.get_runners_count_by_host(host, handle=$evm) + def self.get_runners_count_by_host(host, handle = $evm) handle.vmdb(:service_template_transformation_plan_task).where(:state => 'active').select { |task| task.get_option(:transformation_host) == host }.size end def self.transformation_hosts(ems, method, factory_config) thosts = [] ems.hosts.each do |host| - if host.tagged_with?('v2v_transformation_host', 'true') && host.tagged_with?('v2v_transformation_method', method) - thosts << { - :host => host, - :runners => { - :current => self.get_runners_count_by_host(host), - :maximum => host.custom_get('Max Transformation Runners') || factory_config['transformation_host_max_runners'] || 1 - } + next unless host.tagged_with?('v2v_transformation_host', 'true') && host.tagged_with?('v2v_transformation_method', method) + thosts << { + :host => host, + :runners => { + :current => get_runners_count_by_host(host), + :maximum => host.custom_get('Max Transformation Runners') || factory_config['transformation_host_max_runners'] || 1 } - end + } end thosts.sort_by! { |th| th[:runners][:current] } end - + def self.eligible_transformation_hosts(ems, method, factory_config) - self.transformation_hosts(ems, method, factory_config).select { |thost| thost[:runners][:current] < thost[:runners][:maximum] } + transformation_hosts(ems, method, factory_config).select { |thost| thost[:runners][:current] < thost[:runners][:maximum] } end - + def self.get_runners_count_by_ems(ems, method, factory_config) - self.transformation_hosts(ems, method, factory_config).inject(0) { |sum, thost| sum + thost[:runners][:current] } + transformation_hosts(ems, method, factory_config).inject(0) { |sum, thost| sum + thost[:runners][:current] } end - def self.get_transformation_host(ems, method, factory_config, max_runners=nil) + def self.get_transformation_host(ems, method, factory_config, max_runners = nil) ems_max_runners = ems.custom_get('Max Transformation Runners') || factory_config['ems_max_runners'] || 1 - ems_cur_runners = self.get_runners_count_by_ems(ems, method, factory_config) - transformation_host = ems_cur_runners < ems_max_runners ? self.eligible_transformation_hosts(ems, method, factory_config).first[:host] : nil - return transformation_host + ems_cur_runners = get_runners_count_by_ems(ems, method, factory_config) + transformation_host = ems_cur_runners < ems_max_runners ? eligible_transformation_hosts(ems, method, factory_config).first[:host] : nil + transformation_host end end end diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.rb index d716769b4..b4bdc8606 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.rb @@ -7,10 +7,10 @@ class RoleCheck def initialize(handle = $evm) @handle = handle end - + def main playbook = "/usr/share/doc/ovirt-ansible-v2v-conversion-host-1.0.0/examples/conversion_host_check.yml" - extra_vars = { v2v_manageiq_conversion_host_check: true } + extra_vars = { :v2v_manageiq_conversion_host_check => true } result = Transformation::TransformationHosts::OVirtHost::Utils.ansible_playbook(@handle.root['host'], playbook, extra_vars) raise 'Conversion Host role is not enabled.' unless result[:rc].zero? diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roledisable.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roledisable.rb index 1752ac226..374ee19be 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roledisable.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roledisable.rb @@ -7,7 +7,7 @@ class RoleDisable def initialize(handle = $evm) @handle = handle end - + def main host = @handle.root['host'] playbook = "/usr/share/doc/ovirt-ansible-v2v-conversion-host-1.0.0/examples/conversion_host_disable.yml" diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roleenable.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roleenable.rb index 21d0e5566..185fa8c1a 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roleenable.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roleenable.rb @@ -7,7 +7,7 @@ class RoleEnable def initialize(handle = $evm) @handle = handle end - + def main host = @handle.root['host'] playbook = "/usr/share/doc/ovirt-ansible-v2v-conversion-host-1.0.0/examples/conversion_host_enable.yml" diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb index f501c57b5..697b2c2d1 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb @@ -12,28 +12,24 @@ def initialize(handle = $evm) def main begin require 'json' - + factory_config = @handle.get_state_var(:factory_config) raise "No factory config found. Aborting." if factory_config.nil? task = @handle.root['service_template_transformation_plan_task'] - source_vm = task.source - - # Get the virt-v2v start timestamp - start_timestamp = task.get_option(:virtv2v_started_on) # Retrieve transformation host transformation_host = @handle.vmdb(:host).find_by(:id => task.get_option(:transformation_host_id)) # Retrieve state of virt-v2v result = Transformation::TransformationHosts::OVirtHost::Utils.remote_command(transformation_host, "cat '#{task.get_option(:virtv2v_wrapper)['state_file']}'") - raise result[:stderr] unless result[:success] and not result[:stdout].empty? + raise result[:stderr] unless result[:success] && ! result[:stdout].empty? virtv2v_state = JSON.parse(result[:stdout]) @handle.log(:info, "VirtV2V State: #{virtv2v_state.inspect}") # Retrieve disks array virtv2v_disks = task.get_option(:virtv2v_disks) - virtv2v_disks = [virtv2v_disks] if virtv2v_disks.is_a?(Hash) + virtv2v_disks = [virtv2v_disks] if virtv2v_disks.kind_of?(Hash) @handle.log(:info, "Disks: #{virtv2v_disks.inspect}") if virtv2v_state['finished'].nil? @@ -44,23 +40,23 @@ def main raise "More than one disk matches '#{disk[:path]}'. Aborting." if matching_disks.length > 1 disk[:percent] = matching_disks.first['progress'] end - converted_disks = virtv2v_disks.select { |d| not d[:percent].zero? } + converted_disks = virtv2v_disks.reject { |d| d[:percent].zero? } @handle.log(:info, "Converted disks: #{converted_disks.inspect}") if converted_disks.empty? - @handle.set_state_var(:ae_state_progress, { 'message' => "Disks transformation is initializing.", 'percent' => 1 }) + @handle.set_state_var(:ae_state_progress, 'message' => "Disks transformation is initializing.", 'percent' => 1) else percent = 0 - converted_disks.each { |disk| percent += ( disk[:percent].to_f * disk[:weight].to_f / 100.0 ) } + converted_disks.each { |disk| percent += (disk[:percent].to_f * disk[:weight].to_f / 100.0) } message = "Converting disk #{converted_disks.length} / #{virtv2v_disks.length} [#{percent.round(2)}%]." - @handle.set_state_var(:ae_state_progress, { 'message' => message, 'percent' => percent.round(2) }) + @handle.set_state_var(:ae_state_progress, 'message' => message, 'percent' => percent.round(2)) end else - task.set_option(:virtv2v_finished_on, Time.now.strftime('%Y%m%d_%H%M')) + task.set_option(:virtv2v_finished_on, Time.now.utc.strftime('%Y%m%d_%H%M')) if virtv2v_state['return_code'].zero? virtv2v_disks.each { |d| d[:percent] = 100 } - @handle.set_state_var(:ae_state_progress, { 'message' => 'Disks transformation succeeded.', 'percent' => 100 }) + @handle.set_state_var(:ae_state_progress, 'message' => 'Disks transformation succeeded.', 'percent' => 100) else - @handle.set_state_var(:ae_state_progress, { 'message' => 'Disks transformation succeeded.'}) + @handle.set_state_var(:ae_state_progress, 'message' => 'Disks transformation succeeded.') raise "Disks transformation failed." end end @@ -74,7 +70,7 @@ def main @handle.log(:info, "Disk transformation is not finished. Checking in #{@handle.root['ae_retry_interval']}") end rescue Exception => e - @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + @handle.set_state_var(:ae_state_progress, 'message' => e.message) raise end end diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb index 56c6ea780..db595d35a 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb @@ -5,14 +5,14 @@ module TransformationHost module OVirtHost class VMTransform_vmwarews2rhevm_vddk def initialize(handle = $evm) - @debug = true + @debug = false @handle = handle end def main begin require 'json' - + factory_config = @handle.get_state_var(:factory_config) raise "No factory config found. Aborting." if factory_config.nil? @@ -26,7 +26,7 @@ def main raise "Invalid destination EMS type: #{destination_ems.emstype}. Aborting." unless destination_ems.emstype == "rhevm" # Get or create the virt-v2v start timestamp - start_timestamp = task.get_option(:virtv2v_started_on) || Time.now.strftime('%Y-%m-%d %H:%M:%S') + start_timestamp = task.get_option(:virtv2v_started_on) || Time.now.utc.strftime('%Y-%m-%d %H:%M:%S') # Retrieve transformation host transformation_host = @handle.vmdb(:host).find_by(:id => task.get_option(:transformation_host_id)) @@ -37,10 +37,6 @@ def main if Transformation::TransformationHosts::Common::Utils.get_runners_count_by_ems(destination_ems, @handle.get_state_var(:transformation_method), factory_config) >= max_runners @handle.log("Too many transformations running: (#{max_runners}). Retrying.") else - # Identify the RHV export domain - export_domain = destination_ems.storages.select { |s| s.storage_domain_type == 'export' }.first - task.set_option(:export_domain_id, export_domain.id) - # Collect the VMware connection information vmware_uri = "vpx://" vmware_uri += "#{source_ems.authentication_userid.gsub('@', '%40')}@#{source_ems.hostname}/" @@ -49,40 +45,40 @@ def main # Collect information about the disks to convert virtv2v_disks = task.get_option(:virtv2v_disks) - virtv2v_disks = [virtv2v_disks] if virtv2v_disks.is_a?(Hash) + virtv2v_disks = [virtv2v_disks] if virtv2v_disks.kind_of?(Hash) source_disks = virtv2v_disks.map { |disk| disk[:path] } @handle.log(:info, "Source VM Disks: #{source_disks}") # Collect information about the network mappings virtv2v_networks = task.get_option(:virtv2v_networks) - virtv2v_networks = [virtv2v_networks] if virtv2v_networks.is_a?(Hash) + virtv2v_networks = [virtv2v_networks] if virtv2v_networks.kind_of?(Hash) @handle.log(:info, "Network mappings: #{virtv2v_networks}") - + wrapper_options = { - vm_name: source_vm.name, - transport_method: 'vddk', - vmware_fingerprint: Transformation::Infrastructure::VM::VMware::Utils.get_vcenter_fingerprint(source_ems), - vmware_uri: vmware_uri, - vmware_password: source_ems.authentication_password, -# rhv_url: "https://#{destination_ems.authentication_userid.gsub('@', '%40')}@#{destination_ems.hostname}/ovirt-engine/api", - rhv_url: "https://#{destination_ems.hostname}/ovirt-engine/api", - rhv_cluster: destination_cluster.name, - rhv_storage: destination_storage.name, - rhv_password: destination_ems.authentication_password, - source_disks: source_disks, - network_mappings: virtv2v_networks + :vm_name => source_vm.name, + :transport_method => 'vddk', + :vmware_fingerprint => Transformation::Infrastructure::VM::VMware::Utils.get_vcenter_fingerprint(source_ems), + :vmware_uri => vmware_uri, + :vmware_password => source_ems.authentication_password, + :rhv_url => "https://#{destination_ems.hostname}/ovirt-engine/api", + :rhv_cluster => destination_cluster.name, + :rhv_storage => destination_storage.name, + :rhv_password => destination_ems.authentication_password, + :source_disks => source_disks, + :network_mappings => virtv2v_networks } - @handle.log(:info, "JSON Input:\n#{JSON.pretty_generate(wrapper_options)}") if @debug + # WARNING: Enable at your own risk, as it may lead to sensitive data leak + # @handle.log(:info, "JSON Input:\n#{JSON.pretty_generate(wrapper_options)}") if @debug @handle.log(:info, "Connecting to #{transformation_host.name} as #{transformation_host.authentication_userid}") if @debug @handle.log(:info, "Executing '/usr/bin/virt-v2v-wrapper.py'") - result = Transformation::TransformationHosts::OVirtHost::Utils.remote_command(transformation_host, "/usr/bin/virt-v2v-wrapper.py", stdin = wrapper_options.to_json) + result = Transformation::TransformationHosts::OVirtHost::Utils.remote_command(transformation_host, "/usr/bin/virt-v2v-wrapper.py", wrapper_options.to_json) raise result[:stderr] unless result[:success] # Record the wrapper files path @handle.log(:info, "Command stdout: #{result[:stdout]}") if @debug task.set_option(:virtv2v_wrapper, JSON.parse(result[:stdout])) - + # Record the status in the task object task.set_option(:virtv2v_started_on, start_timestamp) task.set_option(:virtv2v_status, 'active') @@ -94,7 +90,7 @@ def main @handle.root['ae_retry_interval'] = $evm.object['check_convert_interval'] || '1.minutes' end rescue Exception => e - @handle.set_state_var(:ae_state_progress, { 'message' => e.message }) + @handle.set_state_var(:ae_state_progress, 'message' => e.message) raise end end From d077995dbbd0c01038f1991547ef8d5aee3faad4 Mon Sep 17 00:00:00 2001 From: fdupont-redhat Date: Fri, 25 May 2018 12:39:42 +0200 Subject: [PATCH 05/12] Fix rubcocop errors - cont'd --- .../__methods__/assesstransformation.rb | 4 +- .../VM/rhevm.class/__methods__/utils.rb | 15 +++---- .../Common.class/__methods__/utils.rb | 6 +-- .../ovirt_host.class/__methods__/rolecheck.rb | 2 +- .../ovirt_host.class/__methods__/utils.rb | 40 +++++++++---------- .../vmchecktransformed_vmwarews2rhevm_vddk.rb | 2 +- 6 files changed, 33 insertions(+), 36 deletions(-) diff --git a/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb b/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb index 1001c09b3..0cdd0c998 100644 --- a/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb +++ b/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb @@ -6,7 +6,7 @@ class AssessTransformation SUPPORTED_SOURCE_EMS_TYPES = ['vmwarews'].freeze SUPPORTED_DESTINATION_EMS_TYPES = ['rhevm'].freeze REQUIRED_CUSTOM_ATTRIBUTES = { - 'rhevm' => %i[rhv_export_domain_id, rhv_cluster_id, rhv_storage_domain_id] + 'rhevm' => %i(rhv_export_domain_id rhv_cluster_id rhv_storage_domain_id) }.freeze def initialize(handle = $evm) @@ -44,7 +44,7 @@ def main source_storage = disk.storage destination_storage = task.transformation_destination(disk.storage) raise "[#{source_vm.name}] Disk #{disk.device_name} [#{source_storage.name}] has no mapping. Aborting." if destination_storage.nil? - virtv2v_disks << { :path => disk.filename, :size => disk.size, percent: 0, :weight => disk.size / source_vm.allocated_disk_storage * 100 } + virtv2v_disks << { :path => disk.filename, :size => disk.size, :percent => 0, :weight => disk.size / source_vm.allocated_disk_storage * 100 } end @handle.log(:info, "Source VM Disks #{virtv2v_disks}") task.set_option(:virtv2v_disks, virtv2v_disks) diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/utils.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/utils.rb index a677bf134..3b0a8a96f 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/utils.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/utils.rb @@ -10,7 +10,6 @@ module Infrastructure module VM module RedHat class Utils - def initialize(ems, handle = $evm) @debug = true @handle = handle @@ -18,11 +17,11 @@ def initialize(ems, handle = $evm) @connection = connection(@ems) end - def get_export_domain + def ems_get_export_domain storage_domains_service.list.select { |domain_service| domain_service.type == OvirtSDK4::StorageDomainType::EXPORT }.first end - def vm_import(vm_name, cluster, storage_domain) + def vm_import(vm_name, cluster, storage_domain) target_domain = storage_domains_service.list(:search => "name=#{storage_domain}").first raise "Can't find storage domain #{storage_domain}" if target_domain.blank? target_cluster = clusters_service.list(:search => "name=#{cluster}").first @@ -38,13 +37,13 @@ def vm_import(vm_name, cluster, storage_domain) def vm_delete_from_export_domain(vm_name) vm = vm_find_in_export_domain(vm_name) - raise "Can't find VM #{vm_name} on export domain" if vm.blank? + raise "Can't find VM #{vm_name} on export domain" if vm.blank? @handle.log(:info, "About to remove VM: #{vm_name}") export_domain_vm_service(vm.id).remove end def vm_find_by_name(vm_name) - vms_service.list(search: "name=#{vm_name}").first + vms_service.list(:search => "name=#{vm_name}").first end def vm_set_description(vm, description) @@ -101,7 +100,7 @@ def vm_get_disk_interfaces(vm) def ems_to_service_model(ems) raise "Invalid EMS" if ems.nil? # ems could be a numeric id or the ems object itself - unless ems.is_a?(DRb::DRbObject) && /Manager/.match(ems.type.demodulize) + unless ems.kind_of?(DRb::DRbObject) && /Manager/.match(ems.type.demodulize) if ems.to_s =~ /^\d{1,13}$/ ems = @handle.vmdb(:ems, ems) end @@ -122,7 +121,7 @@ def clusters_service end def export_domain_vms_service - export_domain = get_export_domain + export_domain = ems_get_export_domain raise "No export domain found!" if export_domain.blank? storage_domains_service.storage_domain_service(export_domain.id).vms_service end @@ -164,7 +163,6 @@ def connection(ems) ) connection if connection.test(true) end - end end end @@ -172,4 +170,3 @@ def connection(ems) end end end - diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.rb index 4295e2762..ab1671046 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.rb @@ -21,9 +21,9 @@ def self.transformation_hosts(ems, method, factory_config) ems.hosts.each do |host| next unless host.tagged_with?('v2v_transformation_host', 'true') && host.tagged_with?('v2v_transformation_method', method) thosts << { - :host => host, - :runners => { - :current => get_runners_count_by_host(host), + :host => host, + :runners => { + :current => get_runners_count_by_host(host), :maximum => host.custom_get('Max Transformation Runners') || factory_config['transformation_host_max_runners'] || 1 } } diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.rb index b4bdc8606..4a1a75bdb 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.rb @@ -3,7 +3,7 @@ module Automate module Transformation module TransformationHost module OVirtHost - class RoleCheck + class RoleCheck def initialize(handle = $evm) @handle = handle end diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/utils.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/utils.rb index 12e5c381b..f4a3e9dc3 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/utils.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/utils.rb @@ -3,32 +3,32 @@ module Automate module Transformation module TransformationHosts module OVirtHost - class Utils + class Utils def initialize(handle = $evm) @handle = handle end - - def self.remote_command(host, command, stdin=nil, run_as=nil) + + def self.remote_command(host, command, stdin = nil, run_as = nil) require "net/ssh" command = "sudo -u #{run_as} #{command}" unless run_as.nil? success, stdout, stderr, exit_code = true, '', '', nil Net::SSH.start(host.name, host.authentication_userid, :password => host.authentication_password) do |ssh| channel = ssh.open_channel do |channel| channel.request_pty unless run_as.nil? - channel.exec(command) do |channel, success| - if success - channel.on_data do |_, data| + channel.exec(command) do |ch, exec_success| + if exec_success + ch.on_data do |_, data| stdout += data.to_s end - channel.on_extended_data do |_, data| + ch.on_extended_data do |_, data| stderr += data.to_s end - channel.on_request("exit-status") do |ch,data| + ch.on_request("exit-status") do |_, data| exit_code = data.read_long end unless stdin.nil? - channel.send_data(stdin) - channel.eof! + ch.send_data(stdin) + ch.eof! end else success = false @@ -38,25 +38,25 @@ def self.remote_command(host, command, stdin=nil, run_as=nil) end channel.wait end - return { :success => success, :stdout => stdout, :stderr => stderr, :rc => exit_code } + { :success => success, :stdout => stdout, :stderr => stderr, :rc => exit_code } end - + def self.ansible_playbook(host, playbook, extra_vars) require "net/ssh" command = "ansible-playbook -i #{host.name}, #{playbook}" - extra_vars.each { |k,v| command += " -e '#{k}=#{v}'" } + extra_vars.each { |k, v| command += " -e '#{k}=#{v}'" } success, stdout, stderr, exit_code = true, '', '', nil Net::SSH.start(host.ext_management_system.hostname, 'root') do |ssh| - channel = ssh.open_channel do |channel| - channel.exec(command) do |channel, success| - if success - channel.on_data do |_, data| + channel = ssh.open_channel do |channel| + channel.exec(command) do |ch, exec_success| + if exec_success + ch.on_data do |_, data| stdout += data.to_s end - channel.on_extended_data do |_, data| + ch.on_extended_data do |_, data| stderr += data.to_s end - channel.on_request("exit-status") do |ch,data| + ch.on_request("exit-status") do |_, data| exit_code = data.read_long end else @@ -67,7 +67,7 @@ def self.ansible_playbook(host, playbook, extra_vars) end channel.wait end - return { :success => success, :stdout => stdout, :stderr => stderr, :rc => exit_code } + { :success => success, :stdout => stdout, :stderr => stderr, :rc => exit_code } end end end diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb index 697b2c2d1..42312b0cc 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb @@ -23,7 +23,7 @@ def main # Retrieve state of virt-v2v result = Transformation::TransformationHosts::OVirtHost::Utils.remote_command(transformation_host, "cat '#{task.get_option(:virtv2v_wrapper)['state_file']}'") - raise result[:stderr] unless result[:success] && ! result[:stdout].empty? + raise result[:stderr] unless result[:success] && !result[:stdout].empty? virtv2v_state = JSON.parse(result[:stdout]) @handle.log(:info, "VirtV2V State: #{virtv2v_state.inspect}") From b71eafdfe04781a8d7fe8f2dc095d197f33571d3 Mon Sep 17 00:00:00 2001 From: fdupont-redhat Date: Fri, 25 May 2018 16:51:24 +0200 Subject: [PATCH 06/12] Fix rubocop errors - cont'd --- .../__methods__/acquiretransformationhost.rb | 2 +- .../Common.class/__methods__/utils.rb | 2 +- .../ovirt_host.class/__methods__/rolecheck.rb | 2 +- .../ovirt_host.class/__methods__/roledisable.rb | 2 +- .../ovirt_host.class/__methods__/roleenable.rb | 2 +- .../ovirt_host.class/__methods__/utils.rb | 10 +++++----- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.rb b/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.rb index fe118648f..cda908661 100644 --- a/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.rb +++ b/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.rb @@ -22,7 +22,7 @@ def main destination_ems = task.transformation_destination(source_cluster).ext_management_system raise "Invalid destination EMS type: #{destination_ems.emstype}. Aborting." unless destination_ems.emstype == "rhevm" - transformation_host = ManageIQ::Automate::Transformation::TransformationHosts::Common::Utils.get_transformation_host(destination_ems, 'vddk', factory_config) + transformation_host = ManageIQ::Automate::Transformation::TransformationHosts::Common::Utils.get_transformation_host(destination_ems, @handle.get_state_var(:transformation_method), factory_config) if transformation_host.nil? @handle.log(:info, "No transformation host available. Retrying.") @handle.root['ae_result'] = 'retry' diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.rb index ab1671046..03158426d 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/utils.rb @@ -39,7 +39,7 @@ def self.get_runners_count_by_ems(ems, method, factory_config) transformation_hosts(ems, method, factory_config).inject(0) { |sum, thost| sum + thost[:runners][:current] } end - def self.get_transformation_host(ems, method, factory_config, max_runners = nil) + def self.get_transformation_host(ems, method, factory_config) ems_max_runners = ems.custom_get('Max Transformation Runners') || factory_config['ems_max_runners'] || 1 ems_cur_runners = get_runners_count_by_ems(ems, method, factory_config) transformation_host = ems_cur_runners < ems_max_runners ? eligible_transformation_hosts(ems, method, factory_config).first[:host] : nil diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.rb index 4a1a75bdb..0b6fa49e5 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/rolecheck.rb @@ -9,7 +9,7 @@ def initialize(handle = $evm) end def main - playbook = "/usr/share/doc/ovirt-ansible-v2v-conversion-host-1.0.0/examples/conversion_host_check.yml" + playbook = "/usr/share/doc/ovirt-ansible-v2v-conversion-host-1.2.0/examples/conversion_host_check.yml" extra_vars = { :v2v_manageiq_conversion_host_check => true } result = Transformation::TransformationHosts::OVirtHost::Utils.ansible_playbook(@handle.root['host'], playbook, extra_vars) diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roledisable.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roledisable.rb index 374ee19be..0c78a02fa 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roledisable.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roledisable.rb @@ -10,7 +10,7 @@ def initialize(handle = $evm) def main host = @handle.root['host'] - playbook = "/usr/share/doc/ovirt-ansible-v2v-conversion-host-1.0.0/examples/conversion_host_disable.yml" + playbook = "/usr/share/doc/ovirt-ansible-v2v-conversion-host-1.2.0/examples/conversion_host_disable.yml" extra_vars = {} result = Transformation::TransformationHosts::OVirtHost::Utils.ansible_playbook(host, playbook, extra_vars) diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roleenable.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roleenable.rb index 185fa8c1a..067aef809 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roleenable.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/roleenable.rb @@ -10,7 +10,7 @@ def initialize(handle = $evm) def main host = @handle.root['host'] - playbook = "/usr/share/doc/ovirt-ansible-v2v-conversion-host-1.0.0/examples/conversion_host_enable.yml" + playbook = "/usr/share/doc/ovirt-ansible-v2v-conversion-host-1.2.0/examples/conversion_host_enable.yml" extra_vars = {} extra_vars[:v2v_vddk_package_name] = "VMware-vix-disklib-stable.tar.gz" extra_vars[:v2v_vddk_package_url] = "http://#{host.ext_management_system.hostname}/vddk/#{extra_vars[:v2v_vddk_package_name]}" diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/utils.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/utils.rb index f4a3e9dc3..b7fad90ca 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/utils.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/utils.rb @@ -13,9 +13,9 @@ def self.remote_command(host, command, stdin = nil, run_as = nil) command = "sudo -u #{run_as} #{command}" unless run_as.nil? success, stdout, stderr, exit_code = true, '', '', nil Net::SSH.start(host.name, host.authentication_userid, :password => host.authentication_password) do |ssh| - channel = ssh.open_channel do |channel| - channel.request_pty unless run_as.nil? - channel.exec(command) do |ch, exec_success| + channel = ssh.open_channel do |chan| + chan.request_pty unless run_as.nil? + chan.exec(command) do |ch, exec_success| if exec_success ch.on_data do |_, data| stdout += data.to_s @@ -47,8 +47,8 @@ def self.ansible_playbook(host, playbook, extra_vars) extra_vars.each { |k, v| command += " -e '#{k}=#{v}'" } success, stdout, stderr, exit_code = true, '', '', nil Net::SSH.start(host.ext_management_system.hostname, 'root') do |ssh| - channel = ssh.open_channel do |channel| - channel.exec(command) do |ch, exec_success| + channel = ssh.open_channel do |chan| + chan.exec(command) do |ch, exec_success| if exec_success ch.on_data do |_, data| stdout += data.to_s From 876ecbdee74c75fe3f22e8baeaf482c6028bf8ba Mon Sep 17 00:00:00 2001 From: fdupont-redhat Date: Tue, 29 May 2018 18:48:09 +0200 Subject: [PATCH 07/12] Fix disks and networks enumeration: x.get_option(:my_key) only returns the first element of an array. Using x[:options][:my_key] instead. --- .../__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb | 3 +-- .../__methods__/vmtransform_vmwarews2rhevm_vddk.rb | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb index 42312b0cc..5e7a9f109 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb @@ -28,8 +28,7 @@ def main @handle.log(:info, "VirtV2V State: #{virtv2v_state.inspect}") # Retrieve disks array - virtv2v_disks = task.get_option(:virtv2v_disks) - virtv2v_disks = [virtv2v_disks] if virtv2v_disks.kind_of?(Hash) + virtv2v_disks = task[:options][:virtv2v_disks] @handle.log(:info, "Disks: #{virtv2v_disks.inspect}") if virtv2v_state['finished'].nil? diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb index db595d35a..0584d16a3 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb @@ -44,14 +44,12 @@ def main vmware_uri += "?no_verify=1" # Collect information about the disks to convert - virtv2v_disks = task.get_option(:virtv2v_disks) - virtv2v_disks = [virtv2v_disks] if virtv2v_disks.kind_of?(Hash) + virtv2v_disks = task[:options][:virtv2v_disks] source_disks = virtv2v_disks.map { |disk| disk[:path] } @handle.log(:info, "Source VM Disks: #{source_disks}") # Collect information about the network mappings - virtv2v_networks = task.get_option(:virtv2v_networks) - virtv2v_networks = [virtv2v_networks] if virtv2v_networks.kind_of?(Hash) + virtv2v_networks = task[:options][:virtv2v_networks] @handle.log(:info, "Network mappings: #{virtv2v_networks}") wrapper_options = { From 4a5e5dcdded71f869c699830ad5e0ec9c13b276b Mon Sep 17 00:00:00 2001 From: fdupont-redhat Date: Wed, 30 May 2018 15:43:36 +0200 Subject: [PATCH 08/12] Add an attribute to the virt-v2v-wrapper options hash to force drivers installation. --- .../__methods__/vmtransform_vmwarews2rhevm_vddk.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb index 0584d16a3..fedf5a24c 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb @@ -63,7 +63,8 @@ def main :rhv_storage => destination_storage.name, :rhv_password => destination_ems.authentication_password, :source_disks => source_disks, - :network_mappings => virtv2v_networks + :network_mappings => virtv2v_networks, + :install_drivers => true } # WARNING: Enable at your own risk, as it may lead to sensitive data leak # @handle.log(:info, "JSON Input:\n#{JSON.pretty_generate(wrapper_options)}") if @debug From efdd8c9d2e42cadba72ed80385263b55ce0d05c6 Mon Sep 17 00:00:00 2001 From: fdupont-redhat Date: Wed, 30 May 2018 19:47:11 +0200 Subject: [PATCH 09/12] Fix rubocop errors - cont'd --- .../Infrastructure/VM/vmwarews.class/__methods__/utils.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.rb index 301548c04..c40e00b29 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/utils.rb @@ -57,7 +57,6 @@ def self.vm_rename(vm, new_name, handle = $evm) end true end - end end end From 1a77e7a372a62f585b033265064efe6d97b24d83 Mon Sep 17 00:00:00 2001 From: fdupont-redhat Date: Thu, 31 May 2018 13:56:47 +0200 Subject: [PATCH 10/12] Fix disk size handling. Remove state that enforce virtio-scsi driver. --- .../Common.class/__methods__/assesstransformation.rb | 2 +- .../VMTransformation.class/vmwarews2rhevm_vddk.yaml | 10 +--------- .../__methods__/vmtransform_vmwarews2rhevm_vddk.rb | 3 ++- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb b/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb index 0cdd0c998..7cd808ac2 100644 --- a/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb +++ b/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb @@ -44,7 +44,7 @@ def main source_storage = disk.storage destination_storage = task.transformation_destination(disk.storage) raise "[#{source_vm.name}] Disk #{disk.device_name} [#{source_storage.name}] has no mapping. Aborting." if destination_storage.nil? - virtv2v_disks << { :path => disk.filename, :size => disk.size, :percent => 0, :weight => disk.size / source_vm.allocated_disk_storage * 100 } + virtv2v_disks << { :path => disk.filename, :size => disk.size, :percent => 0, :weight => disk.size.to_f / source_vm.allocated_disk_storage.to_f * 100 } end @handle.log(:info, "Source VM Disks #{virtv2v_disks}") task.set_option(:virtv2v_disks, virtv2v_disks) diff --git a/content/automate/ManageIQ/Transformation/StateMachines/VMTransformation.class/vmwarews2rhevm_vddk.yaml b/content/automate/ManageIQ/Transformation/StateMachines/VMTransformation.class/vmwarews2rhevm_vddk.yaml index 139474bb4..7af947659 100644 --- a/content/automate/ManageIQ/Transformation/StateMachines/VMTransformation.class/vmwarews2rhevm_vddk.yaml +++ b/content/automate/ManageIQ/Transformation/StateMachines/VMTransformation.class/vmwarews2rhevm_vddk.yaml @@ -43,14 +43,6 @@ object: on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description => "Update description of VM", task_message => "Migrating") - State5: - value: "/Transformation/Infrastructure/VM/${state_var#destination_ems_type}/EnableVirtIOSCSI" - on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Enable Virtio-SCSI for VM", task_message => "Migrating") - on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Enable Virtio-SCSI for VM", task_message => "Migrating") - on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description - => "Enable Virtio-SCSI for VM", task_message => "Migrating") - - State6: value: "/Transformation/Infrastructure/VM/Common/PowerOn" on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description => "Power-on VM", task_message => "Migrating") @@ -58,7 +50,7 @@ object: => "Power-on VM", task_message => "Migrating") on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description => "Power-on VM", task_message => "Migrating") - - State7: + - State6: value: "/Transformation/Infrastructure/VM/${state_var#destination_ems_type}/CheckPoweredOn" on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 7, description => "Power-on VM", task_message => "Migrating") diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb index fedf5a24c..0cd892195 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb @@ -66,13 +66,14 @@ def main :network_mappings => virtv2v_networks, :install_drivers => true } + # WARNING: Enable at your own risk, as it may lead to sensitive data leak # @handle.log(:info, "JSON Input:\n#{JSON.pretty_generate(wrapper_options)}") if @debug @handle.log(:info, "Connecting to #{transformation_host.name} as #{transformation_host.authentication_userid}") if @debug @handle.log(:info, "Executing '/usr/bin/virt-v2v-wrapper.py'") result = Transformation::TransformationHosts::OVirtHost::Utils.remote_command(transformation_host, "/usr/bin/virt-v2v-wrapper.py", wrapper_options.to_json) - raise result[:stderr] unless result[:success] + raise result[:stderr] unless result[:rc].zero? # Record the wrapper files path @handle.log(:info, "Command stdout: #{result[:stdout]}") if @debug From f365d210d6e50f4a9291330db6dc45d0fd890093 Mon Sep 17 00:00:00 2001 From: fdupont-redhat Date: Thu, 31 May 2018 14:15:35 +0200 Subject: [PATCH 11/12] Removed unused method --- .../__methods__/enablevirtioscsi.rb | 33 ------------------- .../__methods__/enablevirtioscsi.yaml | 15 --------- 2 files changed, 48 deletions(-) delete mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.rb delete mode 100644 content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.yaml diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.rb deleted file mode 100644 index 7a8d48b53..000000000 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.rb +++ /dev/null @@ -1,33 +0,0 @@ -module ManageIQ - module Automate - module Transformation - module Infrastructure - module VM - module RedHat - class EnableVirtIOSCSI - def initialize(handle = $evm) - @handle = handle - end - - def main - begin - task = @handle.root['service_template_transformation_plan_task'] - destination_vm = @handle.vmdb(:vm).find_by(:id => task.get_option(:destination_vm_id)) - destination_ems = destination_vm.ext_management_system - ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::Utils.new(destination_ems).vm_enable_virtio_scsi(destination_vm) - rescue Exception => e - @handle.set_state_var(:ae_state_progress, 'message' => e.message) - raise - end - end - end - end - end - end - end - end -end - -if $PROGRAM_NAME == __FILE__ - ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::EnableVirtIOSCSI.new.main -end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.yaml b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.yaml deleted file mode 100644 index 1d4984f45..000000000 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/enablevirtioscsi.yaml +++ /dev/null @@ -1,15 +0,0 @@ ---- -object_type: method -version: 1.0 -object: - attributes: - name: EnableVirtIOSCSI - display_name: - description: - scope: instance - language: ruby - location: inline - embedded_methods: - - "/Transformation/Infrastructure/VM/rhevm/Utils" - options: {} - inputs: [] From 20ce58389b7a31550901abdc074873ff86569c2e Mon Sep 17 00:00:00 2001 From: fdupont-redhat Date: Thu, 31 May 2018 15:06:22 +0200 Subject: [PATCH 12/12] Fix rubocop error - cont'd --- .../__methods__/weighted_update_status.rb | 137 --------------- .../__methods__/weighted_update_status.yaml | 53 ------ .../__methods__/acquiretransformationhost.rb | 50 +++--- .../__methods__/assesstransformation.rb | 100 ++++++----- .../VM/Common.class/__methods__/poweroff.rb | 34 ++-- .../VM/Common.class/__methods__/poweron.rb | 14 +- .../rhevm.class/__methods__/checkpoweredon.rb | 24 ++- .../__methods__/checkvmininventory.rb | 52 +++--- .../rhevm.class/__methods__/setdescription.rb | 18 +- .../__methods__/collapsesnapshots.rb | 28 ++- .../vmwarews.class/__methods__/setmigrated.rb | 26 ++- .../vmchecktransformed_vmwarews2rhevm_vddk.rb | 104 ++++++----- .../vmtransform_vmwarews2rhevm_vddk.rb | 165 +++++++++--------- 13 files changed, 296 insertions(+), 509 deletions(-) delete mode 100644 content/automate/ManageIQ/System/CommonMethods/MiqAe.class/__methods__/weighted_update_status.rb delete mode 100644 content/automate/ManageIQ/System/CommonMethods/MiqAe.class/__methods__/weighted_update_status.yaml diff --git a/content/automate/ManageIQ/System/CommonMethods/MiqAe.class/__methods__/weighted_update_status.rb b/content/automate/ManageIQ/System/CommonMethods/MiqAe.class/__methods__/weighted_update_status.rb deleted file mode 100644 index 5c12c6629..000000000 --- a/content/automate/ManageIQ/System/CommonMethods/MiqAe.class/__methods__/weighted_update_status.rb +++ /dev/null @@ -1,137 +0,0 @@ -module ManageIQ - module Automate - module System - module CommonMethods - module MiqAe - class WeightedUpdateStatus - def initialize(handle = $evm) - @handle = handle - end - - # This method gets the current state, even in the context of nested - # state machines. Where running a nested state machines, there can be - # more than one active states: one per level of nesting. The real - # active state is the one with the deepest ancestry. - def current_state(states) - active_states = states.select { |_, v| v['status'] == 'active' }.keys - states_depth = active_states.map { |state| state.split('/').length } - active_states[states_depth.index(states_depth.max)] - end - - # This method recusrively collects the progress of children states - # and weight them, to finally weight the result with the current state - # weight. - def reconcile_states_percent(path, states) - direct_children = states.reject { |k, _| k.gsub(/^#{path}\//, '').include?('/') } - return states[path]['percent'] if direct_children.empty? - percent = 0 - direct_children.each_key { |dc_path| percent += reconcile_states_percent(dc_path, states).to_f * states[dc_path]['weight'].to_f / 100.0 } - percent - end - - def on_entry(state_hash, _, _, state_weight, state_description) - # Initiate the state hash if it doesn't exist yet - state_hash ||= { 'status' => 'active', 'weight' => state_weight, 'description' => state_description, 'message' => state_description } - # Add the start date and set percentage to 0 if entering the - # state for the first time (retries count == 0) - if @handle.root['ae_state_retries'].to_i.zero? - state_hash['started_on'] = Time.now.utc - state_hash['percent'] = 0.0 - end - state_hash - end - - def on_exit(state_hash, state_progress, state_name, _, _) - @handle.log(:info, "State Progress: #{state_progress.inspect}") - # If the state is retrying, we leave the status to 'active'. - if @handle.root['ae_result'] == 'retry' - # If the method provides progress info, it is merged, otherwise we set - # it based on current retry and max retries. - if state_progress.nil? - state_hash['message'] = "#{state_name} is not finished yet [#{@handle.root['ae_state_retries']}/#{@handle.root['ae_state_max_retries']} retries]." - state_hash['percent'] = @handle.root['ae_state_retries'].to_f / @handle.root['ae_state_max_retries'].to_f * 100.0 - else - # We also merge the potential message from method. - state_hash.merge!(state_progress) - end - # If we don't retry, it means that the state is finished, so We also merge - # the potential message from method. - else - # We set status to 'finished' and percentage to 100. - state_hash['status'] = 'finished' - state_hash['percent'] = 100.0 - state_hash['message'] = state_progress.nil? ? "#{state_name} is finished." : state_progress['message'] - end - # Then, we set the update time to now, which is also finish time - # when the state is finished. - state_hash['updated_on'] = Time.now.utc - state_hash - end - - def on_error(state_hash, state_progress, state_name, _, _) - # The state has failed, so we consider it as finished and 100%. - state_hash['status'] = 'failed' - state_hash['percent'] = 100.0 - # We merge the potential message from method and set the update time. - state_hash['message'] = state_progress.nil? ? "#{state_name} has failed." : state_progress['message'] - state_hash['updated_on'] = Time.now.utc - state_hash - end - - def main - vmdb_object_type = @handle.root['vmdb_object_type'] - if vmdb_object_type =~ /^service_template_[\w\d]+_task$/ - task = @handle.root[vmdb_object_type] - raise @handle.root.attributes.inspect if task.nil? - unless task.nil? - # Initiate the task progress hash if it doesn't exist yet - progress = task.get_option(:progress) || { 'current_state' => '', 'current_description' => '', 'percent' => 0.0, 'states' => {} } - - # Collect the state details - state_name = @handle.root['ae_state'] - state_ancestry = @handle.object['state_ancestry'].to_s - state_description = @handle.inputs['description'] || state_name - state_weight = @handle.inputs['weight'] || 0 - - # Updating the current state hash with method progress - state_hash = send( - @handle.root['ae_state_step'], - progress['states']["#{state_ancestry}/#{state_name}"], - @handle.get_state_var('ae_state_progress'), - state_name, - state_weight, - state_description - ) - @handle.log(:info, "State Hash: #{state_hash.inspect}") - - # We record the state hash in the task progress - progress['states']["#{state_ancestry}/#{state_name}"] = state_hash - @handle.log(:info, "Progress: #{progress}") - # If we enter the state, we update the task progress with current - # state and description. - if @handle.root['ae_status_state'] == 'on_entry' - progress['current_state'] = current_state(progress['states']) - progress['current_description'] = progress['states'][progress['current_state']]['description'] - # End if we exit/error the state, we update the percentage based on - # children states and current state weight. - else - progress['percent'] = reconcile_states_percent('', progress['states']).round(2) - end - # We clear the ae_state_progress state var - @handle.set_state_var('ae_state_progress', nil) - # We record the progress as a task option. - task.update_transformation_progress(progress) - @handle.log(:info, "Task: #{task.get_option(:progress)}") - end - end - end - end - end - end - end - end -end - -if $PROGRAM_NAME == __FILE__ - ManageIQ::Automate::System::CommonMethods::MiqAe::WeightedUpdateStatus.new.main -end diff --git a/content/automate/ManageIQ/System/CommonMethods/MiqAe.class/__methods__/weighted_update_status.yaml b/content/automate/ManageIQ/System/CommonMethods/MiqAe.class/__methods__/weighted_update_status.yaml deleted file mode 100644 index f6c867f96..000000000 --- a/content/automate/ManageIQ/System/CommonMethods/MiqAe.class/__methods__/weighted_update_status.yaml +++ /dev/null @@ -1,53 +0,0 @@ ---- -object_type: method -version: 1.0 -object: - attributes: - name: WeightedUpdateStatus - display_name: - description: - scope: instance - language: ruby - location: inline - options: {} - inputs: - - field: - aetype: - name: weight - display_name: - datatype: integer - priority: 1 - owner: - default_value: '0' - substitute: false - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: - - field: - aetype: - name: description - display_name: - datatype: string - priority: 2 - owner: - default_value: _ - substitute: false - message: create - visibility: - collect: - scope: - description: - condition: - on_entry: - on_exit: - on_error: - max_retries: - max_time: diff --git a/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.rb b/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.rb index cda908661..5bde90efd 100644 --- a/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.rb +++ b/content/automate/ManageIQ/Transformation/Common.class/__methods__/acquiretransformationhost.rb @@ -8,35 +8,33 @@ def initialize(handle = $evm) end def main - begin - factory_config = @handle.get_state_var(:factory_config) - raise "No factory config found. Aborting." if factory_config.nil? + factory_config = @handle.get_state_var(:factory_config) + raise "No factory config found. Aborting." if factory_config.nil? - task = @handle.root['service_template_transformation_plan_task'] - @handle.log(:info, "Task: #{task.inspect}") - source_vm = task.source - @handle.log(:info, "Source VM: #{source_vm.name}") - source_cluster = source_vm.ems_cluster - @handle.log(:info, "Source Cluster: #{source_cluster.name}") - @handle.log(:info, "Destination Cluster: #{task.transformation_destination(source_cluster).name}") - destination_ems = task.transformation_destination(source_cluster).ext_management_system - raise "Invalid destination EMS type: #{destination_ems.emstype}. Aborting." unless destination_ems.emstype == "rhevm" + task = @handle.root['service_template_transformation_plan_task'] + @handle.log(:info, "Task: #{task.inspect}") + source_vm = task.source + @handle.log(:info, "Source VM: #{source_vm.name}") + source_cluster = source_vm.ems_cluster + @handle.log(:info, "Source Cluster: #{source_cluster.name}") + @handle.log(:info, "Destination Cluster: #{task.transformation_destination(source_cluster).name}") + destination_ems = task.transformation_destination(source_cluster).ext_management_system + raise "Invalid destination EMS type: #{destination_ems.emstype}. Aborting." unless destination_ems.emstype == "rhevm" - transformation_host = ManageIQ::Automate::Transformation::TransformationHosts::Common::Utils.get_transformation_host(destination_ems, @handle.get_state_var(:transformation_method), factory_config) - if transformation_host.nil? - @handle.log(:info, "No transformation host available. Retrying.") - @handle.root['ae_result'] = 'retry' - @handle.root['ae_retry_server_affinity'] = true - @handle.root['ae_retry_interval'] = $evm.object['check_convert_interval'] || '1.minutes' - else - @handle.log(:info, "Transformation Host: #{transformation_host.name}.") - task.set_option(:transformation_host_id, transformation_host.id) - task.set_option(:transformation_host_name, transformation_host.name) - end - rescue Exception => e - @handle.set_state_var(:ae_state_progress, 'message' => e.message) - raise + transformation_host = ManageIQ::Automate::Transformation::TransformationHosts::Common::Utils.get_transformation_host(destination_ems, @handle.get_state_var(:transformation_method), factory_config) + if transformation_host.nil? + @handle.log(:info, "No transformation host available. Retrying.") + @handle.root['ae_result'] = 'retry' + @handle.root['ae_retry_server_affinity'] = true + @handle.root['ae_retry_interval'] = $evm.object['check_convert_interval'] || '1.minutes' + else + @handle.log(:info, "Transformation Host: #{transformation_host.name}.") + task.set_option(:transformation_host_id, transformation_host.id) + task.set_option(:transformation_host_name, transformation_host.name) end + rescue => e + @handle.set_state_var(:ae_state_progress, 'message' => e.message) + raise end end end diff --git a/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb b/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb index 7cd808ac2..eef6ef56d 100644 --- a/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb +++ b/content/automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformation.rb @@ -14,69 +14,67 @@ def initialize(handle = $evm) end def main - begin - task = @handle.root['service_template_transformation_plan_task'] - raise 'No task found. Exiting' if task.nil? - @handle.log(:info, "Task: #{task.inspect}") if @debug + task = @handle.root['service_template_transformation_plan_task'] + raise 'No task found. Exiting' if task.nil? + @handle.log(:info, "Task: #{task.inspect}") if @debug - source_vm ||= task.source - raise 'No VM found. Exiting' if source_vm.nil? + source_vm ||= task.source + raise 'No VM found. Exiting' if source_vm.nil? - source_cluster = source_vm.ems_cluster - destination_cluster = task.transformation_destination(source_cluster) - raise "No destination cluster for '#{source_vm.name}'. Exiting." if destination_cluster.nil? + source_cluster = source_vm.ems_cluster + destination_cluster = task.transformation_destination(source_cluster) + raise "No destination cluster for '#{source_vm.name}'. Exiting." if destination_cluster.nil? - source_ems = source_vm.ext_management_system - destination_ems = destination_cluster.ext_management_system + source_ems = source_vm.ext_management_system + destination_ems = destination_cluster.ext_management_system - virtv2v_networks = [] - source_vm.hardware.nics.select { |n| n.device_type == 'ethernet' }.each do |nic| - source_network = nic.lan - destination_network = task.transformation_destination(source_network) - raise "[#{source_vm.name}] NIC #{nic.device_name} [#{source_network.name}] has no mapping. Aborting." if destination_network.nil? - virtv2v_networks << { :source => source_network.name, :destination => destination_network.name } - end - @handle.log(:info, "Network mappings: #{virtv2v_networks}") - task.set_option(:virtv2v_networks, virtv2v_networks) + virtv2v_networks = [] + source_vm.hardware.nics.select { |n| n.device_type == 'ethernet' }.each do |nic| + source_network = nic.lan + destination_network = task.transformation_destination(source_network) + raise "[#{source_vm.name}] NIC #{nic.device_name} [#{source_network.name}] has no mapping. Aborting." if destination_network.nil? + virtv2v_networks << { :source => source_network.name, :destination => destination_network.name } + end + @handle.log(:info, "Network mappings: #{virtv2v_networks}") + task.set_option(:virtv2v_networks, virtv2v_networks) - virtv2v_disks = [] - source_vm.hardware.disks.select { |d| d.device_type == 'disk' }.each do |disk| - source_storage = disk.storage - destination_storage = task.transformation_destination(disk.storage) - raise "[#{source_vm.name}] Disk #{disk.device_name} [#{source_storage.name}] has no mapping. Aborting." if destination_storage.nil? - virtv2v_disks << { :path => disk.filename, :size => disk.size, :percent => 0, :weight => disk.size.to_f / source_vm.allocated_disk_storage.to_f * 100 } - end - @handle.log(:info, "Source VM Disks #{virtv2v_disks}") - task.set_option(:virtv2v_disks, virtv2v_disks) + virtv2v_disks = [] + source_vm.hardware.disks.select { |d| d.device_type == 'disk' }.each do |disk| + source_storage = disk.storage + destination_storage = task.transformation_destination(disk.storage) + raise "[#{source_vm.name}] Disk #{disk.device_name} [#{source_storage.name}] has no mapping. Aborting." if destination_storage.nil? + virtv2v_disks << { :path => disk.filename, :size => disk.size, :percent => 0, :weight => disk.size.to_f / source_vm.allocated_disk_storage.to_f * 100 } + end + @handle.log(:info, "Source VM Disks #{virtv2v_disks}") + task.set_option(:virtv2v_disks, virtv2v_disks) - raise "Unsupported source EMS type: #{source_ems.emstype}." unless SUPPORTED_SOURCE_EMS_TYPES.include?(source_ems.emstype) - @handle.set_state_var(:source_ems_type, source_ems.emstype) + raise "Unsupported source EMS type: #{source_ems.emstype}." unless SUPPORTED_SOURCE_EMS_TYPES.include?(source_ems.emstype) + @handle.set_state_var(:source_ems_type, source_ems.emstype) - raise "Unsupported destination EMS type: #{destination_ems.emstype}." unless SUPPORTED_DESTINATION_EMS_TYPES.include?(destination_ems.emstype) - @handle.set_state_var(:destination_ems_type, destination_ems.emstype) + raise "Unsupported destination EMS type: #{destination_ems.emstype}." unless SUPPORTED_DESTINATION_EMS_TYPES.include?(destination_ems.emstype) + @handle.set_state_var(:destination_ems_type, destination_ems.emstype) - transformation_type = "#{source_ems.emstype}2#{destination_ems.emstype}" - @handle.set_state_var(:transformation_type, transformation_type) + transformation_type = "#{source_ems.emstype}2#{destination_ems.emstype}" + @handle.set_state_var(:transformation_type, transformation_type) - transformation_method = "vddk" - @handle.set_state_var(:transformation_method, transformation_method) + transformation_method = "vddk" + @handle.set_state_var(:transformation_method, transformation_method) - transformation_host_type = "ovirt_host" - @handle.set_state_var(:transformation_host_type, transformation_host_type) + transformation_host_type = "ovirt_host" + @handle.set_state_var(:transformation_host_type, transformation_host_type) - factory_config = { - 'vmtransformation_check_interval' => @handle.object['vmtransformation_check_interval'] || '15.seconds', - 'vmpoweroff_check_interval' => @handle.object['vmpoweroff_check_interval'] || '30.seconds' - } - @handle.set_state_var(:factory_config, factory_config) + factory_config = { + 'vmtransformation_check_interval' => @handle.object['vmtransformation_check_interval'] || '15.seconds', + 'vmpoweroff_check_interval' => @handle.object['vmpoweroff_check_interval'] || '30.seconds' + } + @handle.set_state_var(:factory_config, factory_config) - # Force VM shutdown and snapshots collapse by default - task.set_option(:collapse_snapshots, true) - task.set_option(:power_off, true) - rescue Exception => e - @handle.set_state_var(:ae_state_progress, 'message' => e.message) - raise - end + # Force VM shutdown and snapshots collapse by default + task.set_option(:collapse_snapshots, true) + task.set_option(:power_off, true) + rescue => e + @handle.set_state_var(:ae_state_progress, 'message' => e.message) + raise end end end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweroff.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweroff.rb index e5070011a..1a5032c04 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweroff.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweroff.rb @@ -10,28 +10,26 @@ def initialize(handle = $evm) end def main - begin - task = @handle.root['service_template_transformation_plan_task'] - source_vm = task.source + task = @handle.root['service_template_transformation_plan_task'] + source_vm = task.source - if source_vm.power_state == 'off' - @handle.log(:info, "VM '#{source_vm.name}' is already off. Nothing to do.") - elsif task.get_option(:power_off) - @handle.log(:info, "VM '#{source_vm.name} is powered on. Let's shut it down.") - if @handle.state_var_exist?(:vm_shutdown_in_progress) - source_vm.stop if @handle.root['ae_state_retries'].to_i > 10 - else - source_vm.shutdown_guest - @handle.set_state_var(:vm_shutdown_in_progress, true) - end - @handle.root['ae_result'] = 'retry' + if source_vm.power_state == 'off' + @handle.log(:info, "VM '#{source_vm.name}' is already off. Nothing to do.") + elsif task.get_option(:power_off) + @handle.log(:info, "VM '#{source_vm.name} is powered on. Let's shut it down.") + if @handle.state_var_exist?(:vm_shutdown_in_progress) + source_vm.stop if @handle.root['ae_state_retries'].to_i > 10 else - raise "VM '#{source_vm.name} is powered on, but we are not allowed to shut it down. Aborting." + source_vm.shutdown_guest + @handle.set_state_var(:vm_shutdown_in_progress, true) end - rescue Exception => e - @handle.set_state_var(:ae_state_progress, 'message' => e.message) - raise + @handle.root['ae_result'] = 'retry' + else + raise "VM '#{source_vm.name} is powered on, but we are not allowed to shut it down. Aborting." end + rescue => e + @handle.set_state_var(:ae_state_progress, 'message' => e.message) + raise end end end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.rb index a2e05f95f..fbab12a95 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.rb @@ -10,14 +10,12 @@ def initialize(handle = $evm) end def main - begin - task = @handle.root['service_template_transformation_plan_task'] - destination_vm = @handle.vmdb(:vm).find_by(:id => task.get_option(:destination_vm_id)) - destination_vm.start - rescue Exception => e - @handle.set_state_var(:ae_state_progress, 'message' => e.message) - raise - end + task = @handle.root['service_template_transformation_plan_task'] + destination_vm = @handle.vmdb(:vm).find_by(:id => task.get_option(:destination_vm_id)) + destination_vm.start + rescue => e + @handle.set_state_var(:ae_state_progress, 'message' => e.message) + raise end end end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkpoweredon.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkpoweredon.rb index 5bd7bfcec..ca09358f1 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkpoweredon.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkpoweredon.rb @@ -10,20 +10,18 @@ def initialize(handle = $evm) end def main - begin - task = @handle.root['service_template_transformation_plan_task'] - destination_vm = @handle.vmdb(:vm).find_by(:id => task.get_option(:destination_vm_id)) - destination_ems = destination_vm.ext_management_system - destination_vm_sdk = ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::Utils.new(destination_ems).vm_find_by_name(destination_vm.name) - @handle.log(:info, "Status of VM '#{destination_vm.name}': #{destination_vm_sdk.status}") - unless destination_vm_sdk.status == OvirtSDK4::VmStatus::UP - @handle.root["ae_result"] = "retry" - @handle.root["ae_retry_interval"] = "15.seconds" - end - rescue Exception => e - @handle.set_state_var(:ae_state_progress, 'message' => e.message) - raise + task = @handle.root['service_template_transformation_plan_task'] + destination_vm = @handle.vmdb(:vm).find_by(:id => task.get_option(:destination_vm_id)) + destination_ems = destination_vm.ext_management_system + destination_vm_sdk = ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::Utils.new(destination_ems).vm_find_by_name(destination_vm.name) + @handle.log(:info, "Status of VM '#{destination_vm.name}': #{destination_vm_sdk.status}") + unless destination_vm_sdk.status == OvirtSDK4::VmStatus::UP + @handle.root["ae_result"] = "retry" + @handle.root["ae_retry_interval"] = "15.seconds" end + rescue => e + @handle.set_state_var(:ae_state_progress, 'message' => e.message) + raise end end end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkvmininventory.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkvmininventory.rb index 244171a93..5f4aff3bf 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkvmininventory.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/checkvmininventory.rb @@ -10,39 +10,37 @@ def initialize(handle = $evm) end def main - begin - task = @handle.root['service_template_transformation_plan_task'] - source_vm = task.source - destination_ems = task.transformation_destination(source_vm.ems_cluster).ext_management_system - destination_vm = ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::Utils.new(destination_ems).vm_find_by_name(source_vm.name) - raise "VM #{source_vm.name} not found in destination provider #{destination_ems.name}" if destination_vm.nil? + task = @handle.root['service_template_transformation_plan_task'] + source_vm = task.source + destination_ems = task.transformation_destination(source_vm.ems_cluster).ext_management_system + destination_vm = ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::Utils.new(destination_ems).vm_find_by_name(source_vm.name) + raise "VM #{source_vm.name} not found in destination provider #{destination_ems.name}" if destination_vm.nil? - finished = false + finished = false - destination_vm_vmdb = @handle.vmdb(:vm).where(["ems_ref = ?", destination_vm.href.gsub(/^\/ovirt-engine/, '')]).first - if destination_vm_vmdb.blank? - @handle.log(:info, "VM '#{source_vm.name}' not found in VMDB.") - if @handle.state_var_exist?(:ems_refresh_in_progress) - @handle.log(:info, "Refresh of '#{destination_ems.name}' is in progress. Nothing to do.") - else - @handle.log(:info, "Forcing refresh of provider '#{destination_ems.name}'") - destination_ems.refresh - @handle.set_state_var(:ems_refresh_in_progress, true) - end + destination_vm_vmdb = @handle.vmdb(:vm).where(["ems_ref = ?", destination_vm.href.gsub(/^\/ovirt-engine/, '')]).first + if destination_vm_vmdb.blank? + @handle.log(:info, "VM '#{source_vm.name}' not found in VMDB.") + if @handle.state_var_exist?(:ems_refresh_in_progress) + @handle.log(:info, "Refresh of '#{destination_ems.name}' is in progress. Nothing to do.") else - @handle.log(:info, "VM '#{source_vm.name}' found in VMDB with id '#{destination_vm_vmdb.id}'") - task.set_option(:destination_vm_id, destination_vm_vmdb.id) - finished = true + @handle.log(:info, "Forcing refresh of provider '#{destination_ems.name}'") + destination_ems.refresh + @handle.set_state_var(:ems_refresh_in_progress, true) end + else + @handle.log(:info, "VM '#{source_vm.name}' found in VMDB with id '#{destination_vm_vmdb.id}'") + task.set_option(:destination_vm_id, destination_vm_vmdb.id) + finished = true + end - unless finished - @handle.root['ae_result'] = 'retry' - @handle.root['ae_retry_interval'] = '15.seconds' - end - rescue Exception => e - @handle.set_state_var(:ae_state_progress, 'message' => e.message) - raise + unless finished + @handle.root['ae_result'] = 'retry' + @handle.root['ae_retry_interval'] = '15.seconds' end + rescue => e + @handle.set_state_var(:ae_state_progress, 'message' => e.message) + raise end end end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/setdescription.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/setdescription.rb index 8986bc593..e36a625e2 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/setdescription.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/rhevm.class/__methods__/setdescription.rb @@ -10,17 +10,15 @@ def initialize(handle = $evm) end def main - begin - task = @handle.root['service_template_transformation_plan_task'] - destination_vm = @handle.vmdb(:vm).find_by(:id => task.get_option(:destination_vm_id)) - destination_ems = destination_vm.ext_management_system + task = @handle.root['service_template_transformation_plan_task'] + destination_vm = @handle.vmdb(:vm).find_by(:id => task.get_option(:destination_vm_id)) + destination_ems = destination_vm.ext_management_system - description = "Migrated by Cloudforms on #{Time.now.utc}." - ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::Utils.new(destination_ems).vm_set_description(destination_vm, description) - rescue Exception => e - @handle.set_state_var(:ae_state_progress, 'message' => e.message) - raise - end + description = "Migrated by Cloudforms on #{Time.now.utc}." + ManageIQ::Automate::Transformation::Infrastructure::VM::RedHat::Utils.new(destination_ems).vm_set_description(destination_vm, description) + rescue => e + @handle.set_state_var(:ae_state_progress, 'message' => e.message) + raise end end end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/collapsesnapshots.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/collapsesnapshots.rb index 69a2702f6..8c0aac0ae 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/collapsesnapshots.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/collapsesnapshots.rb @@ -10,23 +10,21 @@ def initialize(handle = $evm) end def main - begin - task = @handle.root['service_template_transformation_plan_task'] - source_vm = task.source + task = @handle.root['service_template_transformation_plan_task'] + source_vm = task.source - if source_vm.snapshots.empty? - @handle.log(:info, "VM '#{source_vm.name}' has no snapshot. Nothing to do.") - elsif task.get_option(:collapse_snapshots) - @handle.log(:info, "VM '#{source_vm.name}' has snapshots and we need to collapse them.") - @handle.log(:info, "Collapsing snapshots for #{source_vm.name}") - source_vm.remove_all_snapshots - else - raise "VM '#{source_vm.name}' has snapshots, but we are not allowed to collapse them. Exiting." - end - rescue Exception => e - @handle.set_state_var(:ae_state_progress, 'message' => e.message) - raise + if source_vm.snapshots.empty? + @handle.log(:info, "VM '#{source_vm.name}' has no snapshot. Nothing to do.") + elsif task.get_option(:collapse_snapshots) + @handle.log(:info, "VM '#{source_vm.name}' has snapshots and we need to collapse them.") + @handle.log(:info, "Collapsing snapshots for #{source_vm.name}") + source_vm.remove_all_snapshots + else + raise "VM '#{source_vm.name}' has snapshots, but we are not allowed to collapse them. Exiting." end + rescue => e + @handle.set_state_var(:ae_state_progress, 'message' => e.message) + raise end end end diff --git a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/setmigrated.rb b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/setmigrated.rb index 5cf311036..f0a32294d 100644 --- a/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/setmigrated.rb +++ b/content/automate/ManageIQ/Transformation/Infrastructure/VM/vmwarews.class/__methods__/setmigrated.rb @@ -25,22 +25,20 @@ def check_name_collisions(new_name) end def main - begin - exit MIQ_OK - task = @handle.root['service_template_transformation_plan_task'] - source_vm = task.source - new_name = "#{source_vm.name}_migrated" + exit MIQ_OK + task = @handle.root['service_template_transformation_plan_task'] + source_vm = task.source + new_name = "#{source_vm.name}_migrated" - name_collisions = check_name_collisions(new_name) - raise "ERROR: #{new_name} already exists #{name_collisions}." if name_collisions.present? + name_collisions = check_name_collisions(new_name) + raise "ERROR: #{new_name} already exists #{name_collisions}." if name_collisions.present? - @handle.log(:info, "Renaming VM #{source_vm.name} to #{new_name}") - result = ManageIQ::Automate::Transformation::Infrastructure::VM::VMware::Utils.vm_rename(source_vm, new_name) - raise "VM rename for #{source_vm.name} to #{new_name} failed" unless result - rescue Exception => e - @handle.set_state_var(:ae_state_progress, 'message' => e.message) - raise - end + @handle.log(:info, "Renaming VM #{source_vm.name} to #{new_name}") + result = ManageIQ::Automate::Transformation::Infrastructure::VM::VMware::Utils.vm_rename(source_vm, new_name) + raise "VM rename for #{source_vm.name} to #{new_name} failed" unless result + rescue => e + @handle.set_state_var(:ae_state_progress, 'message' => e.message) + raise end end end diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb index 5e7a9f109..7a4d43640 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmchecktransformed_vmwarews2rhevm_vddk.rb @@ -3,75 +3,73 @@ module Automate module Transformation module TransformationHost module OVirtHost - class VMCheckTransformed_vmwarews2rhevm_vddk + class VMCheckTransformedVmwarews2rhevmVddk def initialize(handle = $evm) @debug = true @handle = handle end def main - begin - require 'json' + require 'json' - factory_config = @handle.get_state_var(:factory_config) - raise "No factory config found. Aborting." if factory_config.nil? + factory_config = @handle.get_state_var(:factory_config) + raise "No factory config found. Aborting." if factory_config.nil? - task = @handle.root['service_template_transformation_plan_task'] + task = @handle.root['service_template_transformation_plan_task'] - # Retrieve transformation host - transformation_host = @handle.vmdb(:host).find_by(:id => task.get_option(:transformation_host_id)) + # Retrieve transformation host + transformation_host = @handle.vmdb(:host).find_by(:id => task.get_option(:transformation_host_id)) - # Retrieve state of virt-v2v - result = Transformation::TransformationHosts::OVirtHost::Utils.remote_command(transformation_host, "cat '#{task.get_option(:virtv2v_wrapper)['state_file']}'") - raise result[:stderr] unless result[:success] && !result[:stdout].empty? - virtv2v_state = JSON.parse(result[:stdout]) - @handle.log(:info, "VirtV2V State: #{virtv2v_state.inspect}") + # Retrieve state of virt-v2v + result = Transformation::TransformationHosts::OVirtHost::Utils.remote_command(transformation_host, "cat '#{task.get_option(:virtv2v_wrapper)['state_file']}'") + raise result[:stderr] unless result[:success] && !result[:stdout].empty? + virtv2v_state = JSON.parse(result[:stdout]) + @handle.log(:info, "VirtV2V State: #{virtv2v_state.inspect}") - # Retrieve disks array - virtv2v_disks = task[:options][:virtv2v_disks] - @handle.log(:info, "Disks: #{virtv2v_disks.inspect}") + # Retrieve disks array + virtv2v_disks = task[:options][:virtv2v_disks] + @handle.log(:info, "Disks: #{virtv2v_disks.inspect}") - if virtv2v_state['finished'].nil? - # Update the progress of each disk - virtv2v_disks.each do |disk| - matching_disks = virtv2v_state['disks'].select { |d| d['path'] == disk[:path] } - raise "No disk matches '#{disk[:path]}'. Aborting." if matching_disks.length.zero? - raise "More than one disk matches '#{disk[:path]}'. Aborting." if matching_disks.length > 1 - disk[:percent] = matching_disks.first['progress'] - end - converted_disks = virtv2v_disks.reject { |d| d[:percent].zero? } - @handle.log(:info, "Converted disks: #{converted_disks.inspect}") - if converted_disks.empty? - @handle.set_state_var(:ae_state_progress, 'message' => "Disks transformation is initializing.", 'percent' => 1) - else - percent = 0 - converted_disks.each { |disk| percent += (disk[:percent].to_f * disk[:weight].to_f / 100.0) } - message = "Converting disk #{converted_disks.length} / #{virtv2v_disks.length} [#{percent.round(2)}%]." - @handle.set_state_var(:ae_state_progress, 'message' => message, 'percent' => percent.round(2)) - end + if virtv2v_state['finished'].nil? + # Update the progress of each disk + virtv2v_disks.each do |disk| + matching_disks = virtv2v_state['disks'].select { |d| d['path'] == disk[:path] } + raise "No disk matches '#{disk[:path]}'. Aborting." if matching_disks.length.zero? + raise "More than one disk matches '#{disk[:path]}'. Aborting." if matching_disks.length > 1 + disk[:percent] = matching_disks.first['progress'] + end + converted_disks = virtv2v_disks.reject { |d| d[:percent].zero? } + @handle.log(:info, "Converted disks: #{converted_disks.inspect}") + if converted_disks.empty? + @handle.set_state_var(:ae_state_progress, 'message' => "Disks transformation is initializing.", 'percent' => 1) + else + percent = 0 + converted_disks.each { |disk| percent += (disk[:percent].to_f * disk[:weight].to_f / 100.0) } + message = "Converting disk #{converted_disks.length} / #{virtv2v_disks.length} [#{percent.round(2)}%]." + @handle.set_state_var(:ae_state_progress, 'message' => message, 'percent' => percent.round(2)) + end + else + task.set_option(:virtv2v_finished_on, Time.now.utc.strftime('%Y%m%d_%H%M')) + if virtv2v_state['return_code'].zero? + virtv2v_disks.each { |d| d[:percent] = 100 } + @handle.set_state_var(:ae_state_progress, 'message' => 'Disks transformation succeeded.', 'percent' => 100) else - task.set_option(:virtv2v_finished_on, Time.now.utc.strftime('%Y%m%d_%H%M')) - if virtv2v_state['return_code'].zero? - virtv2v_disks.each { |d| d[:percent] = 100 } - @handle.set_state_var(:ae_state_progress, 'message' => 'Disks transformation succeeded.', 'percent' => 100) - else - @handle.set_state_var(:ae_state_progress, 'message' => 'Disks transformation succeeded.') - raise "Disks transformation failed." - end + @handle.set_state_var(:ae_state_progress, 'message' => 'Disks transformation succeeded.') + raise "Disks transformation failed." end + end - task.set_option(:virtv2v_disks, virtv2v_disks) + task.set_option(:virtv2v_disks, virtv2v_disks) - if task.get_option(:virtv2v_finished_on).nil? - @handle.root['ae_result'] = 'retry' - @handle.root['ae_retry_server_affinity'] = true - @handle.root['ae_retry_interval'] = factory_config['vmtransformation_check_interval'] || '15.seconds' - @handle.log(:info, "Disk transformation is not finished. Checking in #{@handle.root['ae_retry_interval']}") - end - rescue Exception => e - @handle.set_state_var(:ae_state_progress, 'message' => e.message) - raise + if task.get_option(:virtv2v_finished_on).nil? + @handle.root['ae_result'] = 'retry' + @handle.root['ae_retry_server_affinity'] = true + @handle.root['ae_retry_interval'] = factory_config['vmtransformation_check_interval'] || '15.seconds' + @handle.log(:info, "Disk transformation is not finished. Checking in #{@handle.root['ae_retry_interval']}") end + rescue => e + @handle.set_state_var(:ae_state_progress, 'message' => e.message) + raise end end end @@ -81,5 +79,5 @@ def main end if $PROGRAM_NAME == __FILE__ - ManageIQ::Automate::Transformation::TransformationHost::OVirtHost::VMCheckTransformed_vmwarews2rhevm_vddk.new.main + ManageIQ::Automate::Transformation::TransformationHost::OVirtHost::VMCheckTransformedVmwarews2rhevmVddk.new.main end diff --git a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb index 0cd892195..6e7e78f57 100644 --- a/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb +++ b/content/automate/ManageIQ/Transformation/TransformationHosts/ovirt_host.class/__methods__/vmtransform_vmwarews2rhevm_vddk.rb @@ -3,96 +3,93 @@ module Automate module Transformation module TransformationHost module OVirtHost - class VMTransform_vmwarews2rhevm_vddk + class VMTransformVmwarews2rhevmVddk def initialize(handle = $evm) @debug = false @handle = handle end def main - begin - require 'json' - - factory_config = @handle.get_state_var(:factory_config) - raise "No factory config found. Aborting." if factory_config.nil? - - task = @handle.root['service_template_transformation_plan_task'] - source_vm = task.source - source_cluster = source_vm.ems_cluster - source_ems = source_vm.ext_management_system - destination_cluster = task.transformation_destination(source_cluster) - destination_ems = destination_cluster.ext_management_system - destination_storage = task.transformation_destination(source_vm.hardware.disks.select { |d| d.device_type == 'disk' }.first.storage) - raise "Invalid destination EMS type: #{destination_ems.emstype}. Aborting." unless destination_ems.emstype == "rhevm" - - # Get or create the virt-v2v start timestamp - start_timestamp = task.get_option(:virtv2v_started_on) || Time.now.utc.strftime('%Y-%m-%d %H:%M:%S') - - # Retrieve transformation host - transformation_host = @handle.vmdb(:host).find_by(:id => task.get_option(:transformation_host_id)) - - @handle.log(:info, "Transformation - Started On: #{start_timestamp}") - - max_runners = destination_ems.custom_get('Max Transformation Runners') || factory_config['max_transformation_runners_by_ems'] || 1 - if Transformation::TransformationHosts::Common::Utils.get_runners_count_by_ems(destination_ems, @handle.get_state_var(:transformation_method), factory_config) >= max_runners - @handle.log("Too many transformations running: (#{max_runners}). Retrying.") - else - # Collect the VMware connection information - vmware_uri = "vpx://" - vmware_uri += "#{source_ems.authentication_userid.gsub('@', '%40')}@#{source_ems.hostname}/" - vmware_uri += "#{source_cluster.v_parent_datacenter.gsub(' ', '%20')}/#{source_cluster.name.gsub(' ', '%20')}/#{source_vm.host.uid_ems}" - vmware_uri += "?no_verify=1" - - # Collect information about the disks to convert - virtv2v_disks = task[:options][:virtv2v_disks] - source_disks = virtv2v_disks.map { |disk| disk[:path] } - @handle.log(:info, "Source VM Disks: #{source_disks}") - - # Collect information about the network mappings - virtv2v_networks = task[:options][:virtv2v_networks] - @handle.log(:info, "Network mappings: #{virtv2v_networks}") - - wrapper_options = { - :vm_name => source_vm.name, - :transport_method => 'vddk', - :vmware_fingerprint => Transformation::Infrastructure::VM::VMware::Utils.get_vcenter_fingerprint(source_ems), - :vmware_uri => vmware_uri, - :vmware_password => source_ems.authentication_password, - :rhv_url => "https://#{destination_ems.hostname}/ovirt-engine/api", - :rhv_cluster => destination_cluster.name, - :rhv_storage => destination_storage.name, - :rhv_password => destination_ems.authentication_password, - :source_disks => source_disks, - :network_mappings => virtv2v_networks, - :install_drivers => true - } - - # WARNING: Enable at your own risk, as it may lead to sensitive data leak - # @handle.log(:info, "JSON Input:\n#{JSON.pretty_generate(wrapper_options)}") if @debug - - @handle.log(:info, "Connecting to #{transformation_host.name} as #{transformation_host.authentication_userid}") if @debug - @handle.log(:info, "Executing '/usr/bin/virt-v2v-wrapper.py'") - result = Transformation::TransformationHosts::OVirtHost::Utils.remote_command(transformation_host, "/usr/bin/virt-v2v-wrapper.py", wrapper_options.to_json) - raise result[:stderr] unless result[:rc].zero? - - # Record the wrapper files path - @handle.log(:info, "Command stdout: #{result[:stdout]}") if @debug - task.set_option(:virtv2v_wrapper, JSON.parse(result[:stdout])) - - # Record the status in the task object - task.set_option(:virtv2v_started_on, start_timestamp) - task.set_option(:virtv2v_status, 'active') - end - - if task.get_option(:virtv2v_started_on).nil? - @handle.root['ae_result'] = 'retry' - @handle.root['ae_retry_server_affinity'] = true - @handle.root['ae_retry_interval'] = $evm.object['check_convert_interval'] || '1.minutes' - end - rescue Exception => e - @handle.set_state_var(:ae_state_progress, 'message' => e.message) - raise + require 'json' + + factory_config = @handle.get_state_var(:factory_config) + raise "No factory config found. Aborting." if factory_config.nil? + + task = @handle.root['service_template_transformation_plan_task'] + source_vm = task.source + source_cluster = source_vm.ems_cluster + source_ems = source_vm.ext_management_system + destination_cluster = task.transformation_destination(source_cluster) + destination_ems = destination_cluster.ext_management_system + destination_storage = task.transformation_destination(source_vm.hardware.disks.select { |d| d.device_type == 'disk' }.first.storage) + raise "Invalid destination EMS type: #{destination_ems.emstype}. Aborting." unless destination_ems.emstype == "rhevm" + + # Get or create the virt-v2v start timestamp + start_timestamp = task.get_option(:virtv2v_started_on) || Time.now.utc.strftime('%Y-%m-%d %H:%M:%S') + + # Retrieve transformation host + transformation_host = @handle.vmdb(:host).find_by(:id => task.get_option(:transformation_host_id)) + + @handle.log(:info, "Transformation - Started On: #{start_timestamp}") + + max_runners = destination_ems.custom_get('Max Transformation Runners') || factory_config['max_transformation_runners_by_ems'] || 1 + if Transformation::TransformationHosts::Common::Utils.get_runners_count_by_ems(destination_ems, @handle.get_state_var(:transformation_method), factory_config) >= max_runners + @handle.log("Too many transformations running: (#{max_runners}). Retrying.") + else + # Collect the VMware connection information + vmware_uri = "vpx://" + vmware_uri += "#{source_ems.authentication_userid.gsub('@', '%40')}@#{source_ems.hostname}/" + vmware_uri += "#{source_cluster.v_parent_datacenter.gsub(' ', '%20')}/#{source_cluster.name.gsub(' ', '%20')}/#{source_vm.host.uid_ems}" + vmware_uri += "?no_verify=1" + + # Collect information about the disks to convert + virtv2v_disks = task[:options][:virtv2v_disks] + source_disks = virtv2v_disks.map { |disk| disk[:path] } + @handle.log(:info, "Source VM Disks: #{source_disks}") + + # Collect information about the network mappings + virtv2v_networks = task[:options][:virtv2v_networks] + + wrapper_options = { + :vm_name => source_vm.name, + :transport_method => 'vddk', + :vmware_fingerprint => Transformation::Infrastructure::VM::VMware::Utils.get_vcenter_fingerprint(source_ems), + :vmware_uri => vmware_uri, + :vmware_password => source_ems.authentication_password, + :rhv_url => "https://#{destination_ems.hostname}/ovirt-engine/api", + :rhv_cluster => destination_cluster.name, + :rhv_storage => destination_storage.name, + :rhv_password => destination_ems.authentication_password, + :source_disks => source_disks, + :network_mappings => virtv2v_networks, + :install_drivers => true + } + + # WARNING: Enable at your own risk, as it may lead to sensitive data leak + # @handle.log(:info, "JSON Input:\n#{JSON.pretty_generate(wrapper_options)}") if @debug + + @handle.log(:info, "Connecting to #{transformation_host.name} as #{transformation_host.authentication_userid}") if @debug + @handle.log(:info, "Executing '/usr/bin/virt-v2v-wrapper.py'") + result = Transformation::TransformationHosts::OVirtHost::Utils.remote_command(transformation_host, "/usr/bin/virt-v2v-wrapper.py", wrapper_options.to_json) + raise result[:stderr] unless result[:rc].zero? + + # Record the wrapper files path + @handle.log(:info, "Command stdout: #{result[:stdout]}") if @debug + task.set_option(:virtv2v_wrapper, JSON.parse(result[:stdout])) + + # Record the status in the task object + task.set_option(:virtv2v_started_on, start_timestamp) + task.set_option(:virtv2v_status, 'active') end + + if task.get_option(:virtv2v_started_on).nil? + @handle.root['ae_result'] = 'retry' + @handle.root['ae_retry_server_affinity'] = true + @handle.root['ae_retry_interval'] = $evm.object['check_convert_interval'] || '1.minutes' + end + rescue => e + @handle.set_state_var(:ae_state_progress, 'message' => e.message) + raise end end end @@ -102,5 +99,5 @@ def main end if $PROGRAM_NAME == __FILE__ - ManageIQ::Automate::Transformation::TransformationHost::OVirtHost::VMTransform_vmwarews2rhevm_vddk.new.main + ManageIQ::Automate::Transformation::TransformationHost::OVirtHost::VMTransformVmwarews2rhevmVddk.new.main end