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 #355 from fdupont-redhat/v2v_pre_post_migration_pl…
…aybook_support Add support for pre/post-migration playbook (cherry picked from commit f5fdc82) https://bugzilla.redhat.com/show_bug.cgi?id=1608420
- Loading branch information
1 parent
b364c7f
commit fb6f12c
Showing
11 changed files
with
387 additions
and
9 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
content/automate/ManageIQ/Transformation/Ansible.class/__class__.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,33 @@ | ||
--- | ||
object_type: class | ||
version: 1.0 | ||
object: | ||
attributes: | ||
description: | ||
display_name: | ||
name: Ansible | ||
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: |
51 changes: 51 additions & 0 deletions
51
...ent/automate/ManageIQ/Transformation/Ansible.class/__methods__/checkplaybookasaservice.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,51 @@ | ||
module ManageIQ | ||
module Automate | ||
module Transformation | ||
module Ansible | ||
class CheckPlaybookAsAService | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
def set_retry(message, interval = '1.minutes') | ||
end | ||
|
||
def main | ||
transformation_hook = @handle.inputs['transformation_hook'] | ||
task = @handle.root['service_template_transformation_plan_task'] | ||
service_request_id = task.get_option("#{transformation_hook}_ansible_playbook_service_request_id".to_sym) | ||
|
||
if service_request_id.present? | ||
service_request = @handle.vmdb(:miq_request).find_by(:id => service_request_id) | ||
|
||
playbooks_status = task.get_option(:playbooks) || {} | ||
playbooks_status[transformation_hook] = { :job_state => service_request.request_state } | ||
|
||
if service_request.request_state == 'finished' | ||
@handle.log(:info, "Ansible playbook service request (id: #{service_request_id}) is finished.") | ||
playbooks_status[transformation_hook][:job_status] = service_request.status | ||
playbooks_status[transformation_hook][:job_id] = service_request.miq_request_tasks.first.destination.service_resources.first.resource.id | ||
task.set_option(:playbooks, playbooks_status) | ||
if service_request.status == 'Error' && transformation_hook == 'pre' | ||
raise "Ansible playbook has failed (hook=#{transformation_hook})" | ||
end | ||
else | ||
@handle.log(:info, "Playbook for #{transformation_hook} migration is not finished. Retrying.") | ||
@handle.root['ae_result'] = 'retry' | ||
@handle.root['ae_retry_interval'] = '15.seconds' | ||
end | ||
task.set_option(:playbooks, playbooks_status) | ||
end | ||
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::Ansible::CheckPlaybookAsAService.new.main | ||
end |
33 changes: 33 additions & 0 deletions
33
...t/automate/ManageIQ/Transformation/Ansible.class/__methods__/checkplaybookasaservice.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,33 @@ | ||
--- | ||
object_type: method | ||
version: 1.0 | ||
object: | ||
attributes: | ||
name: CheckPlaybookAsAService | ||
display_name: | ||
description: | ||
scope: instance | ||
language: ruby | ||
location: inline | ||
options: {} | ||
inputs: | ||
- field: | ||
aetype: | ||
name: transformation_hook | ||
display_name: | ||
datatype: | ||
priority: 1 | ||
owner: | ||
default_value: _ | ||
substitute: false | ||
message: create | ||
visibility: | ||
collect: | ||
scope: | ||
description: | ||
condition: | ||
on_entry: | ||
on_exit: | ||
on_error: | ||
max_retries: | ||
max_time: |
45 changes: 45 additions & 0 deletions
45
...nt/automate/ManageIQ/Transformation/Ansible.class/__methods__/launchplaybookasaservice.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,45 @@ | ||
module ManageIQ | ||
module Automate | ||
module Transformation | ||
module Ansible | ||
class LaunchPlaybookAsAService | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
def target_host(task, transformation_hook) | ||
target_host = nil | ||
case transformation_hook | ||
when 'pre' | ||
target_host = task.source | ||
when 'post' | ||
target_host = @handle.vmdb(:vm).find_by(:id => task.get_option(:destination_vm_id)) | ||
end | ||
target_host | ||
end | ||
|
||
def main | ||
task = @handle.root['service_template_transformation_plan_task'] | ||
transformation_hook = @handle.inputs['transformation_hook'] | ||
|
||
return if transformation_hook == '_' | ||
service_template = task.send("#{transformation_hook}_ansible_playbook_service_template") | ||
return if service_template.nil? | ||
target_host = target_host(task, transformation_hook) | ||
return if target_host.nil? || target_host.power_state != 'on' | ||
service_dialog_options = { :hosts => target_host.ipaddresses.first } | ||
service_request = @handle.execute(:create_service_provision_request, service_template, service_dialog_options) | ||
task.set_option("#{transformation_hook}_ansible_playbook_service_request_id".to_sym, service_request.id) | ||
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::Ansible::LaunchPlaybookAsAService.new.main | ||
end |
33 changes: 33 additions & 0 deletions
33
.../automate/ManageIQ/Transformation/Ansible.class/__methods__/launchplaybookasaservice.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,33 @@ | ||
--- | ||
object_type: method | ||
version: 1.0 | ||
object: | ||
attributes: | ||
name: LaunchPlaybookAsAService | ||
display_name: | ||
description: | ||
scope: instance | ||
language: ruby | ||
location: inline | ||
options: {} | ||
inputs: | ||
- field: | ||
aetype: | ||
name: transformation_hook | ||
display_name: | ||
datatype: | ||
priority: 1 | ||
owner: | ||
default_value: _ | ||
substitute: false | ||
message: create | ||
visibility: | ||
collect: | ||
scope: | ||
description: | ||
condition: | ||
on_entry: | ||
on_exit: | ||
on_error: | ||
max_retries: | ||
max_time: |
12 changes: 12 additions & 0 deletions
12
content/automate/ManageIQ/Transformation/Ansible.class/_missing.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,12 @@ | ||
--- | ||
object_type: instance | ||
version: 1.0 | ||
object: | ||
attributes: | ||
display_name: | ||
name: ".missing" | ||
inherits: | ||
description: | ||
fields: | ||
- execute: | ||
value: "${#_missing_instance}" |
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
133 changes: 133 additions & 0 deletions
133
content/automate/ManageIQ/Transformation/StateMachines/Ansible.class/__class__.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,133 @@ | ||
--- | ||
object_type: class | ||
version: 1.0 | ||
object: | ||
attributes: | ||
description: | ||
display_name: | ||
name: Ansible | ||
type: | ||
inherits: | ||
visibility: | ||
owner: | ||
schema: | ||
- field: | ||
aetype: state | ||
name: State1 | ||
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: State2 | ||
display_name: | ||
datatype: | ||
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: state | ||
name: State3 | ||
display_name: | ||
datatype: | ||
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: state | ||
name: State4 | ||
display_name: | ||
datatype: | ||
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: state | ||
name: State5 | ||
display_name: | ||
datatype: | ||
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: state | ||
name: State6 | ||
display_name: | ||
datatype: | ||
priority: 6 | ||
owner: | ||
default_value: | ||
substitute: true | ||
message: create | ||
visibility: | ||
collect: | ||
scope: | ||
description: | ||
condition: | ||
on_entry: | ||
on_exit: | ||
on_error: | ||
max_retries: | ||
max_time: |
27 changes: 27 additions & 0 deletions
27
.../automate/ManageIQ/Transformation/StateMachines/Ansible.class/transformationplaybook.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,27 @@ | ||
--- | ||
object_type: instance | ||
version: 1.0 | ||
object: | ||
attributes: | ||
display_name: | ||
name: TransformationPlaybook | ||
inherits: | ||
description: | ||
fields: | ||
- State2: | ||
value: "/Transformation/Ansible/LaunchPlaybookAsAService" | ||
on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 20, description | ||
=> "Launch ${#transformation_hook} migration playbook", task_message => "Migrating") | ||
on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 20, description | ||
=> "Launch ${#transformation_hook} migration playbook", task_message => "Migrating") | ||
on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 20, description | ||
=> "Launch ${#transformation_hook} migration playbook", task_message => "Migrating") | ||
- State5: | ||
value: "/Transformation/Ansible/CheckPlaybookAsAService" | ||
on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 80, description | ||
=> "Check ${#transformation_hook} migration playbook", task_message => "Migrating") | ||
on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 80, description | ||
=> "Check ${#transformation_hook} migration playbook", task_message => "Migrating") | ||
on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 80, description | ||
=> "Check ${#transformation_hook} migration playbook", task_message => "Migrating") | ||
max_retries: '1500' |
Oops, something went wrong.