Skip to content

Commit 44a785b

Browse files
authored
Add sample template file (#24)
Signed-off-by: Tianhao He <[email protected]>
1 parent 2415e4e commit 44a785b

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
* *******************************************************
5+
* Copyright (c) VMware, Inc. 2017. All Rights Reserved.
6+
* SPDX-License-Identifier: MIT
7+
* *******************************************************
8+
*
9+
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10+
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11+
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12+
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13+
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14+
"""
15+
16+
__author__ = 'VMware, Inc.'
17+
__vcenter_version__ = '6.5+'
18+
19+
import atexit
20+
21+
from com.vmware.vcenter_client import VM
22+
from samples.vsphere.common import vapiconnect
23+
from samples.vsphere.common.sample_util import parse_cli_args
24+
25+
26+
class Sample:
27+
"""
28+
Demonstrates getting list of VMs present in vCenter
29+
30+
Sample Prerequisites:
31+
- vCenter
32+
"""
33+
34+
def __init__(self):
35+
self.vm_service = None # Service used by the sample code.
36+
self.cleardata = None
37+
38+
def setup(self):
39+
server, username, password, cleardata, skip_verification = \
40+
parse_cli_args()
41+
stub_config = vapiconnect.connect(server, username, password,
42+
skip_verification)
43+
self.vm_service = VM(stub_config)
44+
self.cleardata = cleardata
45+
atexit.register(vapiconnect.logout, stub_config)
46+
47+
def run(self):
48+
vms = self.vm_service.list()
49+
print(vms)
50+
51+
def cleanup(self):
52+
if self.cleardata:
53+
pass
54+
55+
56+
def main():
57+
sample = Sample()
58+
sample.setup()
59+
sample.run()
60+
sample.cleanup()
61+
62+
63+
# Start program
64+
if __name__ == '__main__':
65+
main()

0 commit comments

Comments
 (0)