mercredi 8 décembre 2021

Ruby - NoMethodError: undefined method for hash

How can I get the value of attribute and set it in a varaible?

Here is an example: The log shows all attributes. I want to fetch dialog_param_placement_availability_zone value and assign it to a variable.

$evm.root.attributes.sort.each { |k, v| log(:info, "\t Attribute: #{k} = #{v}")}


[----] I, [2021-12-08T07:42:45.138328 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: data_type = string
[----] I, [2021-12-08T07:42:45.139071 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: dialog_guest_access_key_pair = 5
[----] I, [2021-12-08T07:42:45.139928 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: dialog_instance_type = 26
[----] I, [2021-12-08T07:42:45.140745 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: dialog_list_ec2_cloudsubnets_ids =
[----] I, [2021-12-08T07:42:45.141400 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: dialog_list_ec2_template_guids = 60b75115-4f29-49fd-a8d5-d27364cfbef5
[----] I, [2021-12-08T07:42:45.142041 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: dialog_number_of_vms =
[----] I, [2021-12-08T07:42:45.142670 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: dialog_param_placement_availability_zone = 1
[----] I, [2021-12-08T07:42:45.143333 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: dialog_vm_name =
[----] I, [2021-12-08T07:42:45.144040 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: enable_rbac = false
[----] I, [2021-12-08T07:42:45.144976 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: miq_group = #<MiqAeMethodService::MiqAeServiceMiqGroup:0x0000565050716dc0>
[----] I, [2021-12-08T07:42:45.145857 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: miq_server = #<MiqAeMethodService::MiqAeServiceMiqServer:0x000056504ffed328>
[----] I, [2021-12-08T07:42:45.146521 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: miq_server_id = 1
[----] I, [2021-12-08T07:42:45.147148 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: object_name = list_ec2_cloudsubnets_ids
[----] I, [2021-12-08T07:42:45.147792 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: required = true
[----] I, [2021-12-08T07:42:45.148829 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: service_template = #<MiqAeMethodService::MiqAeServiceServiceTemplate:0x000056504beeddf0>
[----] I, [2021-12-08T07:42:45.149803 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: service_template_id = 6
[----] I, [2021-12-08T07:42:45.150583 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: sort_by = description
[----] I, [2021-12-08T07:42:45.151554 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: sort_order = ascending
[----] I, [2021-12-08T07:42:45.153210 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: tenant = #<MiqAeMethodService::MiqAeServiceTenant:0x000056504e1d0160>
[----] I, [2021-12-08T07:42:45.154263 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: user = #<MiqAeMethodService::MiqAeServiceUser:0x000056504e1d1470>
[----] I, [2021-12-08T07:42:45.154917 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: user_id = 1
[----] I, [2021-12-08T07:42:45.155546 #318:2b28283f1fa8]  INFO -- automation: <AEMethod list_ec2_cloudsubnets_ids>      Attribute: vmdb_object_type = service_template

I tried the following

availability_zone_id = $evm.root.attributes.dialog_param_placement_availability_zone`

But I get the error

undefined method dialog_param_placement_availability_zone' for #<Hash:0x00005650509e5808> (NoMethodError)`

Aucun commentaire:

Enregistrer un commentaire