Skip to content

Commit

Permalink
v2v: Wait for VM to appear before finalizing it
Browse files Browse the repository at this point in the history
Added VmImportWaitForVm state machine that is created when
IMPORTEXPORT_IMPORT_VM event arrives. VmImportWaitForVm state machine
waits for the converted VM to appear in the database and then sets its
import status. After that VmImport state machine can continue its
operation.
  • Loading branch information
smelamud committed Jul 24, 2017
1 parent 3daa025 commit 61bb9c5
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
object_type: class
version: 1.0
object:
attributes:
description:
display_name:
name: VmImportWaitForVm
type:
inherits:
visibility:
owner:
schema:
- field:
aetype: state
name: start
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: state
name: Launch
display_name:
datatype: string
priority: 2
owner:
default_value: METHOD::wait_for_imported_vm
substitute: false
message: create
visibility:
collect:
scope:
description:
condition:
on_entry:
on_exit:
on_error:
max_retries: '100'
max_time:
- field:
aetype: state
name: finish
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:
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
#
# Description: This method checks if the VM has been successfully imported
#

module ManageIQ
module Automate
module System
module Event
module EmsEvent
module RHEVM
class UpdateVmImportStatus
module Infrastructure
module VM
module Transform
module StateMachines
class WaitForImportedVm
def initialize(handle = $evm)
@handle = handle
end

def main
update_import_status(vm)
@handle.vmdb(:vm).find_by(:ems_ref => ems_ref).tap do |vm|
if vm
update_import_status(vm)
else
set_retry
end
end
end

private

def vm_id
def ems_ref
event_stream = @handle.root['event_stream']
if event_stream.nil?
@handle.log(:error, 'event_stream not found')
raise 'event_stream not found'
end
event_stream.vm_or_template_id
"/api/vms/#{event_stream.full_data[:vm][:id]}"
end

def vm
@handle.vmdb('Vm', vm_id).tap do |vm|
if vm.nil?
@handle.log(:error, 'VM object not found')
raise 'VM object not found'
end
end
def set_retry
@handle.root['ae_result'] = 'retry'
@handle.root['ae_retry_interval'] = @handle.inputs['retry_interval'] || 1.minute
end

def import_status
Expand All @@ -50,5 +56,5 @@ def update_import_status(vm)
end

if __FILE__ == $PROGRAM_NAME
ManageIQ::Automate::System::Event::EmsEvent::RHEVM::UpdateVmImportStatus.new.main
ManageIQ::Automate::Infrastructure::VM::Transform::StateMachines::WaitForImportedVm.new.main
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ object_type: method
version: 1.0
object:
attributes:
name: update_vm_import_status
name: wait_for_imported_vm
display_name:
description:
scope: instance
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
object_type: instance
version: 1.0
object:
attributes:
display_name:
name: default
inherits:
description:
fields: []
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ object:
fields:
- rel4:
value: "/System/event_handlers/event_action_refresh?target=src_vm"
- meth4:
value: update_vm_import_status
- rel5:
value: "/Infrastructure/VM/Transform/StateMachines/VmImportWaitForVm/default?target=src_vm"
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ object:
inherits:
description:
fields:
- meth4:
value: update_vm_import_status
- rel4:
value: "/Infrastructure/VM/Transform/StateMachines/VmImportWaitForVm/default?target=src_vm"

0 comments on commit 61bb9c5

Please sign in to comment.