Skip to content

Commit bdda4be

Browse files
authored
Merge pull request #28 from tianhao64/master
update sample template and doc
2 parents 2d232fd + 1e090f2 commit bdda4be

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,14 @@ The API documentation can be found [here](doc/client.zip)
143143

144144
Before you start working with this project, please read our [Developer Certificate of Origin](https://cla.vmware.com/dco). All contributions to this repository must be signed as described on that page. Your signature certifies that you wrote the patch or have the right to pass it on as an open-source patch.
145145

146+
### Sample Template
147+
[Sample template](sample_template) contains boilerplate code that can be used to build a new sample.
148+
Please copy the file and use it as a starting point to write a new sample.
149+
146150
### Required Information
147151
The following information must be included in the README.md or in the sample docstring in case README already exists in same folder.
148152
* Author Name
149153
* This can include full name, email address or other identifiable piece of information that would allow interested parties to contact author with questions.
150-
* Date
151-
* Date the sample was originally written
152154
* Minimal/High Level Description
153155
* What does the sample do ?
154156
* Any KNOWN limitations or dependencies

sample_template/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Boilerplate code for new samples
2+
================================
3+
4+
sample_template.py contains boilerplate code that can be used for most of
5+
the new samples. Please fill out the TODOs with your sample information.
6+
The steps included in the template code are:
7+
8+
* Cmd line argument parser.
9+
* Login to vAPI services using vSphere Automation API.
10+
* Login to Vim service using [pyVmomi](https://github.com/vmware/pyvmomi).
11+
* Cleanup after sample execution.
12+
* Logout from both services.

sample_template/__init__.py

Whitespace-only changes.

samples/vsphere/common/sample_template.py renamed to sample_template/sample_template.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@
1313
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
1414
"""
1515

16-
__author__ = 'VMware, Inc.'
17-
__vcenter_version__ = '6.5+'
16+
__author__ = 'TODO: <your name and email>'
17+
__vcenter_version__ = 'TODO: <compatible vcenter versions>'
18+
19+
import atexit
1820

1921
from com.vmware.vcenter_client import VM
2022
from samples.vsphere.common.sample_util import parse_cli_args
21-
from samples.vsphere.common.service_manager_factory import ServiceManagerFactory
23+
from samples.vsphere.common.service_manager import ServiceManager
2224

2325

2426
class Sample:
2527
"""
26-
Demonstrates getting list of VMs present in vCenter
28+
TODO: Sample description and prerequisites.
29+
e.g. Demonstrates getting list of VMs present in vCenter
2730
2831
Sample Prerequisites:
2932
- vCenter
@@ -41,11 +44,12 @@ def setup(self):
4144
self.cleardata = cleardata
4245

4346
# Connect to both Vim and vAPI services
44-
service_manager = ServiceManagerFactory.get_service_manager(
45-
server,
46-
username,
47-
password,
48-
skip_verification)
47+
service_manager = ServiceManager(server,
48+
username,
49+
password,
50+
skip_verification)
51+
service_manager.connect()
52+
atexit.register(service_manager.disconnect)
4953

5054
# Get the vAPI stub
5155
self.stub_config = service_manager.stub_config
@@ -55,14 +59,19 @@ def setup(self):
5559
self.si = service_manager.si
5660

5761
def run(self):
62+
# TODO add steps to demo your API
63+
64+
# Using vAPI services
5865
vms = self.vm_service.list()
5966
print(vms)
6067

68+
# Using vim services
6169
current_time = self.si.CurrentTime()
6270
print(current_time)
6371

6472
def cleanup(self):
6573
if self.cleardata:
74+
# TODO add cleanup code
6675
pass
6776

6877

0 commit comments

Comments
 (0)