How do I set values for my vm request - miq_request resource.options?

Hello,

Seeking help in trying to find a way to set options for a VMware provision. Looking at the dictionary of objects and methods. It seems that I may have to use a sub function of the object to set the values. set_option(key, value)

I crawled looking with object walker and see a setting that says resource.set_option. How would I set values to these vm options (esx host, datastore, description, etc) with an inline method?

Blockquote
[----] I, [2019-09-25T23:19:42.273366 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.miq_provisions (type: Association (empty))
[----] I, [2019-09-25T23:19:42.309545 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.miq_request (type: Association)
[----] I, [2019-09-25T23:19:42.326249 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] miq_request = resource.miq_request
[----] I, [2019-09-25T23:19:42.354705 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] (object type: MiqAeServiceMiqProvisionRequestTemplate, object ID: 1000000000202)
[----] I, [2019-09-25T23:19:42.380659 #19280:153aa1b4] INFO – : object_walker#7A009058:[5] Object MiqAeServiceMiqProvisionRequestTemplate with ID 1000000000202 has already been printed…
[----] I, [2019-09-25T23:19:42.427676 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.miq_request_tasks (type: Association (empty))
[----] I, [2019-09-25T23:19:42.490096 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.requester (type: Association)
[----] I, [2019-09-25T23:19:42.497502 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] *** not walking: ‘requester’ isn’t in the walk_association_whitelist hash for MiqAeServiceMiqProvisionRequestTemplate ***
[----] I, [2019-09-25T23:19:42.525443 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.resource (type: Association)
[----] I, [2019-09-25T23:19:42.527690 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] *** not walking: ‘resource’ isn’t in the walk_association_whitelist hash for MiqAeServiceMiqProvisionRequestTemplate ***
[----] I, [2019-09-25T23:19:42.541845 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.source (type: Association)
[----] I, [2019-09-25T23:19:42.549963 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] *** not walking: ‘source’ isn’t in the walk_association_whitelist hash for MiqAeServiceMiqProvisionRequestTemplate ***
[----] I, [2019-09-25T23:19:42.578493 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.tenant (type: Association)
[----] I, [2019-09-25T23:19:42.597928 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] *** not walking: ‘tenant’ isn’t in the walk_association_whitelist hash for MiqAeServiceMiqProvisionRequestTemplate ***
[----] I, [2019-09-25T23:19:42.649637 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.vm_template (type: Association)
[----] I, [2019-09-25T23:19:42.653359 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] *** not walking: ‘vm_template’ isn’t in the walk_association_whitelist hash for MiqAeServiceMiqProvisionRequestTemplate ***
[----] I, [2019-09-25T23:19:42.665004 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] — end of associations —
[----] I, [2019-09-25T23:19:42.742555 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] — methods follow —
[----] I, [2019-09-25T23:19:42.751515 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.add_tag
[----] I, [2019-09-25T23:19:42.765123 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.approve
[----] I, [2019-09-25T23:19:42.767957 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.authorized?
[----] I, [2019-09-25T23:19:42.776226 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.cancel_requested?
[----] I, [2019-09-25T23:19:42.787753 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.canceled?
[----] I, [2019-09-25T23:19:42.789034 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.canceling?
[----] I, [2019-09-25T23:19:42.791008 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.check_quota
[----] I, [2019-09-25T23:19:42.797464 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.ci_type
[----] I, [2019-09-25T23:19:42.817466 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.clear_tag
[----] I, [2019-09-25T23:19:42.835435 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.deny
[----] I, [2019-09-25T23:19:42.840650 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.description=
[----] I, [2019-09-25T23:19:42.845696 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.eligible_resources
[----] I, [2019-09-25T23:19:42.870402 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.get_classification
[----] I, [2019-09-25T23:19:42.874239 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.get_classifications
[----] I, [2019-09-25T23:19:42.888588 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.get_folder_paths
[----] I, [2019-09-25T23:19:42.890938 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.get_option
[----] I, [2019-09-25T23:19:42.898041 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.get_option_last
[----] I, [2019-09-25T23:19:42.908986 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.get_retirement_days
[----] I, [2019-09-25T23:19:42.913901 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.get_tag
[----] I, [2019-09-25T23:19:42.918106 #19280:eca2ef8] INFO – : object_walker#E0D8C6E4:[4] resource.eligible_pxe_servers (type: Association (empty))
[----] I, [2019-09-25T23:19:42.918386 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.get_tags
[----] I, [2019-09-25T23:19:42.924858 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.inspect
[----] I, [2019-09-25T23:19:42.929793 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.inspect_all
[----] I, [2019-09-25T23:19:42.936354 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.model_suffix
[----] I, [2019-09-25T23:19:42.938891 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.pending
[----] I, [2019-09-25T23:19:42.952941 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.register_automate_callback
[----] I, [2019-09-25T23:19:42.957201 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.reload
[----] I, [2019-09-25T23:19:42.971982 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.set_cluster
[----] I, [2019-09-25T23:19:42.983043 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.set_customization_template
[----] I, [2019-09-25T23:19:42.990407 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.set_dvs
[----] I, [2019-09-25T23:19:42.995363 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.set_folder
[----] I, [2019-09-25T23:19:43.002567 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.set_host
[----] I, [2019-09-25T23:19:43.004489 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.set_iso_image
[----] I, [2019-09-25T23:19:43.011658 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.set_message
[----] I, [2019-09-25T23:19:43.014610 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.set_network_adapter
[----] I, [2019-09-25T23:19:43.037192 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.set_network_address_mode
[----] I, [2019-09-25T23:19:43.058009 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.set_nic_settings
[----] I, [2019-09-25T23:19:43.073496 #19280:153aa1b4] INFO – : object_walker#7A009058:[4] resource.set_option

whats the proper syntax to do this?

Are you looking for this?
https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/vm_provisioning_objects/chapter.html

Thanks. That looks right.

I tried it in my dynamic variable method:

Pillar = $evm.root[‘dialog_var_BCM_Pillar’]
Platform = $evm.root[‘dialog_var_Platform’]
System = $evm.root[‘dialog_var_System’]
AppCode = $evm.root[‘dialog_var_AppCode’]
ServerRole = $evm.root[‘dialog_var_ServerRole’]
Environment = $evm.root[‘dialog_var_Environment’]
Svr_Number = $evm.root[‘dialog_var_Svr_Number’]
Dynamic_Hostname = $evm.root[‘dialog_dynamic_vm_name’]
Whole_Hostname = $evm.root[‘dialog_vm_name’]
TargetVMName = $evm.root[‘dialog_option_1_vm_target_name’]
var_concatenated_string = “#{Pillar}#{Platform}#{System}-#{AppCode}#{ServerRole}-#{Environment}#{Svr_Number}”
miq_provision_request.set_option(“vm_name”, var_concatenated_string)

and I get this the following results

—] I, [2019-09-26T07:05:50.792547 #19280:9c22a0] INFO – : Setting dialog variable value to -as-01
[----] E, [2019-09-26T07:05:50.794493 #19280:9c22a0] ERROR – : The following error occurred during method evaluation:
[----] E, [2019-09-26T07:05:50.800069 #19280:9c22a0] ERROR – : NameError: undefined local variable or method miq_provision_request' for main:Object [----] E, [2019-09-26T07:05:50.804135 #19280:9c22a0] ERROR -- : <AEMethod method_bcm_server_derived_name> [----] E, [2019-09-26T07:05:50.817043 #19280:9c22a0] ERROR -- : Method STDERR: /Bens_Quicksilver_Dev/Service/Provisioning/StateMachines/Methods/method_bcm_server_derived_name:68:in‘: undefined local variable or method `miq_provision_request’ for main:Object (NameError)
[----] I, [2019-09-26T07:05:50.854388 #19280:43121cc] INFO – : <AEMethod [/Bens_Quicksilver_Dev/Service/Provisioning/StateMachines/Methods/method_bcm_server_derived_name]> Ending
[----] E, [2019-09-26T07:05:50.855989 #19280:43121cc] ERROR – : Aborting instantiation (unknown method return code) because [Method exited with rc=Unknown RC: [1]]

I think the problem is that your miq_provision_request variable is undefined. If you’re running this from the VM Provision state machine then you’ll actually need the task object rather than the request object, so try something like this:

prov = $evm.root['miq_provision']
prov.set_option(:vm_target_name, var_concatenated_string)

Once you’re in provisioning task context (i.e. the VM provision state machine) then you need to use :vm_target_name rather than :vm_name to set the VM name. The options hash variable :vm_name is only used as an input parameter to the built-in naming method, which is run during the request stage of the VM provision (so by the time your method runs will have already done its stuff).

Hope this helps,
pemcg

Ok. I was trying to set this in the MIQ_Request while it is still on the dialog form, but I think you have a point. This is probably better handled in the MIQ_Provision state machine. I’ll give this a shot and let you all know how this works out.

Many thanks