Getting Nested Options


#1

Hi Everyone,

How would I access the option “miq_request_task.options[:data_center] = DC1 (type: String)”?

miq_request_task is an element of “miq_provision_request.miq_request_tasks.each do |miq_request_task” Which doesn’t seem to be available via array or hash or get_option/option…

miq_provision_request = $evm.root[‘miq_provision’].miq_provision_request
miq_provision_request.miq_request_tasks (type: Association)
| | | miq_provision_request.miq_request_tasks.each do |miq_request_task|
| | | (object type: MiqAeServiceServiceTemplateProvisionTask, object ID: 51000000003295)
| | | | miq_request_task.miq_request (type: Association)
| | | | miq_request = miq_request_task.miq_request
| | | | (object type: MiqAeServiceServiceTemplateProvisionRequest, object ID: 51000000001334)
| | | | | Object MiqAeServiceServiceTemplateProvisionRequest with ID 51000000001334 has already been printed…
| | | | miq_request_task.miq_request_task (type: Association)
| | | | miq_request_task = miq_request_task.miq_request_task
| | | | (object type: MiqAeServiceServiceTemplateProvisionTask, object ID: 51000000003294)
| | | | | — attributes follow —
| | | | | miq_request_task.created_on = 2017-08-11 09:55:36 UTC (type: ActiveSupport::TimeWithZone)
| | | | | miq_request_task.description = Provisioning [Windows Service] for Service [Windows Service] (type: String)
| | | | | miq_request_task.destination_id = 51000000001053 (type: Fixnum)
| | | | | miq_request_task.destination_type = Service (type: String)
| | | | | miq_request_task.id = 51000000003294 (type: Fixnum)
| | | | | miq_request_task.message = Finished (type: String)
| | | | | miq_request_task.miq_request_id = 51000000001334 (type: Fixnum)
| | | | | miq_request_task.miq_request_task_id = nil
| | | | | miq_request_task.options[:data_center] = DC1 (type: String)

Its an option that is set via task = $evm.root[‘service_template_provision_task’].set_option at / Service / Provisioning / StateMachines / ServiceProvision_Template / and I am trying to retrieve it at / Infrastructure / VM / Provisioning / StateMachines / VMProvision_VM

Thanks


#2

If you follow the object_walker guidance then it’s something like:

miq_provision_request = $evm.root[‘miq_provision’].miq_provision_request

request = $evm.root[‘miq_provision’].miq_provision_request

| | | miq_provision_request.miq_request_tasks.each do |miq_request_task|
| | | (object type: MiqAeServiceServiceTemplateProvisionTask, object ID: 51000000003295)

service_template_provision_task_1 = request.miq_request_tasks.first

| | | | miq_request_task = miq_request_task.miq_request_task
| | | | (object type: MiqAeServiceServiceTemplateProvisionTask, object ID: 51000000003294)

service_template_provision_task_2 = service_template_provision_task_1.miq_request_task

| | | | | miq_request_task.options[:data_center] = DC1 (type: String)

data_center = service_template_provision_task_2.get_option(:data_center)

In this example service_template_provision_task_2 is actually the parent service_template_provision_task, which is the task that you see as $evm.root['service_template_provision_task'] in the service provisioning state machine. I’m not sure that you could always guarantee the order of the two service_template_provision_tasks in the miq_provision_request.miq_request_tasks association.

Of course you could also say:

data_center = $evm.root[‘miq_provision’].miq_provision_request.miq_request_tasks.first.miq_request_task.get_option(:data_center)

Hope this helps,
pemcg


#3

@pemcg Thanks Pete.

This reminded me of the “Service Objects” section of the good (cf) book :wink: I am not 100% on how to manage variables between these yet. I did try your suggestion, but not thoroughly, without success. Fortunate the out of the box CatalogItemInit provides away to propagate options to child/grandchild processes and I am using that now.

In an effort to keep the CatalogItemInit “light weight” I would be interested in breaking out some of the code in there to separate methods, ran via pre 3, pre4, … in /Service/Provisioning/StateMachines/ServiceProvision_Template. I’ll have understand how to do the child propagation for that… back to the lab. :slightly_smiling_face:

Thanks again!