1
0
mirror of https://github.com/vmware/vsphere-automation-sdk-python.git synced 2024-11-23 01:49:59 -05:00
vsphere-automation-sdk-python/samples/vsphere/vcenter/vm/list_vms.py

72 lines
2.1 KiB
Python
Raw Normal View History

2016-10-26 19:08:23 -04:00
#!/usr/bin/env python
"""
* *******************************************************
* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
* SPDX-License-Identifier: MIT
2016-10-26 19:08:23 -04:00
* *******************************************************
*
* 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+'
2016-10-26 19:08:23 -04:00
import atexit
2016-10-26 19:08:23 -04:00
from com.vmware.vcenter_client import VM
from samples.vsphere.common import sample_cli
from samples.vsphere.common import sample_util
from samples.vsphere.common.service_manager import ServiceManager
from pprint import pprint
2016-10-26 19:08:23 -04:00
class ListVM(object):
"""
Demonstrates getting list of VMs present in vCenter
Sample Prerequisites:
vCenter/ESX
"""
2016-10-26 19:08:23 -04:00
def __init__(self):
self.service_manager = None
2016-10-26 19:08:23 -04:00
def setup(self):
parser = sample_cli.build_arg_parser()
args = sample_util.process_cli_args(parser.parse_args())
2016-10-26 19:08:23 -04:00
self.service_manager = ServiceManager(args.server,
args.username,
args.password,
args.skipverification)
self.service_manager.connect()
atexit.register(self.service_manager.disconnect)
def run(self):
"""
List VMs present in server
"""
vm_svc = VM(self.service_manager.stub_config)
list_of_vms = vm_svc.list()
print("----------------------------")
print("List Of VMs")
print("----------------------------")
pprint(list_of_vms)
print("----------------------------")
2016-10-26 19:08:23 -04:00
def main():
list_vm = ListVM()
list_vm.setup()
list_vm.run()
2016-10-26 19:08:23 -04:00
if __name__ == '__main__':
main()