2017-02-01 00:48:28 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
|
|
|
* *******************************************************
|
|
|
|
* Copyright (c) VMware, Inc. 2016. All Rights Reserved.
|
|
|
|
* *******************************************************
|
|
|
|
*
|
|
|
|
* 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-02-06 06:36:00 -05:00
|
|
|
import atexit
|
2017-02-01 00:48:28 -05:00
|
|
|
from samples.vsphere.common import vapiconnect
|
2017-02-02 03:50:31 -05:00
|
|
|
from samples.vsphere.common.sample_util import parse_cli_args
|
2017-02-01 00:48:28 -05:00
|
|
|
from samples.vsphere.common.sample_util import pp
|
2017-02-02 03:50:31 -05:00
|
|
|
from com.vmware.vcenter_client import VM
|
2017-02-01 00:48:28 -05:00
|
|
|
|
|
|
|
"""
|
|
|
|
Demonstrates getting list of VMs present in vCenter
|
|
|
|
Sample Prerequisites:
|
|
|
|
vCenter/ESX
|
|
|
|
"""
|
|
|
|
|
|
|
|
stub_config = None
|
2017-02-02 03:50:31 -05:00
|
|
|
cleardata = False
|
2017-02-01 00:48:28 -05:00
|
|
|
|
|
|
|
def setup(context=None):
|
2017-02-02 03:50:31 -05:00
|
|
|
global stub_config, cleardata
|
|
|
|
server, username, password, cleardata, skip_verification = \
|
|
|
|
parse_cli_args()
|
|
|
|
stub_config = vapiconnect.connect(server,
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
skip_verification)
|
2017-02-06 06:36:00 -05:00
|
|
|
atexit.register(vapiconnect.logout, stub_config)
|
2017-02-01 00:48:28 -05:00
|
|
|
|
|
|
|
|
|
|
|
def run():
|
2017-02-20 03:28:13 -05:00
|
|
|
"""
|
|
|
|
List VMs present in server
|
|
|
|
"""
|
|
|
|
vm_svc = VM(stub_config)
|
|
|
|
list_of_vms = vm_svc.list()
|
|
|
|
print ("----------------------------")
|
|
|
|
print ("List Of VMs")
|
|
|
|
print ("----------------------------")
|
|
|
|
for vm in list_of_vms:
|
|
|
|
print ('{}'.format(vm))
|
|
|
|
print ("----------------------------")
|
2017-02-06 06:36:00 -05:00
|
|
|
|
2017-02-01 00:48:28 -05:00
|
|
|
|
|
|
|
def main():
|
2017-02-20 03:28:13 -05:00
|
|
|
setup()
|
|
|
|
run()
|
2017-02-01 00:48:28 -05:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|