Skip to content

update sample template and doc #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions sample_template/README.md
Original file line number Diff line number Diff line change
@@ -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.
Empty file added sample_template/__init__.py
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,11 +44,12 @@ def setup(self):
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
Expand All @@ -55,14 +59,19 @@ def setup(self):
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


Expand Down