Created
October 26, 2016 02:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
here is the related vsphere doc http://pubs.vmware.com/vsphere-60/index.jsp#com.vmware.vapi.progguide.doc/GUID-03794563-C50A-4C5C-86CC-3EA14495CC4E.html