2018-06-25 07:45:00 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""
|
|
|
|
* *******************************************************
|
2018-11-22 02:51:21 -05:00
|
|
|
* Copyright (c) VMware, Inc. 2016, 2018. All Rights Reserved.
|
2018-06-25 07:45:00 -04:00
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
* *******************************************************
|
|
|
|
*
|
|
|
|
* 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 2018 VMware, Inc. All rights reserved.'
|
|
|
|
__vcenter_version__ = '6.7+'
|
|
|
|
|
2018-06-25 11:43:31 -04:00
|
|
|
from vmware.vapi.vsphere.client import create_vsphere_client
|
|
|
|
from samples.vsphere.common.ssl_helper import get_unverified_session
|
|
|
|
|
2018-06-25 07:45:00 -04:00
|
|
|
from samples.vsphere.common import sample_cli
|
|
|
|
from samples.vsphere.common import sample_util
|
|
|
|
|
2018-09-21 16:38:40 -04:00
|
|
|
|
2018-06-25 07:45:00 -04:00
|
|
|
class ListServices(object):
|
|
|
|
"""
|
|
|
|
Demonstrates the details of vCenter Services
|
|
|
|
|
|
|
|
Retrieves the vCenter Services, its Health Status and Service Startup Type.
|
|
|
|
|
|
|
|
Prerequisites:
|
|
|
|
- vCenter Server
|
|
|
|
"""
|
|
|
|
|
2018-09-21 16:38:40 -04:00
|
|
|
def __init__(self):
|
2018-06-25 07:45:00 -04:00
|
|
|
# Create argument parser for standard inputs:
|
2018-06-25 11:43:31 -04:00
|
|
|
# server, username, password and skipverification
|
2018-06-25 07:45:00 -04:00
|
|
|
parser = sample_cli.build_arg_parser()
|
|
|
|
args = sample_util.process_cli_args(parser.parse_args())
|
|
|
|
|
2018-06-25 11:43:31 -04:00
|
|
|
# Skip server cert verification if needed.
|
|
|
|
# This is not recommended in production code.
|
|
|
|
session = get_unverified_session() if args.skipverification else None
|
|
|
|
|
2018-06-25 07:45:00 -04:00
|
|
|
# Connect to vSphere client
|
2018-11-22 02:51:21 -05:00
|
|
|
self.client = create_vsphere_client(
|
|
|
|
server=args.server,
|
|
|
|
username=args.username,
|
|
|
|
password=args.password,
|
|
|
|
session=session)
|
2018-09-21 16:38:40 -04:00
|
|
|
|
2018-06-25 07:45:00 -04:00
|
|
|
def run(self):
|
2018-06-25 11:43:31 -04:00
|
|
|
services_list = self.client.vcenter.services.Service.list_details()
|
2018-09-21 16:38:40 -04:00
|
|
|
for key, value in services_list.items():
|
2018-11-22 02:51:21 -05:00
|
|
|
print(
|
|
|
|
'Service Name: {}, Service Name Key: {}, Service Health: {}, Service Status: {}, Service Startup Type: {}'
|
|
|
|
).format(key, value.name_key, value.health, value.state,
|
|
|
|
value.startup_type)
|
2018-09-21 16:38:40 -04:00
|
|
|
|
2018-06-25 07:45:00 -04:00
|
|
|
|
|
|
|
def main():
|
|
|
|
list_services = ListServices()
|
|
|
|
list_services.run()
|
|
|
|
|
2018-09-21 16:38:40 -04:00
|
|
|
|
2018-06-25 07:45:00 -04:00
|
|
|
if __name__ == '__main__':
|
2018-09-21 16:38:40 -04:00
|
|
|
main()
|