Skip to content

Tianhao64 patch 1 #1

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

Closed
wants to merge 93 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
0b4d32c
Initial sample drop
Oct 26, 2016
c01cd84
Minor update to python README file
tianhao64 Oct 27, 2016
f347c93
Update README.md
tianhao64 Jan 7, 2017
9662072
Update README.md
tianhao64 Jan 17, 2017
16af3a8
Update README.md
tianhao64 Jan 17, 2017
5efbeee
remove samples/src folder
Jan 17, 2017
429ad93
remove readme html
Jan 17, 2017
0639327
add LICENSE
Jan 17, 2017
c8de1bb
remove licenses folder
Jan 17, 2017
17a6aeb
remove license folder
Jan 17, 2017
a3e6142
Create README.md
tianhao64 Jan 17, 2017
80c1c1a
Update README.md
tianhao64 Jan 17, 2017
0afd74f
Delete vSphere-Automation-Client-SDK-Python-Samples-README.html
tianhao64 Jan 17, 2017
bae355d
Update README.md
tianhao64 Jan 17, 2017
f215e84
Create README.md
tianhao64 Jan 17, 2017
59c2355
Update README.md
tianhao64 Jan 17, 2017
7e89f99
Update README.md
tianhao64 Jan 18, 2017
ed94893
Update README.md
tianhao64 Jan 18, 2017
90d24d6
Update README.md
tianhao64 Jan 18, 2017
2ee1f4c
Update README.md
tianhao64 Jan 18, 2017
928c358
Update README.md
tianhao64 Jan 18, 2017
2f71967
Update README.md
tianhao64 Jan 18, 2017
c2531ad
Update README.md
tianhao64 Jan 18, 2017
afd1b36
Update README.md
tianhao64 Jan 18, 2017
6c6d0cd
Update README.md
tianhao64 Jan 18, 2017
01d69ab
Update README.md
tianhao64 Jan 18, 2017
b16396b
Create README.md
tianhao64 Jan 18, 2017
d6e8448
Delete README.md
tianhao64 Jan 18, 2017
103368f
Update README.md
tianhao64 Jan 19, 2017
e0e94f3
Create requirements.txt
tianhao64 Jan 19, 2017
c90cb65
Update requirements.txt
tianhao64 Jan 19, 2017
7889e7c
Update README.md
tianhao64 Jan 19, 2017
e1efd8a
Update README.md
tianhao64 Jan 19, 2017
9b630f7
add .gitignore
Jan 23, 2017
2a40af9
folder change vsphere/samples -> samples/vsphere
Jan 23, 2017
3d2f044
remove logging_context, use print() instead to simplify sample output…
Jan 23, 2017
1002915
fix a couple of pep8 format warnings
Jan 23, 2017
a3ff53b
remove sample.cfg
Jan 23, 2017
fa2ab50
Delete sample.cfg
tianhao64 Jan 23, 2017
b3bea5c
Adjust the folder strucuture to match what's like in Java project.
Jan 24, 2017
edc5972
Update README.md
tianhao64 Jan 24, 2017
e9a5cd3
update script path
Jan 24, 2017
b82debc
Update README.md
tianhao64 Jan 24, 2017
4f26679
update run_sample.sh permission
Jan 24, 2017
af0f3f2
Update README.md
tianhao64 Jan 24, 2017
92c7943
Mis changes
Jan 24, 2017
fe9795e
update readme
Jan 24, 2017
aa5291b
Update README.md
tianhao64 Jan 24, 2017
0281721
update readme and fix a bug in print_service.py
Jan 25, 2017
afab2ab
update vcenter README
Jan 25, 2017
9f7277f
Update README.md
tianhao64 Jan 25, 2017
290ae75
Update README.md
tianhao64 Jan 25, 2017
6af52b2
Update README.md
tianhao64 Jan 25, 2017
b13f9b3
Update README.md
tianhao64 Jan 25, 2017
67ce5da
Update README.md
tianhao64 Jan 25, 2017
6f35147
Update README.md
tianhao64 Jan 25, 2017
f31f352
Update README.md
tianhao64 Jan 25, 2017
f831791
Update README.md
tianhao64 Jan 25, 2017
72a5072
update vcenter README files
Jan 25, 2017
082f7b2
remove doc folder
Jan 25, 2017
72e6895
raise exception rather than silently exit program when missing parame…
Jan 25, 2017
fb34b56
switch -t and -v in setup_cli.py
Jan 25, 2017
3890bbc
Update README.md
tianhao64 Jan 25, 2017
487ce97
Update testbed.py
tianhao64 Jan 30, 2017
510e183
Update README.md
tianhao64 Feb 3, 2017
68d4480
Update README.md
tianhao64 Feb 3, 2017
7e75730
Update README.md
tianhao64 Feb 3, 2017
35d37ce
Update README.md
tianhao64 Feb 3, 2017
2b54a33
Update deploy_ovf_template.py
tianhao64 Feb 6, 2017
d78b4ba
Update README.md
tianhao64 Feb 6, 2017
3778c38
Update README.md
tianhao64 Feb 8, 2017
78b4873
Merge pull request #2 from tianhao64/tianhao64-patch-1
tianhao64 Feb 9, 2017
45aa7b7
Update README.md
tianhao64 Feb 9, 2017
5ae9f6a
Add missing top level module dunder
Feb 10, 2017
0ffcc43
Update README.md
tianhao64 Feb 10, 2017
998db27
add supported vcenter_version to vcenter and tagging samples
Feb 10, 2017
b10443a
add supported vcenter version info to content library samples
Feb 10, 2017
b25c66e
Rewrite sso samples
Feb 16, 2017
9ef07ac
Update README.md
tianhao64 Feb 16, 2017
90b109a
remove print statements from lookup_service_helper
Feb 16, 2017
0ea5025
use default wsdl when wsdl parameter is absent
Feb 16, 2017
b3ce1a6
Update README.md
alanrenouf Feb 16, 2017
3684335
Merge pull request #3 from tianhao64/alanrenouf-patch-1
tianhao64 Feb 16, 2017
ab32e1e
Update README.md
tianhao64 Feb 16, 2017
15f9332
Update README.md
tianhao64 Feb 17, 2017
970edcf
Create .travis.yml
tianhao64 Feb 21, 2017
df1de22
Update .travis.yml
tianhao64 Feb 21, 2017
defcb7d
Update .travis.yml
tianhao64 Feb 21, 2017
6dd87e6
Update .travis.yml
tianhao64 Feb 21, 2017
09df061
Create setup.cfg
tianhao64 Feb 23, 2017
7835ae1
Update .travis.yml
tianhao64 Feb 24, 2017
e24bbb7
Update setup.cfg
tianhao64 Feb 24, 2017
81ac07e
fix format to meet pep8 requirements
Feb 24, 2017
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.py[cod]
__pycache__/
.DS_Store
.idea/*
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: python
python:
- "2.7.13"
- "3.6"
# command to install dependencies
install:
- "pip install -r requirements.txt"
- "pip install pycodestyle"
# command to run tests
script: pycodestyle samples/*
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License

Copyright 2017 VMware Inc.

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.
195 changes: 193 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,193 @@
# vsphere-automation-sdk-python-samples
Python Samples for the vSphere Automation SDK
# VMware vSphere Automation SDK for Python

## Table of Contents
- [Abstract](#abstract)
- [Quick Start Guide](#quick-start-guide)
- [Installing the required Python Packages](#installing-the-required-python-packages)
- [Setting up a vSphere Test Environment](#setting-up-a-vsphere-test-environment)
- [Running the SDK Sample Setup Script](#running-the-sdk-sample-setup-script)
- [Running a complex sample](#running-a-complex-sample)
- [API Documentation and Programming Guide](#api-documentation-and-programming-guide)
- [Submitting samples](#submitting-samples)
- [Required Information](#required-information)
- [Suggested Information](#suggested-information)
- [Contribution Process](#contribution-process)
- [Code Style](#code-style)
- [Resource Maintenance](#resource-maintenance)
- [Maintenance Ownership](#maintenance-ownership)
- [Filing Issues](#filing-issues)
- [Resolving Issues](#resolving-issues)
- [VMware Sample Exchange](#vmware-sample-exchange)
- [Repository Administrator Resources](#repository-administrator-resources)
- [Board Members](#board-members)
- [Approval of Additions](#approval-of-additions)

## Abstract
This document describes the vSphere Automation Python SDK samples that use the vSphere Automation
python client library. Additionally, some of the samples demonstrate the combined use of the
vSphere Automation and vSphere APIs. To support this combined use, the vSphere Automation Python SDK
samples require the vSphere Management SDK packages (pyVmomi) to be installed on the client.
The samples have been developed to work with python 2.7.x and 3.3+

## Supported vCenter Releases:
vCenter 6.0 and 6.5.
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.

## Quick Start Guide
This document will walk you through getting up and running with the Python SDK Samples.
Prior to running the samples you will need to setup a vCenter test environment and
install local Python packages, the following steps will take you through this process.

Before you can run the SDK samples we'll need to walk you through the following steps:

1. Installing the required Python packages
2. Installing SDK provided packages
3. Setting up a vSphere test environment
4. Running SDK Samples setup script

### Installing the required Python Packages
**Note:** The SDK requires Python v2.7+ (preferably v3.6) to run the setup/samples,
please make sure you have the appropriate version installed before continuing.
If you are on macOS/OSX/Linux, please note that the system installed version of
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.

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/).

```cmd
pip install -r requirements.txt
```

### Setting up a vSphere Test Environment
**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.

To run the samples a vSphere test environment is required with the following configuration
* 1 vCenter Server
* 2 ESX hosts
* 1 NFS Datastore with at least 3GB of free capacity

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.

### Running the SDK Sample Setup Script
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.

First, from the command line change to the SDK ./bin folder.

```cmd
$ cd /path/to/vsphere-automation-sdk-python-samples/bin
```

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.

```python
config["SERVER"] = "<vcenter_hostname_or_ip>"
config["USERNAME"] = "<vsphere_username>"
config["PASSWORD"] = "<vsphere_password>"

config["ESX_HOST1"] = "<ESX_host1_ipaddress>"
config["ESX_HOST2"] = "<ESX_host2_ipaddress>"
config["ESX_USER"] = "<esx_username>"
config["ESX_PASS"] = "<esx_password>"

config["USE_NFS"] = True
config["NFS_HOST"] = "<nfs_ipaddress>"
config["NFS_REMOTE_PATH"] = "/store1"
```

Save and close the file.

At this point, we're ready to run the setup script.

This script will perform the following:
* Create 2 test Datacenters
* Create a test Cluster
* Create Test Folders for VM Storage
* Attach the hosts
* Create a Distributed Switch
* Create a Distributed Portgroup
* Attach the NFS datastore (if Selected) to the hosts
* 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
* Create directories to add sample ports


**Note:** The setup script may take several minutes to complete.

**To view the available command-line options:**

```cmd
$ ./run_sample.sh ../samples/vsphere/vcenter/setup/main.py -h
```

**To run the setup script:**

```cmd
$ ./run_sample.sh ../samples/vsphere/vcenter/setup/main.py -sv
```

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.

### Running a complex sample
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:

**Run the vAPI vCenter sample suite:**

```cmd
$ ./run_sample.sh ../samples/vsphere/vcenter/setup/main.py -riv
```

## API Documentation
The API documentation can be found here : TODO

## Submitting samples
### 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

### Suggested Information
The following information should be included when possible. Inclusion of information provides valuable information to consumers of the resource.
* vSphere version against which the sample was developed/tested
* SDK version against which the sample was developed/tested
* Python version against which the sample was developed/tested

### Contribution Process

* Follow the [GitHub process](https://help.github.com/articles/fork-a-repo)
* Please use one branch per sample or change-set
* Please use one commit and pull request per sample
* Please post the sample output along with the pull request
* If you include a license with your sample, use the project license

### Code Style

Please conform to pep8 standards. Check your code by running the pep8 tool.
https://pypi.python.org/pypi/pep8

## Resource Maintenance
### Maintenance Ownership
Ownership of any and all submitted samples are maintained by the submitter.
### Filing Issues
Any bugs or other issues should be filed within GitHub by way of the repository’s Issue Tracker.
### Resolving Issues
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.

### VMware Sample Exchange
It is highly recommended to add any and all submitted samples to the VMware Sample Exchange: <https://code.vmware.com/samples>

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.

## Repository Administrator Resources
### Board Members

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.

Members:
* Tianhao He (VMware)
* Steve Trefethen (VMware)

### Approval of Additions
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.
11 changes: 11 additions & 0 deletions bin/run_sample.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@echo off
setlocal ENABLEDELAYEDEXPANSION
:: Clear the command-prompt screen
cls
set SRCDIR=%cd%\..\
set LIBDIR=%cd%\..\lib
set PYTHONPATH=%PYTHONPATH%;%SRCDIR%
setlocal DisableDelayedExpansion
:: Run the sample
python %*
endlocal
13 changes: 13 additions & 0 deletions bin/run_sample.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
SCRIPTDIR=`dirname $0`
cd $SCRIPTDIR
PATHDIR=`pwd`
PROJECT_ROOT=$PATHDIR/..
SRCDIR=$PROJECT_ROOT/
LIBDIR=$PROJECT_ROOT/lib

# add the src directory to the python path
export PYTHONPATH=$PYTHONPATH:$SRCDIR

# run the sample
python $@
9 changes: 9 additions & 0 deletions lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SDK libraries

For python developers, client libraries are supplied for testing and development purposes. All the supplied libraries are located under lib directory.

Name | Description
------------------------------------| -------------
vapi_runtime-\<version>.zip | vAPI runtime responsible for serialization/de-serialization of objects and wire protocol
vapi_common_client-\<version>.zip | vAPI common client code
vapi_client_bindings-\<version>.zip | client stubs for vSphere Automation APIs
Binary file added lib/vapi_client_bindings-2.5.0.zip
Binary file not shown.
Binary file added lib/vapi_common_client-2.5.0.zip
Binary file not shown.
Binary file added lib/vapi_runtime-2.5.0.zip
Binary file not shown.
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pyOpenSSL >= 0.14
pyVmomi >= 6.5
lxml
suds ; python_version < '3'
suds-jurko ; python_version >= '3.0'
lib/vapi_runtime-2.5.0.zip
lib/vapi_common_client-2.5.0.zip
lib/vapi_client_bindings-2.5.0.zip
24 changes: 24 additions & 0 deletions samples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
* *******************************************************
* Copyright VMware, Inc. 2016. All Rights Reserved.
* *******************************************************
*
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
"""

__author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'


# Required to distribute different parts of this
# package as multiple distribution
try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__) # @ReservedAssignment
11 changes: 11 additions & 0 deletions samples/vsphere/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#Client Samples

The following table shows the sample sub-directories and their contents.

Directory | Description
----------------| -------------
common | Samples common helper classes and abstractions; This package does NOT contain any sample
contentlibrary | Samples for Content Library APIs
tagging | Samples for Tagging APIs
vcenter | Samples for managing vSphere infrastructure and virtual machines
sso | Samples for Platform Service Controller(PSC), SSO and Lookup Service APIs
24 changes: 24 additions & 0 deletions samples/vsphere/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
* *******************************************************
* Copyright VMware, Inc. 2016. All Rights Reserved.
* *******************************************************
*
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
"""

__author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'


# Required to distribute different parts of this
# package as multiple distribution
try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__) # @ReservedAssignment
10 changes: 10 additions & 0 deletions samples/vsphere/common/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Required to distribute different parts of this
# package as multiple distribution
try:
import pkg_resources

pkg_resources.declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path

__path__ = extend_path(__path__, __name__) # @ReservedAssignment
42 changes: 42 additions & 0 deletions samples/vsphere/common/id_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
* *******************************************************
* Copyright (c) VMware, Inc. 2013. All Rights Reserved.
* *******************************************************
*
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
"""

__author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2013 VMware, Inc. All rights reserved.'


import uuid
import string
import random


def generate_random_uuid():
return str(uuid.uuid4())


def rand(value):
return value + generate_random_string(5)


def generate_random_string(length):
return ''.join(random.choice(string.ascii_uppercase) for _i in range(length))


def main():
print(generate_random_uuid())
print(generate_random_string(5))
print(rand('Simple VM-'))


# Start program
if __name__ == "__main__":
main()
Loading