1
0
mirror of https://github.com/vmware/vsphere-automation-sdk-python.git synced 2024-11-21 17:29:59 -05:00

Merge pull request #78 from jobingeo/master

A sample to list the Services in the vCenter Server. Signed-off-by:jo…
This commit is contained in:
Tianhao He 2018-06-26 10:07:31 +08:00 committed by GitHub
commit 01829d6d5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,72 @@
#!/usr/bin/env python
"""
* *******************************************************
* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
* 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+'
from tabulate import tabulate
from vmware.vapi.vsphere.client import create_vsphere_client
from samples.vsphere.common.ssl_helper import get_unverified_session
from samples.vsphere.common import sample_cli
from samples.vsphere.common import sample_util
class ListServices(object):
"""
Demonstrates the details of vCenter Services
Retrieves the vCenter Services, its Health Status and Service Startup Type.
Prerequisites:
- vCenter Server
"""
def __init__(self):
# Create argument parser for standard inputs:
# server, username, password and skipverification
parser = sample_cli.build_arg_parser()
args = sample_util.process_cli_args(parser.parse_args())
# Skip server cert verification if needed.
# This is not recommended in production code.
session = get_unverified_session() if args.skipverification else None
# Connect to vSphere client
self.client = create_vsphere_client(server=args.server,
username=args.username,
password=args.password,
session=session)
def run(self):
services_list = self.client.vcenter.services.Service.list_details()
table = []
for key,value in services_list.items():
row = [key,
value.name_key,
value.health,
value.state,
value.startup_type]
table.append(row)
headers = ["Service Name", "Service Name Key", "Service Health", "Service Status", "Service Startup Type"]
print(tabulate(table,headers))
def main():
list_services = ListServices()
list_services.run()
if __name__ == '__main__':
main()