1
0
mirror of https://github.com/vmware/vsphere-automation-sdk-python.git synced 2024-11-25 02:39:59 -05:00

update sample template and doc

Signed-off-by: Tianhao He <tianhao64@users.noreply.github.com>
This commit is contained in:
Tianhao He 2017-08-06 23:45:22 -07:00
parent 2d232fd3a2
commit 1e090f252f
4 changed files with 34 additions and 11 deletions

View File

@ -143,12 +143,14 @@ The API documentation can be found [here](doc/client.zip)
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.
### Sample Template
[Sample template](sample_template) contains boilerplate code that can be used to build a new sample.
Please copy the file and use it as a starting point to write a new sample.
### Required Information
The following information must be included in the README.md or in the sample docstring in case README already exists in same folder.
* Author Name
* This can include full name, email address or other identifiable piece of information that would allow interested parties to contact author with questions.
* Date
* Date the sample was originally written
* Minimal/High Level Description
* What does the sample do ?
* Any KNOWN limitations or dependencies

12
sample_template/README.md Normal file
View File

@ -0,0 +1,12 @@
Boilerplate code for new samples
================================
sample_template.py contains boilerplate code that can be used for most of
the new samples. Please fill out the TODOs with your sample information.
The steps included in the template code are:
* Cmd line argument parser.
* Login to vAPI services using vSphere Automation API.
* Login to Vim service using [pyVmomi](https://github.com/vmware/pyvmomi).
* Cleanup after sample execution.
* Logout from both services.

View File

View File

@ -13,17 +13,20 @@
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
"""
__author__ = 'VMware, Inc.'
__vcenter_version__ = '6.5+'
__author__ = 'TODO: <your name and email>'
__vcenter_version__ = 'TODO: <compatible vcenter versions>'
import atexit
from com.vmware.vcenter_client import VM
from samples.vsphere.common.sample_util import parse_cli_args
from samples.vsphere.common.service_manager_factory import ServiceManagerFactory
from samples.vsphere.common.service_manager import ServiceManager
class Sample:
"""
Demonstrates getting list of VMs present in vCenter
TODO: Sample description and prerequisites.
e.g. Demonstrates getting list of VMs present in vCenter
Sample Prerequisites:
- vCenter
@ -41,11 +44,12 @@ class Sample:
self.cleardata = cleardata
# Connect to both Vim and vAPI services
service_manager = ServiceManagerFactory.get_service_manager(
server,
service_manager = ServiceManager(server,
username,
password,
skip_verification)
service_manager.connect()
atexit.register(service_manager.disconnect)
# Get the vAPI stub
self.stub_config = service_manager.stub_config
@ -55,14 +59,19 @@ class Sample:
self.si = service_manager.si
def run(self):
# TODO add steps to demo your API
# Using vAPI services
vms = self.vm_service.list()
print(vms)
# Using vim services
current_time = self.si.CurrentTime()
print(current_time)
def cleanup(self):
if self.cleardata:
# TODO add cleanup code
pass