A sample datacenter ("DC1") hierarchy structure is given below, under DC1 there are two parent folders "Parent1" and "Parent2". Under them there are sub-folders containing VMs. I have to deploy the ovf under the correct sub-folder under the given parent path. For instance, I have to deploy it under subfolder2 of Parent1 and not under Parent2.
Folder input: parent1/subfolder1/subfolder2
DC1
|
|----Parent1
| |---subfolder1
| |---subfolder2
|
|----Parent2
| |---subfolder2
Current code searches for the first available folder name from the datacenter folder objects' list without following the directory structure.
from pyvim.connect import SmartConnect, Disconnect
import ssl
try:
#context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
#context.verify_mode = ssl.CERT_NONE
context = ssl._create_unverified_context()
si = SmartConnect(host=args.host,
user="root",
pwd="****",
port=int("443"),
sslContext=context)
except:
raise Exception("Unable to connect")
datacenter = connect.content.rootFolder.childEntity[0]
vmfolder_list = datacenter.vmFolder.childEntity
for vmfolder in vmfolder_list:
if vmfolder.name == search_folder:
return vmfolder
raise Exception("Unable to find object by the name of %s in list:\n%s" %
(search_folder, map(lambda x: x.name, vmfolder_list)))