vmware / pyvmomi

VMware vSphere API Python Bindings
Apache License 2.0
2.22k stars 766 forks source link

Having trouble retrieving config.ExtraConfig.OptionValue #193

Closed zukeru closed 9 years ago

zukeru commented 10 years ago

Goal: To determine by a each VM's UUID if it is managed by vCloud Director or vCenter. This is so I can know which API to send the commands too. I search each vm by UUID because the program is looping through a command_dictonary. Thus, it is not always looping through a very large amount of VM's.

Since I already have the VM object I'm trying to get to the object value config.extraConfig Inside this object value there is an array of values. This is also where the vCloud director UUID is stored. I need this UUID to make the REST URL needed to send commands to vCloud Director.

However I am having issues accessing the value. Basically I want iterate over the object array list until the .Key value is =='cloud.uuid' however, the code I'm using returns the error:

2014-12-01 15:41:00,278 ERROR ApplicationError
Traceback (most recent call last):
  File "/home/grant/workspace/Portal/PortalModules/PortalBackendController.py", line 240, in  vm_command_center
    print option.Key, option.value
 AttributeError: 'vim.option.OptionValue' object has no attribute 'Key'

This is the code I'm using:

           for vcenter in list_of_vc_connections:
              #call the current time to keep the connection alive.
              list_of_vc_connections[vcenter].CurrentTime()
              vm_uuid = command_dict[command]['vm_uuid']
              search_index = list_of_vc_connections[vcenter].content.searchIndex
              vm = search_index.FindByUuid(None, vm_uuid, True, True)
              command_exec = command_dict[command]['command']
              vcenter_uuid = uuid_dict[vcenter]
              vm_mor = vm._moId
              for option in vm.config.extraConfig:
                 print option
                 if option.Key == 'cloud.uuid':
                    print option.value

This is what it prints for option:

(vim.option.OptionValue) {
   dynamicType = <unset>,
   dynamicProperty = (vmodl.DynamicProperty) [],
   key = 'hpet0.present',
   value = 'true'
}
purple4reina commented 10 years ago

I believe your issue is case sensitivity. You are looking for option.Key when the attribute is actually option.key.

zukeru commented 10 years ago

ahhhhhh I see wow let me try that I believe I should head + keyboard right now if thats it.