-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #378 from fdupont-redhat/v2v_cleanup_add_default_s…
…tate_machine Add default cleanup state machine for VM transformation (cherry picked from commit fe3fe98) https://bugzilla.redhat.com/show_bug.cgi?id=1608758
- Loading branch information
1 parent
3a98ce6
commit a1db904
Showing
9 changed files
with
195 additions
and
24 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
.../automate/ManageIQ/Transformation/Common.class/__methods__/assesstransformationcleanup.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module ManageIQ | ||
module Automate | ||
module Transformation | ||
module Common | ||
class AssessTransformationCleanup | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
@debug = false | ||
end | ||
|
||
def main | ||
task = @handle.vmdb(:service_template_transformation_plan_task).find_by(:id => @handle.root['service_template_transformation_plan_task_id']) | ||
raise 'No task found. Exiting' if task.nil? | ||
@handle.log(:info, "Task: #{task.inspect}") if @debug | ||
|
||
destination_ems_id = task.get_option(:destination_ems_id) | ||
raise "'destination_ems_id' is not available" if destination_ems_id.blank? | ||
destination_ems = @handle.vmdb(:ext_management_system).find_by(:id => destination_ems_id) | ||
raise "Destination EMS with id '#{destination_ems_id}' doesn't exist." if destination_ems.blank? | ||
@handle.set_state_var(:destination_ems_type, destination_ems.emstype) | ||
rescue => e | ||
@handle.set_state_var(:ae_state_progress, 'message' => e.message) | ||
raise | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
if $PROGRAM_NAME == __FILE__ | ||
ManageIQ::Automate::Transformation::Common::AssessTransformationCleanup.new.main | ||
end |
13 changes: 13 additions & 0 deletions
13
...utomate/ManageIQ/Transformation/Common.class/__methods__/assesstransformationcleanup.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
object_type: method | ||
version: 1.0 | ||
object: | ||
attributes: | ||
name: AssessTransformationCleanup | ||
display_name: | ||
description: | ||
scope: instance | ||
language: ruby | ||
location: inline | ||
options: {} | ||
inputs: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...e/ManageIQ/Transformation/StateMachines/VMTransformation.class/transformationcleanup.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
object_type: instance | ||
version: 1.0 | ||
object: | ||
attributes: | ||
display_name: | ||
name: TransformationCleanup | ||
inherits: | ||
description: | ||
fields: | ||
- State2: | ||
value: "/Transformation/Common/AssessTransformationCleanup" | ||
on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 10, description | ||
=> "Assess Migration Cleanup", task_message => "Cleanup") | ||
on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 10, description | ||
=> "Assess Migration Cleanup", task_message => "Cleanup") | ||
on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 10, description | ||
=> "Assess Migration Cleanup", task_message => "Cleanup") | ||
- State5: | ||
value: "/Transformation/TransformationHosts/Common/KillVirtV2V" | ||
on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 40, description | ||
=> "Interrupt virt-v2v", task_message => "Cleanup") | ||
on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 40, description | ||
=> "Interrupt virt-v2v", task_message => "Cleanup") | ||
on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 40, description | ||
=> "Interrupt virt-v2v", task_message => "Cleanup") | ||
- State8: | ||
value: "/Transformation/Infrastructure/VM/Common/PowerOn" | ||
on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 10, description | ||
=> "Power-on VM", task_message => "Cleanup") | ||
on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 10, description | ||
=> "Power-on VM", task_message => "Cleanup") | ||
on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 10, description | ||
=> "Power-on VM", task_message => "Cleanup") | ||
- State11: | ||
value: "/Transformation/Infrastructure/VM/${state_var#destination_ems_type}/CheckPoweredOn" | ||
on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 40, description | ||
=> "Power-on VM", task_message => "Cleanup") | ||
on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 40, description | ||
=> "Power-on VM", task_message => "Cleanup") | ||
on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 40, description | ||
=> "Power-on VM", task_message => "Cleanup") | ||
max_retries: '200' |
39 changes: 39 additions & 0 deletions
39
...omate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/killvirtv2v.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module ManageIQ | ||
module Automate | ||
module Transformation | ||
module TransformationHost | ||
module Common | ||
class KillVirtV2V | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
def task_virtv2v_state(task, transformation_host) | ||
require 'json' | ||
return if task.get_option(:virtv2v_started_on).blank? || task.get_option(:virtv2v_finished_on).present? | ||
return if task.get_option(:virtv2v_wrapper).blank? | ||
result = Transformation::TransformationHosts::Common::Utils.remote_command(task, transformation_host, "cat '#{task.get_option(:virtv2v_wrapper)['state_file']}'") | ||
return if !result[:success] || result[:stdout].empty? | ||
JSON.parse(result[:stdout]) | ||
end | ||
|
||
def main | ||
task = @handle.vmdb(:service_template_transformation_plan_task).find_by(:id => @handle.root['service_template_transformation_plan_task_id']) | ||
transformation_host = @handle.vmdb(:host).find_by(:id => task.get_option(:transformation_host_id)) | ||
virtv2v_state = task_virtv2v_state(task, transformation_host) | ||
@handle.log(:info, "VirtV2V State: #{virtv2v_state.inspect}") | ||
Transformation::TransformationHosts::Common::Utils.remote_command(task, transformation_host, "kill -9 #{virtv2v_state['pid']}") if virtv2v_state.present? | ||
rescue => 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::TransformationHost::Common::KillVirtV2V.new.main | ||
end |
16 changes: 16 additions & 0 deletions
16
...ate/ManageIQ/Transformation/TransformationHosts/Common.class/__methods__/killvirtv2v.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
object_type: method | ||
version: 1.0 | ||
object: | ||
attributes: | ||
name: KillVirtV2V | ||
display_name: | ||
description: | ||
scope: instance | ||
language: ruby | ||
location: inline | ||
embedded_methods: | ||
- "/Transformation/TransformationHosts/Common/Utils" | ||
- "/Transformation/TransformationHosts/ovirt_host/Utils" | ||
options: {} | ||
inputs: [] |