I'm trying to read/edit tags associated with a virtual machine by using the vsphere sdk (with pyvmomi cause I prefer python, our VSphere has version 5.1). The vm object has a field "tag" which should contain the tag - but in fact it contains the custom attribute, not the tag.
A simple code excerpt:
from pyVim.connect import SmartConnect, Disconnect def tags(vm): if hasattr(vm, 'childEntity'): vmList = vm.childEntity for c in vmList: tags(c) else: print vm.name for k in vm.tag: print k def main(): si = SmartConnect(host="<host>", user="<user>", pwd="<password>", port=<port>) content = si.RetrieveContent() datacenter = content.rootFolder.childEntity[0] vmFolder = datacenter.vmFolder vmList = vmFolder.childEntity for vm in vmList: tags(vm) if __name__ == "__main__": main()
This code prints the custom attributes of the VMs (which is a bit surprising because of the naming of fields like vm.tag), but I'm looking for the tags and categories. Where can I find this information?
Mathias