Skip to content

Commit fb7b0f5

Browse files
author
Tianhao He
committed
Initial sample drop
1 parent ba97ea9 commit fb7b0f5

File tree

124 files changed

+12255
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+12255
-2
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.py[cod]
2+
__pycache__/
3+
.DS_Store
4+
.idea/*

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: python
2+
python:
3+
- "2.7.13"
4+
- "3.6"
5+
# command to install dependencies
6+
install:
7+
- pip install -r requirements.txt
8+
- pip install -r test-requirements.txt
9+
- pip install pycodestyle
10+
# command to run tests
11+
script: pycodestyle samples/*

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License
2+
3+
Copyright 2017 VMware Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 193 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,193 @@
1-
# vsphere-automation-sdk-python-samples
2-
Python Samples for the vSphere Automation SDK
1+
# VMware vSphere Automation SDK for Python
2+
[![Build Status](https://travis-ci.com/tianhao64/vsphere-automation-sdk-python-samples.svg?token=v9mEJjcpDiQ9DrYbzyaQ&branch=master)](https://travis-ci.com/tianhao64/vsphere-automation-sdk-python-samples)
3+
## Table of Contents
4+
- [Abstract](#abstract)
5+
- [Quick Start Guide](#quick-start-guide)
6+
- [Installing the required Python Packages](#installing-the-required-python-packages)
7+
- [Setting up a vSphere Test Environment](#setting-up-a-vsphere-test-environment)
8+
- [Running the SDK Sample Setup Script](#running-the-sdk-sample-setup-script)
9+
- [Running a complex sample](#running-a-complex-sample)
10+
- [API Documentation](#api-documentation)
11+
- [Submitting samples](#submitting-samples)
12+
- [Required Information](#required-information)
13+
- [Suggested Information](#suggested-information)
14+
- [Contribution Process](#contribution-process)
15+
- [Code Style](#code-style)
16+
- [Resource Maintenance](#resource-maintenance)
17+
- [Maintenance Ownership](#maintenance-ownership)
18+
- [Filing Issues](#filing-issues)
19+
- [Resolving Issues](#resolving-issues)
20+
- [VMware Sample Exchange](#vmware-sample-exchange)
21+
- [Repository Administrator Resources](#repository-administrator-resources)
22+
- [Board Members](#board-members)
23+
- [Approval of Additions](#approval-of-additions)
24+
25+
## Abstract
26+
This document describes the vSphere Automation Python SDK samples that use the vSphere Automation
27+
python client library. Additionally, some of the samples demonstrate the combined use of the
28+
vSphere Automation and vSphere APIs. To support this combined use, the vSphere Automation Python SDK
29+
samples require the vSphere Management SDK packages (pyVmomi) to be installed on the client.
30+
The samples have been developed to work with python 2.7.x and 3.3+
31+
32+
## Supported vCenter Releases:
33+
vCenter 6.0 and 6.5.
34+
Certain APIs and samples that are introduced in 6.5 release, such as vCenter, Virtual Machine and Appliance Management. Please refer to the notes in each sample for detailed compatibility information.
35+
36+
## Quick Start Guide
37+
This document will walk you through getting up and running with the Python SDK Samples.
38+
Prior to running the samples you will need to setup a vCenter test environment and
39+
install local Python packages, the following steps will take you through this process.
40+
41+
Before you can run the SDK samples we'll need to walk you through the following steps:
42+
43+
1. Installing the required Python packages
44+
2. Installing SDK provided packages
45+
3. Setting up a vSphere test environment
46+
4. Running SDK Samples setup script
47+
48+
### Installing the required Python Packages
49+
**Note:** The SDK requires Python v2.7+ (preferably v3.6) to run the setup/samples,
50+
please make sure you have the appropriate version installed before continuing.
51+
If you are on macOS/OSX/Linux, please note that the system installed version of
52+
Python may be outdated and/or not be intended for development and we recommended you [install Python](http://docs.python-guide.org/en/latest/starting/installation/) yourself before installing the required packages. [Virtualenv](https://virtualenv.pypa.io/en/stable/) is also highly recommended.
53+
54+
The required packages are listed in the requirements.txt file and installed using "pip install"; For more details on how to install python packages using pip please refer to the [pip user guide](http://pip.readthedocs.io/en/latest/user_guide/).
55+
56+
```cmd
57+
pip install -r requirements.txt
58+
```
59+
60+
### Setting up a vSphere Test Environment
61+
**NOTE:** The samples are intended to be run against a freshly installed **non-Production** vSphere setup as the scripts may make changes to the test environment and in some cases can destroy items when needed.
62+
63+
To run the samples a vSphere test environment is required with the following configuration
64+
* 1 vCenter Server
65+
* 2 ESX hosts
66+
* 1 NFS Datastore with at least 3GB of free capacity
67+
68+
Please have the details of these available but do not have any configuration pre-created on vCenter server or ESXi Hosts, for example there should be no existing datacenters, clusters or attached hosts on the vCenter server.
69+
70+
### Running the SDK Sample Setup Script
71+
Before executing the samples we'll need to setup the vSphere test environment using one of the sample scripts. Before we run the script we'll need to edit one of the files and provide IP addresses for the various machine instances.
72+
73+
First, from the command line change to the SDK ./bin folder.
74+
75+
```cmd
76+
$ cd /path/to/vsphere-automation-sdk-python-samples/bin
77+
```
78+
79+
Next, using a text editor open ../samples/vsphere/vcenter/setup/testbed.py and edit the following settings replace everything in < > brackets with your environment information. Leave the rest of the settings in this file at their default values.
80+
81+
```python
82+
config["SERVER"] = "<vcenter_hostname_or_ip>"
83+
config["USERNAME"] = "<vsphere_username>"
84+
config["PASSWORD"] = "<vsphere_password>"
85+
86+
config["ESX_HOST1"] = "<ESX_host1_ipaddress>"
87+
config["ESX_HOST2"] = "<ESX_host2_ipaddress>"
88+
config["ESX_USER"] = "<esx_username>"
89+
config["ESX_PASS"] = "<esx_password>"
90+
91+
config["USE_NFS"] = True
92+
config["NFS_HOST"] = "<nfs_ipaddress>"
93+
config["NFS_REMOTE_PATH"] = "/store1"
94+
```
95+
96+
Save and close the file.
97+
98+
At this point, we're ready to run the setup script.
99+
100+
This script will perform the following:
101+
* Create 2 test Datacenters
102+
* Create a test Cluster
103+
* Create Test Folders for VM Storage
104+
* Attach the hosts
105+
* Create a Distributed Switch
106+
* Create a Distributed Portgroup
107+
* Attach the NFS datastore (if Selected) to the hosts
108+
* Copy the [Photon OS](https://vmware.github.io/photon/) ISO image downloaded from [VMware's bintray server](https://dl.bintray.com/vmware/photon) to the datastore
109+
* Create directories to add sample ports
110+
111+
112+
**Note:** The setup script may take several minutes to complete.
113+
114+
**To view the available command-line options:**
115+
116+
```cmd
117+
$ ./run_sample.sh ../samples/vsphere/vcenter/setup/main.py -h
118+
```
119+
120+
**To run the setup script:**
121+
122+
```cmd
123+
$ ./run_sample.sh ../samples/vsphere/vcenter/setup/main.py -sv
124+
```
125+
126+
After completion you will see from the output and also the vSphere Webclient that the environment has now been fully setup and is ready to easily run further samples.
127+
128+
### Running a complex sample
129+
This SDK includes a sample script which can be used to perform a number of actions and give you an indication of how to perform multiple vCenter actions, this script is located in the /samples/vsphere/vcenter/setup/ directory, use the following instructions to run this sample:
130+
131+
**Run the vAPI vCenter sample suite:**
132+
133+
```cmd
134+
$ ./run_sample.sh ../samples/vsphere/vcenter/setup/main.py -riv
135+
```
136+
137+
## API Documentation
138+
The API documentation can be found [here] (doc/client.zip)
139+
140+
## Submitting samples
141+
### Required Information
142+
The following information must be included in the README.md or in the sample docstring in case README already exists in same folder.
143+
* Author Name
144+
* This can include full name, email address or other identifiable piece of information that would allow interested parties to contact author with questions.
145+
* Date
146+
* Date the sample was originally written
147+
* Minimal/High Level Description
148+
* What does the sample do ?
149+
* Any KNOWN limitations or dependencies
150+
151+
### Suggested Information
152+
The following information should be included when possible. Inclusion of information provides valuable information to consumers of the resource.
153+
* vSphere version against which the sample was developed/tested
154+
* SDK version against which the sample was developed/tested
155+
* Python version against which the sample was developed/tested
156+
157+
### Contribution Process
158+
159+
* Follow the [GitHub process](https://help.github.com/articles/fork-a-repo)
160+
* Please use one branch per sample or change-set
161+
* Please use one commit and pull request per sample
162+
* Please post the sample output along with the pull request
163+
* If you include a license with your sample, use the project license
164+
165+
### Code Style
166+
167+
Please conform to pep8 standards. Check your code by running the pep8 tool.
168+
https://pypi.python.org/pypi/pep8
169+
170+
## Resource Maintenance
171+
### Maintenance Ownership
172+
Ownership of any and all submitted samples are maintained by the submitter.
173+
### Filing Issues
174+
Any bugs or other issues should be filed within GitHub by way of the repository’s Issue Tracker.
175+
### Resolving Issues
176+
Any community member can resolve issues within the repository, however only the board member can approve the update. Once approved, assuming the resolution involves a pull request, only a board member will be able to merge and close the request.
177+
178+
### VMware Sample Exchange
179+
It is highly recommended to add any and all submitted samples to the VMware Sample Exchange: <https://code.vmware.com/samples>
180+
181+
Sample Exchange can be allowed to access your GitHub resources, by way of a linking process, where they can be indexed and searched by the community. There are VMware social media accounts which will advertise resources posted to the site and there's no additional accounts needed, as the VMware Sample Exchange uses MyVMware credentials.
182+
183+
## Repository Administrator Resources
184+
### Board Members
185+
186+
Board members are volunteers from the SDK community and VMware staff members, board members are not held responsible for any issues which may occur from running of samples from this repository.
187+
188+
Members:
189+
* Tianhao He (VMware)
190+
* Steve Trefethen (VMware)
191+
192+
### Approval of Additions
193+
Items added to the repository, including items from the Board members, require 2 votes from the board members before being added to the repository. The approving members will have ideally downloaded and tested the item. When two “Approved for Merge” comments are added from board members, the pull can then be committed to the repository.

bin/run_sample.bat

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@echo off
2+
setlocal ENABLEDELAYEDEXPANSION
3+
:: Clear the command-prompt screen
4+
cls
5+
set SRCDIR=%cd%\..\
6+
set LIBDIR=%cd%\..\lib
7+
set PYTHONPATH=%PYTHONPATH%;%SRCDIR%
8+
setlocal DisableDelayedExpansion
9+
:: Run the sample
10+
python %*
11+
endlocal

bin/run_sample.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
SCRIPTDIR=`dirname $0`
3+
cd $SCRIPTDIR
4+
PATHDIR=`pwd`
5+
PROJECT_ROOT=$PATHDIR/..
6+
SRCDIR=$PROJECT_ROOT/
7+
LIBDIR=$PROJECT_ROOT/lib
8+
9+
# add the src directory to the python path
10+
export PYTHONPATH=$PYTHONPATH:$SRCDIR
11+
12+
# run the sample
13+
python $@

doc/client.zip

580 KB
Binary file not shown.

lib/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SDK libraries
2+
3+
For python developers, client libraries are supplied for testing and development purposes. All the supplied libraries are located under lib directory.
4+
5+
Name | Description
6+
------------------------------------| -------------
7+
vapi_runtime-\<version>.zip | vAPI runtime responsible for serialization/de-serialization of objects and wire protocol
8+
vapi_common_client-\<version>.zip | vAPI common client code
9+
vapi_client_bindings-\<version>.zip | client stubs for vSphere Automation APIs

lib/vapi_client_bindings-2.5.0.zip

200 KB
Binary file not shown.

lib/vapi_common_client-2.5.0.zip

72.7 KB
Binary file not shown.

lib/vapi_runtime-2.5.0.zip

238 KB
Binary file not shown.

requirements.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pyOpenSSL >= 0.14
2+
pyVmomi >= 6.5
3+
lxml
4+
suds ; python_version < '3'
5+
suds-jurko ; python_version >= '3.0'
6+
lib/vapi_runtime-2.5.0.zip
7+
lib/vapi_common_client-2.5.0.zip
8+
lib/vapi_client_bindings-2.5.0.zip

samples/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
* *******************************************************
3+
* Copyright VMware, Inc. 2016. All Rights Reserved.
4+
* *******************************************************
5+
*
6+
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
7+
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
8+
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
9+
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
10+
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
11+
"""
12+
13+
__author__ = 'VMware, Inc.'
14+
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
15+
16+
17+
# Required to distribute different parts of this
18+
# package as multiple distribution
19+
try:
20+
import pkg_resources
21+
pkg_resources.declare_namespace(__name__)
22+
except ImportError:
23+
from pkgutil import extend_path
24+
__path__ = extend_path(__path__, __name__) # @ReservedAssignment

samples/vsphere/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#Client Samples
2+
3+
The following table shows the sample sub-directories and their contents.
4+
5+
Directory | Description
6+
----------------| -------------
7+
common | Samples common helper classes and abstractions; This package does NOT contain any sample
8+
contentlibrary | Samples for Content Library APIs
9+
tagging | Samples for Tagging APIs
10+
vcenter | Samples for managing vSphere infrastructure and virtual machines
11+
sso | Samples for Platform Service Controller(PSC), SSO and Lookup Service APIs

samples/vsphere/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
* *******************************************************
3+
* Copyright VMware, Inc. 2016. All Rights Reserved.
4+
* *******************************************************
5+
*
6+
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
7+
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
8+
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
9+
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
10+
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
11+
"""
12+
13+
__author__ = 'VMware, Inc.'
14+
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
15+
16+
17+
# Required to distribute different parts of this
18+
# package as multiple distribution
19+
try:
20+
import pkg_resources
21+
pkg_resources.declare_namespace(__name__)
22+
except ImportError:
23+
from pkgutil import extend_path
24+
__path__ = extend_path(__path__, __name__) # @ReservedAssignment

samples/vsphere/common/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Required to distribute different parts of this
2+
# package as multiple distribution
3+
try:
4+
import pkg_resources
5+
6+
pkg_resources.declare_namespace(__name__)
7+
except ImportError:
8+
from pkgutil import extend_path
9+
10+
__path__ = extend_path(__path__, __name__) # @ReservedAssignment
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
* *******************************************************
3+
* Copyright (c) VMware, Inc. 2013. All Rights Reserved.
4+
* *******************************************************
5+
*
6+
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
7+
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
8+
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
9+
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
10+
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
11+
"""
12+
13+
__author__ = 'VMware, Inc.'
14+
__copyright__ = 'Copyright 2013 VMware, Inc. All rights reserved.'
15+
16+
17+
import uuid
18+
import string
19+
import random
20+
21+
22+
def generate_random_uuid():
23+
return str(uuid.uuid4())
24+
25+
26+
def rand(value):
27+
return value + generate_random_string(5)
28+
29+
30+
def generate_random_string(length):
31+
return ''.join(random.choice(string.ascii_uppercase) for _i in range(length))
32+
33+
34+
def main():
35+
print(generate_random_uuid())
36+
print(generate_random_string(5))
37+
print(rand('Simple VM-'))
38+
39+
40+
# Start program
41+
if __name__ == "__main__":
42+
main()

0 commit comments

Comments
 (0)