mirror of
https://github.com/vmware/vsphere-automation-sdk-python.git
synced 2024-11-22 01:39:58 -05:00
Merge pull request #28 from tianhao64/master
update sample template and doc
This commit is contained in:
commit
bdda4be0dd
@ -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.
|
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
|
### 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.
|
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
|
* 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.
|
* 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
|
* Minimal/High Level Description
|
||||||
* What does the sample do ?
|
* What does the sample do ?
|
||||||
* Any KNOWN limitations or dependencies
|
* Any KNOWN limitations or dependencies
|
||||||
|
12
sample_template/README.md
Normal file
12
sample_template/README.md
Normal 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.
|
0
sample_template/__init__.py
Normal file
0
sample_template/__init__.py
Normal file
@ -13,17 +13,20 @@
|
|||||||
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
|
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__author__ = 'VMware, Inc.'
|
__author__ = 'TODO: <your name and email>'
|
||||||
__vcenter_version__ = '6.5+'
|
__vcenter_version__ = 'TODO: <compatible vcenter versions>'
|
||||||
|
|
||||||
|
import atexit
|
||||||
|
|
||||||
from com.vmware.vcenter_client import VM
|
from com.vmware.vcenter_client import VM
|
||||||
from samples.vsphere.common.sample_util import parse_cli_args
|
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:
|
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:
|
Sample Prerequisites:
|
||||||
- vCenter
|
- vCenter
|
||||||
@ -41,11 +44,12 @@ class Sample:
|
|||||||
self.cleardata = cleardata
|
self.cleardata = cleardata
|
||||||
|
|
||||||
# Connect to both Vim and vAPI services
|
# Connect to both Vim and vAPI services
|
||||||
service_manager = ServiceManagerFactory.get_service_manager(
|
service_manager = ServiceManager(server,
|
||||||
server,
|
username,
|
||||||
username,
|
password,
|
||||||
password,
|
skip_verification)
|
||||||
skip_verification)
|
service_manager.connect()
|
||||||
|
atexit.register(service_manager.disconnect)
|
||||||
|
|
||||||
# Get the vAPI stub
|
# Get the vAPI stub
|
||||||
self.stub_config = service_manager.stub_config
|
self.stub_config = service_manager.stub_config
|
||||||
@ -55,14 +59,19 @@ class Sample:
|
|||||||
self.si = service_manager.si
|
self.si = service_manager.si
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
# TODO add steps to demo your API
|
||||||
|
|
||||||
|
# Using vAPI services
|
||||||
vms = self.vm_service.list()
|
vms = self.vm_service.list()
|
||||||
print(vms)
|
print(vms)
|
||||||
|
|
||||||
|
# Using vim services
|
||||||
current_time = self.si.CurrentTime()
|
current_time = self.si.CurrentTime()
|
||||||
print(current_time)
|
print(current_time)
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
if self.cleardata:
|
if self.cleardata:
|
||||||
|
# TODO add cleanup code
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user