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
748 stars 311 forks source link

DynamicID should check type and fail for wrong type assigned #242

Open Akasurde opened 4 years ago

Akasurde commented 4 years ago

Environment

Steps or code snippet to reproduce

from vmware.vapi.vsphere.client import create_vsphere_client
import requests
from com.vmware.vapi.std_client import DynamicID
import urllib3
urllib3.disable_warnings()

session = requests.Session()
session.verify = False

hostname = "10.65.201.153"
username = "administrator@vsphere.local"
password = "Esxi@123$%"

client = create_vsphere_client(server=hostname,
                               username=username,
                               password=password,
                               session=session)
tag_svc = client.tagging.Tag
tag_ass_svc = client.tagging.TagAssociation

tags = []

cluster_id = 'domain-c9'
cls_dynamic_id = DynamicID(type='ComputeClusterResource', id=cluster_id) # This is wrong type, it should be ClusterComputeResource
tag_ids = tag_ass_svc.list_attached_tags(cls_dynamic_id)
for tag_id in tag_ids:
    tags.append(tag_svc.get(tag_id))

print(tags)

Actual behavior

[]

Expected behavior

[TagModel(id='urn:vmomi:InventoryServiceTag:0deaa3f7-a91e-4c20-bf19-f15201c49ec2:GLOBAL', category_id='urn:vmomi:InventoryServiceCategory:ca46a635-5e0c-47e9-a4c1-9682ac281928:GLOBAL', name='tag_0001', description='', used_by=set())]

Akasurde commented 4 years ago

When specifying the wrong type in DynamicID should raise an error or exception.