VMware vSphere

 View Only
  • 1.  Reading/modifying VM tags using the SDK?

    Posted Mar 14, 2014 09:19 AM

    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



  • 2.  RE: Reading/modifying VM tags using the SDK?

    Posted Dec 19, 2014 11:36 PM

    Did you ever find a resolution for this?

    I'm looking for the same.

    Thanks



  • 3.  RE: Reading/modifying VM tags using the SDK?

    Broadcom Employee
    Posted Dec 20, 2014 03:40 AM

    is this not working :vSphere 5.5 Documentation Center

    vSphere 5.5 Documentation Center

    As per API reference, tag property is experimental.



  • 4.  RE: Reading/modifying VM tags using the SDK?

    Posted Dec 22, 2014 07:28 AM

    Well, it should be possible with PowerCLI if you upgrade to 5.5, there are cmdlets Set-Tag, Get-Tag

    And here is nice article about using them: Using vSphere tags powercli



  • 5.  RE: Reading/modifying VM tags using the SDK?

    Posted Mar 01, 2016 10:19 PM

    Any update on this?

    The SDK / pyvmomi are now at version 6.0.  The Release Notes for SDK 6.0 mention new APIs for Tag management.  I can't find any information about them though.

    The use case I'm trying to address is for VMs to be classified via custom Attributes and/or Tags.  I'm using a PropertyCollector / WaitForUpdatesEx(), and for common property types (e.g. 'summary.config.name') this works fine.  Need to be able to do the same sort of thing with custom attributes and/or Tags, but so far have been unable to find any means of doing this.



  • 6.  RE: Reading/modifying VM tags using the SDK?

    Posted Mar 30, 2016 06:24 PM

    Ya this is pretty frustrating, I'm using yavijava 6 and have the same issue.



  • 7.  RE: Reading/modifying VM tags using the SDK?

    Posted Nov 21, 2017 01:30 PM

    Did anyone found a soultion yet?

    i am having the same issue.



  • 8.  RE: Reading/modifying VM tags using the SDK?

    Posted Jun 25, 2025 05:42 AM

    Is there any solutions found to fetch the tags associated with VMs in a vSphere environment using the vSphere SDK 8.0 U3 ?