#!/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 2017 VMware, Inc. All rights reserved.' __vcenter_version__ = '6.5+' from pprint import pprint from vmware.vapi.vsphere.client import create_vsphere_client from samples.vsphere.common import sample_cli from samples.vsphere.common import sample_util from samples.vsphere.common.ssl_helper import get_unverified_session class ListVM(object): """ Demonstrates getting list of VMs present in vCenter Sample Prerequisites: vCenter/ESX """ def __init__(self): parser = sample_cli.build_arg_parser() args = sample_util.process_cli_args(parser.parse_args()) session = get_unverified_session() if args.skipverification else None self.client = create_vsphere_client(server=args.server, username=args.username, password=args.password, session=session) def run(self): """ List VMs present in server """ list_of_vms = self.client.vcenter.VM.list() print("----------------------------") print("List Of VMs") print("----------------------------") pprint(list_of_vms) print("----------------------------") def main(): list_vm = ListVM() list_vm.run() if __name__ == '__main__': main()