Skip to content

Instantly share code, notes, and snippets.

@jessehu
Created October 26, 2016 02:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessehu/2e28b2d8ab454e67712cd943a8500512 to your computer and use it in GitHub Desktop.
Save jessehu/2e28b2d8ab454e67712cd943a8500512 to your computer and use it in GitHub Desktop.
List linked mode vCenter Servers 6.0 or other Service Endpoints from PSC
from pyVim import connect
import requests
import sys, ssl
from xml.etree.ElementTree import XML, fromstring, tostring
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
server=sys.argv[1]
protocol='https'
port=443
path='lookupservice/sdk'
url = "%s://%s:%s/%s" % (protocol, server, port, path)
baseVersion = 'lookup'
# Disabling SSL certificate verification
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
context.verify_mode = ssl.CERT_NONE
versionId = 'urn:lookup/2.0'
headers = {'content-type': 'text/xml; charset=utf-8', 'Accept': 'text/xml,multipart/*,application/soap', 'SOAPAction': versionId}
body="""
<soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body>
<List xmlns='urn:lookup'>
<_this type='LookupServiceRegistration'>ServiceRegistration</_this>
<filterCriteria>
<serviceType>
<product>com.vmware.cis</product>
<type>vcenterserver</type>
</serviceType>
</filterCriteria>
</List>
</soap:Body>
</soap:Envelope>
"""
response=requests.post(url,data=body,headers=headers, verify=False)
#print response, response.content
soapResponse = fromstring(response.content)
vCenterList=[]
returnvalList = soapResponse.findall('.//{urn:' + baseVersion + '}returnval')
for retVal in returnvalList:
nodes = retVal.findall('.//{urn:' + baseVersion + '}url')
for node in nodes:
#print node.text
if node.text.endswith(':443/sdk'):
vCenterList.append(node.text)
print vCenterList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment