Description
Issue:
When i try to execute the below code, i always get only the hostname , but not the full path
Script Below
===============================================
#!/usr/bin/env python
"""
List Of Hosts in a Cluster
"""
from pyVmomi import vim
from pyVim.connect import SmartConnect, Disconnect
import atexit
import argparse
import getpass
import ssl
import requests
def get_args():
""" Get arguments from CLI """
parser = argparse.ArgumentParser(
description='Arguments for talking to vCenter')
parser.add_argument('-s', '--host',
required=True,
action='store',
help='vSpehre service to connect to')
parser.add_argument('-o', '--port',
type=int,
default=443,
action='store',
help='Port to connect on')
parser.add_argument('-u', '--user',
required=True,
action='store',
help='Username to use')
parser.add_argument('-p', '--password',
required=False,
action='store',
help='Password to use')
args = parser.parse_args()
if not args.password:
args.password = getpass.getpass(
prompt='Enter password')
return args
def get_obj(content, vimtype, name = None):
return [item for item in content.viewManager.CreateContainerView(
content.rootFolder, [vimtype], recursive=True).view]
def get_all_objs(content, vimtype):
obj = {}
container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
for managed_object_ref in container.view:
obj.update({managed_object_ref: managed_object_ref.name})
return obj
def main():
args = get_args()
# Disabling urllib3 ssl warnings
requests.packages.urllib3.disable_warnings()
# Disabling SSL certificate verification
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
context.verify_mode = ssl.CERT_NONE
# connect this thing
si = SmartConnect(
host=args.host,
user=args.user,
pwd=args.password,
port=args.port,
sslContext=context)
# disconnect this thing
atexit.register(Disconnect, si)
content = si.RetrieveContent()
hosts=get_all_objs(content, [vim.HostSystem])
for host_obj in hosts: #get_obj(content, [vim.HostSystem]):
print "Host Name:", host_obj.name
if name == "main":
main()
===============================================
Output:
cluster1
cluster2
cluster3
Expected Output:
/Folder/DCNAME/clustername
What should i do to get the full path.
For example when we use govc ls
It displays the full path as mentioned in the Expected Output. Help please.