如何獲取屬性的值并將其設定在變數中?
這是一個示例:日志顯示所有屬性。我想獲取dialog_param_placement_availability_zone值并將其分配給一個變數。
$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
我嘗試了以下
availability_zone_id = $evm.root.attributes.dialog_param_placement_availability_zone`
但我得到了錯誤
undefined method dialog_param_placement_availability_zone' for #<Hash:0x00005650509e5808> (NoMethodError)`
uj5u.com熱心網友回復:
您可以像這樣訪問值
availability_zone_id = $evm.root.attributes["dialog_param_placement_availability_zone"]
這里有一些很好的答案,解釋了如何訪問哈希值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/376639.html
