diff --git a/content/automate/ManageIQ/System/Event/EmsEvent/EVM.class/reconfigvm_task_complete.yaml b/content/automate/ManageIQ/System/Event/EmsEvent/EVM.class/reconfigvm_task_complete.yaml index cf45edb65..374066b2c 100644 --- a/content/automate/ManageIQ/System/Event/EmsEvent/EVM.class/reconfigvm_task_complete.yaml +++ b/content/automate/ManageIQ/System/Event/EmsEvent/EVM.class/reconfigvm_task_complete.yaml @@ -9,6 +9,4 @@ object: description: fields: - rel4: - value: "/System/event_handlers/event_action_refresh_sync?target=src_vm" - - rel5: - value: "/System/event_handlers/event_action_policy?target=src_vm&policy_event=vm_reconfigure¶m=" + value: "/System/Event/StateMachines/Refresh/default?refresh_target=src_vm&policy_event=vm_reconfigure&policy_target=src_vm" diff --git a/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/__class__.yaml b/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/__class__.yaml new file mode 100644 index 000000000..c9dd0c027 --- /dev/null +++ b/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/__class__.yaml @@ -0,0 +1,133 @@ +--- +object_type: class +version: 1.0 +object: + attributes: + description: Refresh State Machine + display_name: + name: Refresh + type: + inherits: + visibility: + owner: + schema: + - field: + aetype: state + name: pre + 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: '100' + max_time: + - field: + aetype: state + name: refresh + display_name: + datatype: string + priority: 2 + owner: + default_value: + substitute: true + message: create + visibility: + collect: + scope: + description: + condition: + on_entry: + on_exit: + on_error: + max_retries: '100' + max_time: + - field: + aetype: state + name: check_refreshed + 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: '100' + max_time: + - field: + aetype: state + name: post + display_name: + datatype: string + priority: 4 + owner: + default_value: + substitute: true + message: create + visibility: + collect: + scope: + description: + condition: + on_entry: '' + on_exit: '' + on_error: '' + max_retries: '100' + max_time: + - field: + aetype: state + name: policy + display_name: + datatype: string + 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: finished + display_name: + datatype: string + priority: 6 + owner: + default_value: + substitute: true + message: create + visibility: + collect: + scope: + description: + condition: + on_entry: + on_exit: + on_error: + max_retries: + max_time: diff --git a/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/check_refreshed.rb b/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/check_refreshed.rb new file mode 100644 index 000000000..baf444a94 --- /dev/null +++ b/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/check_refreshed.rb @@ -0,0 +1,61 @@ +# +# Description: This method checks the refresh completion. +# + +module ManageIQ + module Automate + module System + module Event + module StateMachines + module Refresh + class CheckRefreshed + def initialize(handle = $evm) + @handle = handle + end + + def main + check_status(refresh_task) + end + + private + + def check_status(task) + case task.state + when 'Finished' + @handle.root['ae_result'] = 'ok' + else + @handle.root['ae_result'] = 'retry' + @handle.root['ae_retry_interval'] = 1.minute + end + end + + def refresh_task + task_id = @handle.get_state_var(:task_id).first + @handle.log(:info, "Stored task ID: [#{task_id}]") + if task_id.nil? + @handle.log(:error, 'Refresh task id not found') + exit(MIQ_ERROR) + end + fetch_task(task_id) + end + + def fetch_task(task_id) + $evm.object.attributes.sort.each { |k, v| $evm.log("info", "#{k}: #{v}") } + task = @handle.vmdb(:miq_task).find(task_id) + if task.nil? + @handle.log(:error, 'Refresh task with id : #{task_id} not found') + exit(MIQ_ERROR) + end + task + end + end + end + end + end + end + end +end + +if __FILE__ == $PROGRAM_NAME + ManageIQ::Automate::System::Event::StateMachines::Refresh::CheckRefreshed.new.main +end diff --git a/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/check_refreshed.yaml b/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/check_refreshed.yaml new file mode 100644 index 000000000..c3cd30231 --- /dev/null +++ b/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/check_refreshed.yaml @@ -0,0 +1,13 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: check_refreshed + display_name: + description: + scope: instance + language: ruby + location: inline + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/target_refresh.rb b/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/target_refresh.rb new file mode 100644 index 000000000..aba5c52f7 --- /dev/null +++ b/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/target_refresh.rb @@ -0,0 +1,50 @@ +# +# Description: This method starts a synchronous refresh and save the +# task id in the state variables so we can use it when +# waiting for the refresh to finish. +# + +module ManageIQ + module Automate + module System + module Event + module StateMachines + module Refresh + class TargetRefresh + def initialize(handle = $evm) + @handle = handle + end + + def main + task_id = event.refresh(refresh_target, true) + @handle.set_state_var(:task_id, task_id) + end + + private + + def event + @handle.root["event_stream"].tap do |event| + if event.nil? + @handle.log(:error, 'Event object is nil') + raise 'Event object not found' + end + end + end + + def refresh_target + target = @handle.object["refresh_target"] + @handle.log(:info, "Refresh target: [#{target}]") + raise "Refresh target not found" if target.nil? + target + end + end + end + end + end + end + end +end + +if __FILE__ == $PROGRAM_NAME + ManageIQ::Automate::System::Event::StateMachines::Refresh::TargetRefresh.new.main +end diff --git a/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/target_refresh.yaml b/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/target_refresh.yaml new file mode 100644 index 000000000..6abf840a9 --- /dev/null +++ b/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/__methods__/target_refresh.yaml @@ -0,0 +1,13 @@ +--- +object_type: method +version: 1.0 +object: + attributes: + name: target_refresh + display_name: + description: + scope: instance + language: ruby + location: inline + options: {} + inputs: [] diff --git a/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/default.yaml b/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/default.yaml new file mode 100644 index 000000000..99dcc5737 --- /dev/null +++ b/content/automate/ManageIQ/System/Event/StateMachines/Refresh.class/default.yaml @@ -0,0 +1,16 @@ +--- +object_type: instance +version: 1.0 +object: + attributes: + display_name: + name: default + inherits: + description: + fields: + - refresh: + value: METHOD::target_refresh + - check_refreshed: + value: METHOD::check_refreshed + - policy: + value: "/System/event_handlers/event_action_policy?target=${#policy_target}&policy_event=${#policy_event}¶m=" diff --git a/content/automate/ManageIQ/System/Event/StateMachines/__namespace__.yaml b/content/automate/ManageIQ/System/Event/StateMachines/__namespace__.yaml new file mode 100644 index 000000000..5ce1866e7 --- /dev/null +++ b/content/automate/ManageIQ/System/Event/StateMachines/__namespace__.yaml @@ -0,0 +1,10 @@ +--- +object_type: namespace +version: 1.0 +object: + attributes: + name: StateMachines + description: + display_name: + priority: + enabled: