-
Notifications
You must be signed in to change notification settings - Fork 120
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 #441 from fdupont-redhat/v2v_move_code_to_backend_1
Refactor to delegate task and conversion host code to backend (cherry picked from commit 8e7ed4d) https://bugzilla.redhat.com/show_bug.cgi?id=1634029
- Loading branch information
Showing
58 changed files
with
1,032 additions
and
1,717 deletions.
There are no files selected for viewing
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
39 changes: 39 additions & 0 deletions
39
content/automate/ManageIQ/Transformation/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 Common | ||
class KillVirtV2V | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
@task = ManageIQ::Automate::Transformation::Common::Utils.task(@handle) | ||
end | ||
|
||
def task_virtv2v_state | ||
return if @task.get_option(:virtv2v_started_on).blank? || @task.get_option(:virtv2v_finished_on).present? || @task.get_option(:virtv2v_wrapper).blank? | ||
@task.get_conversion_state | ||
end | ||
|
||
def kill_signal | ||
if @handle.get_state_var('virtv2v_graceful_kill') | ||
'KILL' | ||
else | ||
@handle.set_state_var('virtv2v_graceful_kill', true) | ||
@handle.root['ae_result'] = 'retry' | ||
@handle.root['ae_retry_interval'] = '30.seconds' | ||
'TERM' | ||
end | ||
end | ||
|
||
def main | ||
@task.kill_virtv2v(kill_signal) unless task_virtv2v_state.nil? | ||
rescue => e | ||
@handle.set_state_var(:ae_state_progress, 'message' => e.message) | ||
raise | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
ManageIQ::Automate::Transformation::Common::KillVirtV2V.new.main |
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
23 changes: 23 additions & 0 deletions
23
content/automate/ManageIQ/Transformation/Common.class/__methods__/setmigrated.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,23 @@ | ||
module ManageIQ | ||
module Automate | ||
module Transformation | ||
module Common | ||
class SetMigrated | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
@task = ManageIQ::Automate::Transformation::Common::Utils.task(@handle) | ||
end | ||
|
||
def main | ||
@task.mark_vm_migrated | ||
rescue => e | ||
@handle.set_state_var(:ae_state_progress, 'message' => e.message) | ||
raise | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
ManageIQ::Automate::Transformation::Common::SetMigrated.new.main |
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
56 changes: 56 additions & 0 deletions
56
content/automate/ManageIQ/Transformation/Common.class/__methods__/vmchecktransformed.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,56 @@ | ||
module ManageIQ | ||
module Automate | ||
module Transformation | ||
module Common | ||
class VMCheckTransformed | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
@task = ManageIQ::Automate::Transformation::Common::Utils.task(@handle) | ||
end | ||
|
||
def set_retry | ||
@handle.root['ae_result'] = 'retry' | ||
@handle.root['ae_retry_server_affinity'] = true | ||
@handle.log(:info, "Disk transformation is not finished. Checking in #{@handle.root['ae_retry_interval']}") | ||
end | ||
|
||
def update_total_percentage | ||
virtv2v_disks = @task[:options][:virtv2v_disks] | ||
converted_disks = virtv2v_disks.reject { |d| d[:percent].zero? } | ||
message, percent = nil, nil | ||
if converted_disks.empty? | ||
percent = 1 | ||
message = 'Disks transformation is initializing.' | ||
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)}%]." | ||
end | ||
[message, percent] | ||
end | ||
|
||
def main | ||
@task.get_conversion_state | ||
|
||
case @task.get_option(:virtv2v_status) | ||
when 'active' | ||
message, percent = update_total_percentage | ||
@handle.set_state_var(:ae_state_progress, 'message' => message, 'percent' => percent.round(2)) | ||
set_retry | ||
when 'failed' | ||
@handle.set_state_var(:ae_state_progress, 'message' => 'Disks transformation failed.') | ||
raise "Disks transformation failed." | ||
when 'succeeded' | ||
@handle.set_state_var(:ae_state_progress, 'message' => 'Disks transformation succeeded.', 'percent' => 100) | ||
end | ||
rescue => e | ||
@handle.set_state_var(:ae_state_progress, 'message' => e.message) | ||
raise | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
ManageIQ::Automate::Transformation::Common::VMCheckTransformed.new.main |
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
27 changes: 27 additions & 0 deletions
27
content/automate/ManageIQ/Transformation/Common.class/__methods__/vmtransform.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,27 @@ | ||
module ManageIQ | ||
module Automate | ||
module Transformation | ||
module Common | ||
class VMTransform | ||
def initialize(handle = $evm) | ||
@debug = false | ||
@handle = handle | ||
@task = ManageIQ::Automate::Transformation::Common::Utils.task(@handle) | ||
end | ||
|
||
def main | ||
# WARNING: Enable at your own risk, as it may lead to sensitive data leak | ||
# @handle.log(:info, "JSON Input:\n#{JSON.pretty_generate(@task.conversion_options)}") if @debug | ||
|
||
@task.run_conversion | ||
rescue => e | ||
@handle.set_state_var(:ae_state_progress, 'message' => e.message) | ||
raise | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
ManageIQ::Automate::Transformation::Common::VMTransform.new.main |
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
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
Oops, something went wrong.