Reputation: 9539
I am querying a datastore with its name in vcenter using an example of pyvmomi sample code:
si = connect.SmartConnectNoSSL(host=192.168.1.2, user=Administrator, pwd=password, port=443)
content = si.RetrieveContent()
container = content.viewManager.CreateContainerView(content.rootFolder, [vim.Datastore], True)
for c in container.view:
if c.name == "datastore-01":
vim_obj = c
break
return vim_obj
This worked fine if there is only one datacenter. But if I have more than one datacenter with same name datastore in each of those datacenters, the query returns only first datastore it finds. I was able to find that the datstores are in content.rootFolder.childEntity[].datastoreFolder.childEntity[]
path but wondering how to query for specific datastore in a datacenter.
Upvotes: 0
Views: 2175
Reputation: 9539
figured out a solution to my question. Posting if somebody else looking for an answer:
for c in container.view:
if c.name == "datacenter-01":
datastores = c.datastoreFolder.childEntity
for datastore in datastores:
if datastore.name == "datastore-01":
vim_obj = datastore
break
return vim_obj
Upvotes: 1