2016-10-26 19:08:23 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
|
|
|
* *******************************************************
|
|
|
|
* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
|
2017-03-15 18:36:13 -04:00
|
|
|
* 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.
|
|
|
|
"""
|
|
|
|
|
2017-08-18 02:09:38 -04:00
|
|
|
__author__ = 'VMware, Inc.'
|
|
|
|
__copyright__ = 'Copyright 2017 VMware, Inc. All rights reserved.'
|
|
|
|
__vcenter_version__ = '6.5+'
|
|
|
|
|
2018-03-08 16:02:07 -05:00
|
|
|
from pprint import pprint
|
2017-08-18 02:09:38 -04:00
|
|
|
|
2018-03-08 16:02:07 -05:00
|
|
|
from vmware.vapi.vsphere.client import create_vsphere_client
|
2016-10-26 19:08:23 -04:00
|
|
|
|
2017-08-18 02:09:38 -04:00
|
|
|
from samples.vsphere.common import sample_cli
|
|
|
|
from samples.vsphere.common import sample_util
|
2018-03-08 16:02:07 -05:00
|
|
|
from samples.vsphere.common.ssl_helper import get_unverified_session
|
2016-10-26 19:08:23 -04:00
|
|
|
|
|
|
|
|
2017-08-18 02:09:38 -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())
|
2018-03-08 16:02:07 -05:00
|
|
|
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)
|
2017-08-18 02:09:38 -04:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
"""
|
|
|
|
List VMs present in server
|
|
|
|
"""
|
2018-03-08 16:02:07 -05:00
|
|
|
list_of_vms = self.client.vcenter.VM.list()
|
2017-08-18 02:09:38 -04:00
|
|
|
print("----------------------------")
|
|
|
|
print("List Of VMs")
|
|
|
|
print("----------------------------")
|
|
|
|
pprint(list_of_vms)
|
|
|
|
print("----------------------------")
|
2016-10-26 19:08:23 -04:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2017-08-18 02:09:38 -04:00
|
|
|
list_vm = ListVM()
|
|
|
|
list_vm.run()
|
2016-10-26 19:08:23 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|