1
0
mirror of https://github.com/vmware/vsphere-automation-sdk-python.git synced 2024-11-23 18:10:00 -05:00
vsphere-automation-sdk-python/samples/vsphere/sso/print_services.py

91 lines
3.8 KiB
Python
Raw Normal View History

2016-10-26 19:08:23 -04:00
"""
* *******************************************************
* Copyright (c) VMware, Inc. 2014. All Rights Reserved.
* *******************************************************
*
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
"""
__author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2014 VMware, Inc. All rights reserved.'
import argparse
from samples.vsphere.common.lookup_service_helper import LookupServiceHelper
2016-10-26 19:08:23 -04:00
class PrintServices(object):
"""
Demonstrates service discovery using lookup service APIs.
The sample prints all the PSC (Platform Service Controller) and Management Node (vCenter Server) and
some of the critical services (SSO, VAPI, VIM etc.) running on these nodes. This sample can also be used
to find out the server deployment (e.g. MxN setup with multiple PSC/Management nodes).
"""
def __init__(self):
self.lswsdlurl = None
self.lssoapurl = None
def options(self):
self.argparser = argparse.ArgumentParser(description=self.__doc__)
# setup the argument parser
self.argparser.add_argument('-w', '--lswsdlurl',
help='Lookup service WSDL URL')
self.argparser.add_argument('-s', '--lssoapurl',
help='Lookup service SOAP URL')
self.argparser.add_argument('-v', '--skipverification',
action='store_true',
help='Do not verify server certificate')
2016-10-26 19:08:23 -04:00
self.args = self.argparser.parse_args() # parse all the sample arguments when they are all set
def setup(self):
2017-01-23 18:27:54 -05:00
self.lswsdlurl = self.args.lswsdlurl
2016-10-26 19:08:23 -04:00
assert self.lswsdlurl is not None
print('lswsdlurl: {0}'.format(self.lswsdlurl))
2016-10-26 19:08:23 -04:00
2017-01-23 18:27:54 -05:00
self.lssoapurl = self.args.lssoapurl
2016-10-26 19:08:23 -04:00
assert self.lssoapurl is not None
print('lssoapurl: {0}'.format(self.lssoapurl))
2016-10-26 19:08:23 -04:00
self.skip_verification = self.args.skipverification
2016-10-26 19:08:23 -04:00
def execute(self):
print('Connecting to lookup service url: {0}'.format(self.lssoapurl))
lookupservicehelper = LookupServiceHelper(wsdl_url=self.lswsdlurl,
soap_url=self.lssoapurl,
skip_verification=self.skip_verification)
2016-10-26 19:08:23 -04:00
lookupservicehelper.connect()
# print the PSC nodes and SSO service endpoint URLs
for index, sso_url in enumerate(lookupservicehelper.find_sso_urls(), start=1):
print('=============================')
print('PSC node: {0}'.format(index))
print(' SSO URL: {0}'.format(sso_url))
print('=============================')
2016-10-26 19:08:23 -04:00
# print the mgmt (vCenter Server) nodes and some of the critical service endpoint URLs
for instance_name, node_id in lookupservicehelper.find_mgmt_nodes().items():
print('=============================')
print('Mgmt node instance name: {0} node_id: {1}'.format(instance_name, node_id))
print(' VAPI URL: {0}'.format(lookupservicehelper.find_vapi_url(node_id)))
print(' VIM URL: {0}'.format(lookupservicehelper.find_vim_url(node_id)))
print(' SPBM URL: {0}'.format(lookupservicehelper.find_vim_pbm_url(node_id)))
print('=============================')
2016-10-26 19:08:23 -04:00
def cleanup(self):
pass
def main():
printServices = PrintServices()
printServices.options()
printServices.setup()
printServices.execute()
printServices.cleanup()
# Start program
if __name__ == "__main__":
main()