Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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