diff --git a/README.md b/README.md index bd77c8f3..4a48b091 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/sample_template/README.md b/sample_template/README.md new file mode 100644 index 00000000..cd96a9c7 --- /dev/null +++ b/sample_template/README.md @@ -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. \ No newline at end of file diff --git a/sample_template/__init__.py b/sample_template/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/samples/vsphere/common/sample_template.py b/sample_template/sample_template.py similarity index 69% rename from samples/vsphere/common/sample_template.py rename to sample_template/sample_template.py index b8e4920d..7b6b0b7f 100644 --- a/samples/vsphere/common/sample_template.py +++ b/sample_template/sample_template.py @@ -13,17 +13,20 @@ * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. """ -__author__ = 'VMware, Inc.' -__vcenter_version__ = '6.5+' +__author__ = 'TODO: ' +__vcenter_version__ = 'TODO: ' + +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, - username, - password, - skip_verification) + 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