vmware / vsphere-automation-sdk-python

Python samples, language bindings, and API reference documentation for vSphere, VMC, and NSX-T using the VMware REST API
MIT License
745 stars 313 forks source link

Tag name association to Tag urn #360

Closed alan-cugler closed 1 year ago

alan-cugler commented 1 year ago

Is your feature request related to a problem? Please describe.

A client is asking for their vCenter Tags associated to VMs to be imported to the grains system of Aria Automation Config (open-salt). This is a good fit for integration between the two pieces of technology. I attempted to achieve this by installing the vsphere-automation-sdk in the open-salt python environment. This did work and I was able to authenticate a session to vCenter!

However, I found I was able to extract the information of VM names and VM IDs, and I was able to get Tag URNs assigned to VM IDs. But there was no way to associate the Tag URNs to the human readable Tag names.

image

Describe the solution you'd like

I would like the Tag names to also be part of the data returned when calling session.vcenter.tagging.Associations.list().

Alternatively, the Tags Names ( +URNs?) could also be part of information returned from session.vcenter.VM.get() or session.vcenter.VM.list()

Describe alternatives you've considered

Additional context

VM.list() output in my PSO lab image

VM.get() output in my PSO lab image

Tags in my PSO lab image

Tag connected to my VM that has an ID of vm-49 image

tldlauser commented 1 year ago

I think this might be it: https://vdc-repo.vmware.com/vmwb-repository/dcr-public/97e6db01-d441-472e-ad53-b48c2bb0e1e4/45347fb1-052d-44b7-b3e9-cbefc34488e3/SDK/vsphere-ws/docs/ReferenceGuide/vim.Tag.html

tldlauser commented 1 year ago

This one seems better. https://developer.vmware.com/apis/vsphere-automation/latest/vcenter/tagging/ The whitepaper it references says, "To retrieve tag names from these IDs, you must use get() calls. For example, Tag.get() returns a TagModel object that has name, id, category_ id, description, and used_by fields."

kunal-pmj commented 1 year ago

Thanks @tldlauser for answering how to get the tag properties from tag id. @alan-cugler
In the associations, providing attributes other than id is not desirable

Kindly used the getTag API to get the name .

I am closing the issue.

Thanks Kunal

alan-cugler commented 1 year ago

I request this be reopened to at least explain how to get tags, the White paper does not clearly specify how to get tag name to vm associations clearly. It makes up alot of its own api calls that are not in the official api.

kunal-pmj commented 1 year ago

Kindly refer to the sample on how to get the tag from tag_id https://github.com/vmware/vsphere-automation-sdk-python/blob/master/samples/vsphere/tagging/tagging_workflow.py#L173

From tag association get the tag_id and pass it to the client.tagging.Tag.get(tag_id)