Skip to content

Commit

Permalink
Merge pull request #378 from fdupont-redhat/v2v_cleanup_add_default_s…
Browse files Browse the repository at this point in the history
…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
gmcculloug authored and simaishi committed Aug 1, 2018
1 parent 3a98ce6 commit a1db904
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 24 deletions.
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
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: []
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ def initialize(handle = $evm)
end

def main
task = @handle.root['service_template_transformation_plan_task']
if task.get_option(:source_vm_power_state) == 'on'
destination_vm = @handle.vmdb(:vm).find_by(:id => task.get_option(:destination_vm_id))
destination_vm.start
if @handle.root['service_template_transformation_plan_task'].blank?
task = @handle.vmdb(:service_template_transformation_plan_task).find_by(:id => @handle.root['service_template_transformation_plan_task_id'])
vm = task.source if task.present?
else
task = @handle.root['service_template_transformation_plan_task']
vm = @handle.vmdb(:vm).find_by(:id => task.get_option(:destination_vm_id)) if task.present?
end
return if vm.blank?
vm.start if task.get_option(:source_vm_power_state) == 'on'
rescue => e
@handle.set_state_var(:ae_state_progress, 'message' => e.message)
raise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def initialize(handle = $evm)

def main
task = @handle.root['service_template_transformation_plan_task']
task ||= @handle.vmdb(:service_template_transformation_plan_task).find_by(:id => @handle.root['service_template_transformation_plan_task_id'])
if task.get_option(:source_vm_power_state) == 'on'
destination_vm = @handle.vmdb(:vm).find_by(:id => task.get_option(:destination_vm_id))
unless destination_vm.power_state == 'on'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,32 @@ object:
visibility:
owner:
schema:
- field:
aetype: attribute
name: cleanup_state_machine
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:
- field:
aetype: state
name: State1
display_name:
datatype:
priority: 1
priority: 2
owner:
default_value:
substitute: true
Expand All @@ -36,7 +56,7 @@ object:
name: State2
display_name:
datatype:
priority: 2
priority: 3
owner:
default_value:
substitute: true
Expand All @@ -56,7 +76,7 @@ object:
name: State3
display_name:
datatype:
priority: 3
priority: 4
owner:
default_value:
substitute: true
Expand All @@ -76,7 +96,7 @@ object:
name: State4
display_name:
datatype:
priority: 4
priority: 5
owner:
default_value:
substitute: true
Expand All @@ -96,7 +116,7 @@ object:
name: State5
display_name:
datatype:
priority: 5
priority: 6
owner:
default_value:
substitute: true
Expand All @@ -116,7 +136,7 @@ object:
name: State6
display_name:
datatype:
priority: 6
priority: 7
owner:
default_value:
substitute: true
Expand All @@ -136,7 +156,7 @@ object:
name: State7
display_name:
datatype:
priority: 7
priority: 8
owner:
default_value:
substitute: true
Expand All @@ -156,7 +176,7 @@ object:
name: State8
display_name:
datatype:
priority: 8
priority: 9
owner:
default_value:
substitute: true
Expand All @@ -176,7 +196,7 @@ object:
name: State9
display_name:
datatype:
priority: 9
priority: 10
owner:
default_value:
substitute: true
Expand All @@ -196,7 +216,7 @@ object:
name: State10
display_name:
datatype:
priority: 10
priority: 11
owner:
default_value:
substitute: true
Expand All @@ -216,7 +236,7 @@ object:
name: State11
display_name:
datatype:
priority: 11
priority: 12
owner:
default_value:
substitute: true
Expand All @@ -236,7 +256,7 @@ object:
name: State12
display_name:
datatype:
priority: 12
priority: 13
owner:
default_value:
substitute: true
Expand All @@ -256,7 +276,7 @@ object:
name: State13
display_name:
datatype:
priority: 13
priority: 14
owner:
default_value:
substitute: true
Expand All @@ -276,7 +296,7 @@ object:
name: State14
display_name:
datatype:
priority: 14
priority: 15
owner:
default_value:
substitute: true
Expand All @@ -296,7 +316,7 @@ object:
name: State15
display_name:
datatype:
priority: 15
priority: 16
owner:
default_value:
substitute: true
Expand All @@ -316,7 +336,7 @@ object:
name: State16
display_name:
datatype:
priority: 16
priority: 17
owner:
default_value:
substitute: true
Expand All @@ -336,7 +356,7 @@ object:
name: State17
display_name:
datatype:
priority: 17
priority: 18
owner:
default_value:
substitute: true
Expand All @@ -356,7 +376,7 @@ object:
name: State18
display_name:
datatype:
priority: 18
priority: 19
owner:
default_value:
substitute: true
Expand All @@ -376,7 +396,7 @@ object:
name: State19
display_name:
datatype:
priority: 19
priority: 20
owner:
default_value:
substitute: true
Expand All @@ -396,7 +416,7 @@ object:
name: State20
display_name:
datatype:
priority: 20
priority: 21
owner:
default_value:
substitute: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ object:
inherits:
description:
fields:
- cleanup_state_machine:
value: "/Transformation/StateMachines/VMTransformation/TransformationCleanup"
- State2:
value: "/Transformation/Common/AssessTransformation"
on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 1, description
Expand Down
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'
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
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: []

0 comments on commit a1db904

Please sign in to comment.