Class: MiqDevUtil::Automate
- Inherits:
-
Object
- Object
- MiqDevUtil::Automate
- Defined in:
- lib/miq_dev_util/automate.rb
Overview
The Automate class is intended to hold methods that are useful when interacting with the ManageIQ automate system directly.
Instance Method Summary collapse
-
#get_instance_with_attributes(path) ⇒ Object
This is a hacky workaround used to get an instance without executing the methods on it.
-
#initialize(evm) ⇒ Automate
constructor
A new instance of Automate.
-
#instantiate_or_raise(path, message) ⇒ Object
Instantiate an automate instance at path or raise an exception with the message provided if the instantiation returns nil (not found).
-
#resolve_vm(lookup_order: [:rootvm, :dialog_id, :provision], dialog_name: 'dialog_target_server') ⇒ Object
Condense multiple types of VM lookups into one call.
Constructor Details
#initialize(evm) ⇒ Automate
Returns a new instance of Automate.
5 6 7 |
# File 'lib/miq_dev_util/automate.rb', line 5 def initialize(evm) @evm = evm end |
Instance Method Details
#get_instance_with_attributes(path) ⇒ Object
This is a hacky workaround used to get an instance without executing the methods on it. It fails if a message is passed in the path or if the message field on the any of the methods are *.
23 24 25 26 27 28 29 30 31 |
# File 'lib/miq_dev_util/automate.rb', line 23 def get_instance_with_attributes(path) if path =~ /#/ raise "Does not work with messages in the path." end = "callingWithAFakeMessage" empty_instance = @evm.instantiate("#{path}##{fake_message}") instance_name = empty_instance.name @evm.instance_get(instance_name) end |
#instantiate_or_raise(path, message) ⇒ Object
Instantiate an automate instance at path or raise an exception with the message provided if the instantiation returns nil (not found).
11 12 13 14 15 16 17 18 |
# File 'lib/miq_dev_util/automate.rb', line 11 def instantiate_or_raise(path, ) object = @evm.instantiate(path) if object.nil? raise end object end |
#resolve_vm(lookup_order: [:rootvm, :dialog_id, :provision], dialog_name: 'dialog_target_server') ⇒ Object
Condense multiple types of VM lookups into one call. This is useful when making an Automate method generic enough to be used during provisioning, with a custom button, or as a catalog item.
Lookup methods used and their order can be overridden by specifying :lookup_order
The dialog name that may hold the miq ID is specified via :dialog_name
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/miq_dev_util/automate.rb', line 41 def resolve_vm(lookup_order: [:rootvm, :dialog_id, :provision], dialog_name: 'dialog_target_server') vm = nil lookup_order.each do |lu_method| vm = vm_lookup_by(lu_method, dialog_name) # If we found a VM we can stop looking break unless vm.nil? end vm end |