1
0
mirror of https://github.com/vmware/vsphere-automation-sdk-python.git synced 2024-11-27 03:30:00 -05:00
vsphere-automation-sdk-python/samples/vsphere/vcenter/vm/list_vms.py

63 lines
2.0 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+'
from pprint import pprint
from vmware.vapi.vsphere.client import create_vsphere_client
2016-10-26 19:08:23 -04:00
from samples.vsphere.common import sample_cli
from samples.vsphere.common import sample_util
from samples.vsphere.common.ssl_helper import get_unverified_session
2016-10-26 19:08:23 -04:00
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("----------------------------")
2016-10-26 19:08:23 -04:00
def main():
list_vm = ListVM()
list_vm.run()
2016-10-26 19:08:23 -04:00
if __name__ == '__main__':
main()