Skip to content

Commit c9c9855

Browse files
authored
Merge pull request #54 from tianhao64/readme
Update README.md
2 parents eda57e2 + aa6667b commit c9c9855

1 file changed

Lines changed: 133 additions & 72 deletions

File tree

README.md

Lines changed: 133 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,11 @@
55
- [Supported vCenter Releases](#supported-vcenter-releases)
66
- [VMware Cloud on AWS Support](#vmware-cloud-on-aws-support)
77
- [Quick Start Guide](#quick-start-guide)
8-
- [Installing the required Python Packages](#installing-the-required-python-packages)
9-
- [Setting up a vSphere Test Environment](#setting-up-a-vsphere-test-environment)
10-
- [Running the SDK Sample Setup Script](#running-the-sdk-sample-setup-script)
11-
- [Running a complex sample](#running-a-complex-sample)
8+
- [Run SDK Samples](#run-sdk-samples)
129
- [API Documentation](#api-documentation)
1310
- [Submitting samples](#submitting-samples)
14-
- [Required Information](#required-information)
15-
- [Suggested Information](#suggested-information)
16-
- [Contribution Process](#contribution-process)
17-
- [Code Style](#code-style)
1811
- [Resource Maintenance](#resource-maintenance)
19-
- [Maintenance Ownership](#maintenance-ownership)
20-
- [Filing Issues](#filing-issues)
21-
- [Resolving Issues](#resolving-issues)
22-
- [VMware Sample Exchange](#vmware-sample-exchange)
2312
- [Repository Administrator Resources](#repository-administrator-resources)
24-
- [Board Members](#board-members)
25-
- [Approval of Additions](#approval-of-additions)
2613
- [VMware Resources](#vmware-resources)
2714
## Abstract
2815
This document describes the vSphere Automation Python SDK samples that use the vSphere Automation
@@ -39,52 +26,100 @@ Certain APIs and samples that are introduced in 6.5 release, such as vCenter, Vi
3926
The VMware Cloud on AWS API and samples are currently available as a preview and are subject to change in the future.
4027

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

46-
Before you can run the SDK samples we'll need to walk you through the following steps:
30+
### Prepare a Python Development Environment
4731

48-
1. Installing the required Python packages
49-
2. Setting up a vSphere test environment
50-
3. Running SDK Samples setup script
32+
We recommend you to install latest [Python](http://docs.python-guide.org/en/latest/starting/installation/) and
33+
[pip](https://pypi.python.org/pypi/pip/) on your system.
5134

52-
### Installing the required Python Packages
53-
**Note:** The SDK requires Python v2.7+ (preferably v3.6) to run the setup/samples,
54-
please make sure you have the appropriate version installed before continuing.
55-
If you are on macOS/OSX/Linux, please note that the system installed version of
56-
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.
35+
A Python virtual environment is also highly recommended.
36+
* [Install a virtual env for Python 2](https://virtualenv.pypa.io/en/stable/)
37+
* [Install a virtual env for Python 3](https://docs.python.org/3/tutorial/venv.html)
5738

58-
The required packages are:
59-
60-
* pyVmomi
61-
* suds (suds-jurko for python3+)
62-
* vapi-client-bindings
63-
* vmc-client-bindings
64-
* vapi-vmc-client
65-
66-
These dependencies 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/).
39+
### Installing Required Python Packages
6740

6841
```cmd
69-
pip install --upgrade --force-reinstall -r requirements.txt --extra-index-url <file:///abs_path/to/sdk/lib/>
42+
git clone https://github.com/vmware/vsphere-automation-sdk-python.git
43+
cd vsphere-automation-sdk-python
44+
pip install --upgrade --force-reinstall -r requirements.txt --extra-index-url file:///`pwd`/lib
7045
```
7146

7247
**NOTE:** The SDK also requires OpenSSL 1.0.1+ if you want to connect to vSphere 6.5+ in order to support TLS1.1 & 1.2
7348

74-
### Setting up a vSphere Test Environment
75-
**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.
49+
### Connect to a vCenter Server
7650

77-
To run the samples a vSphere test environment is required with the following configuration
78-
* 1 vCenter Server
79-
* 2 ESX hosts
80-
* 1 NFS Datastore with at least 3GB of free capacity
51+
```python
52+
import requests
53+
import urllib3
54+
from vmware.vapi.vsphere.client import create_vsphere_client
55+
session = requests.session()
56+
57+
# Disable cert verification for demo purpose.
58+
# This is not recommended in a production environment.
59+
session.verify = False
60+
61+
# Disable the secure connection warning for demo purpose.
62+
# This is not recommended in a production environment.
63+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
64+
65+
# Connect to a vCenter Server using username and password
66+
vsphere_client = create_vsphere_client(server='<vc_ip>', username='<vc_username>', password='<vc_password>', session=session)
67+
68+
# List all VMs inside the vCenter Server
69+
vsphere_client.vcenter.VM.list()
70+
```
71+
72+
Output in a Python Interpreter:
73+
74+
```shell
75+
(venv) het-m03:vsphere-automation-sdk-python het$ python
76+
Python 3.6.3 (v3.6.3:2c5fed86e0, Oct 3 2017, 00:32:08)
77+
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
78+
Type "help", "copyright", "credits" or "license" for more information.
79+
>>> import requests
80+
>>> import urllib3
81+
>>> from vmware.vapi.vsphere.client import create_vsphere_client
82+
>>> session = requests.session()
83+
>>> session.verify = False
84+
>>> urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
85+
>>> vsphere_client = create_vsphere_client(server='<vc_ip>', username='<vc_username>', password='<vc_password>', session=session)
86+
>>> vsphere_client.vcenter.VM.list()
87+
[Summary(vm='vm-58', name='standalone-20e4bd3af-esx.0-vm.0', power_state=State(string='POWERED_OFF'), cpu_count=1, memory_size_mib=256),
88+
...]
89+
```
90+
91+
### Connect to VMware Cloud on AWS
92+
93+
```python
94+
from vmware.vapi.vmc.client import create_vmc_client
95+
96+
# Connect to VMware Cloud on AWS using refresh token
97+
vmc_client = create_vmc_client('<refresh_token>')
8198

82-
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.
99+
# Get organizations associated with calling user.
100+
vmc_client.Orgs.list()
101+
```
102+
103+
Output in a Python Interpreter:
104+
105+
```shell
106+
(venv) het-m03:vsphere-automation-sdk-python het$ python
107+
Python 3.6.3 (v3.6.3:2c5fed86e0, Oct 3 2017, 00:32:08)
108+
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
109+
Type "help", "copyright", "credits" or "license" for more information.
110+
>>> from vmware.vapi.vmc.client import create_vmc_client
111+
>>> vmc_client = create_vmc_client('<refresh_token>')
112+
>>> vmc_client.Orgs.list()
113+
[Organization(updated=datetime.datetime(2018, 3, 2, 16, 57, 46), user_id='77aa6e6f-3257-3637-9cd9-14fae3a25b9d', updated_by_user_id='2021b5ae-890b-3472-ba9a-bc8cff776ca7', created=datetime.datetime(2017, 4, 4, 11, 57, 48, 861), version=15, updated_by_user_name='mdreyer@vmware.com', user_name='pgifford@vmware.com', id='2a8ac0ba-c93d-4748-879f-7dc9918beaa5', display_name='VMC-SET', name='j13hqg73', sla='VMC_INTERNAL', project_state='CREATED', properties=OrgProperties(values={'defaultAwsRegions': 'US_WEST_2,US_EAST_1', 'sddcLimit': '5', 'planVersion': '3.0', 'defaultHostsPerSddc': '4', 'invitationCode': '/csp/gateway/slc/api/service-invitations/aa7203c3617bbe755597b8b0ad652', 'enableAWSCloudProvider': 'true', 'enableZeroCloudCloudProvider': 'true', 'accountLinkingOptional': 'false', 'defaultPDXDatacenter': 'pdx2', 'skipSubscriptionCheck': 'true', 'minHostsPerSddc': '4', 'maxHostsPerSddc': '8', 'hostLimit': '16', 'maxHostsPerSddcOnCreate': '4', 'isAllAccess': 'true', 'enabledAvailabilityZones': '{"us-east-1":["iad6","iad7","iad12"],"us-west-2":["pdx1", "pdx4", "pdx2"]}'}), cloud_configurations={'AWS': AwsOrgConfiguration(provider='AWS')})
114+
...]
115+
```
83116

84-
### Running the SDK Sample Setup Script
85-
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.
117+
## Run SDK Samples
86118

87-
First, set PYTHONPATH to use SDK helper methods
119+
In this section we will walk you through the steps to run the sample code for vSphere
120+
and VMware Cloud on AWS APIs.
121+
122+
### First, set PYTHONPATH to use SDK helper methods
88123

89124
* Linux/Mac:
90125

@@ -94,28 +129,25 @@ First, set PYTHONPATH to use SDK helper methods
94129

95130
set PYTHONPATH=%cd%;%PYTHONPATH%
96131

97-
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.
132+
### Run VMware Cloud on AWS Samples
98133

99-
```python
100-
config["SERVER"] = "<vcenter_hostname_or_ip>"
101-
config["USERNAME"] = "<vsphere_username>"
102-
config["PASSWORD"] = "<vsphere_password>"
134+
```cmd
135+
$ python samples/vmc/orgs/organization_operations.py -r <refresh_token>
136+
```
103137

104-
config["ESX_HOST1"] = "<ESX_host1_ipaddress>"
105-
config["ESX_HOST2"] = "<ESX_host2_ipaddress>"
106-
config["ESX_USER"] = "<esx_username>"
107-
config["ESX_PASS"] = "<esx_password>"
138+
### Run vSphere Samples
108139

109-
config["USE_NFS"] = True
110-
config["NFS_HOST"] = "<nfs_ipaddress>"
111-
config["NFS_REMOTE_PATH"] = "/store1"
112-
```
140+
A vSphere test environment is required with the following configuration:
141+
* 1 vCenter Server
142+
* 2 ESX hosts
143+
* 1 NFS Datastore with at least 3GB of free capacity
144+
145+
**Note** 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.
113146

114-
Save and close the file.
147+
#### Running the SDK Sample Setup Script
115148

116-
At this point, we're ready to run the setup script.
149+
Before executing the samples we'll need to setup the vSphere test environment using one of the sample scripts (samples/vsphere/vcenter/setup/main.py). The script will perform the following:
117150

118-
This script will perform the following:
119151
* Create 2 test Datacenters
120152
* Create a test Cluster
121153
* Create Test Folders for VM Storage
@@ -126,33 +158,51 @@ This script will perform the following:
126158
* 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
127159
* Create directories to add sample ports
128160

161+
First, edit settings in samples/vsphere/vcenter/setup/testbed.py and replace everything in < > brackets with your environment information. Leave the rest of the settings in this file at their default values.
129162

130-
**Note:** The setup script may take several minutes to complete.
163+
```python
164+
config["SERVER"] = "<vcenter_hostname_or_ip>"
165+
config["USERNAME"] = "<vsphere_username>"
166+
config["PASSWORD"] = "<vsphere_password>"
167+
168+
config["ESX_HOST1"] = "<ESX_host1_ipaddress>"
169+
config["ESX_HOST2"] = "<ESX_host2_ipaddress>"
170+
config["ESX_USER"] = "<esx_username>"
171+
config["ESX_PASS"] = "<esx_password>"
172+
173+
config["USE_NFS"] = True
174+
config["NFS_HOST"] = "<nfs_ipaddress>"
175+
config["NFS_REMOTE_PATH"] = "/store1"
176+
```
131177

132-
**To view the available command-line options:**
178+
At this point, we're ready to run the setup script:
133179

134180
```cmd
135-
$ python ../samples/vsphere/vcenter/setup/main.py -h
181+
$ python samples/vsphere/vcenter/setup/main.py -sv
136182
```
137183

138-
**To run the setup script:**
184+
After completion you will see from the output and also the vSphere Client that the environment has now been fully setup and is ready to easily run further samples.
185+
186+
To view other available command-line options:
139187

140188
```cmd
141-
$ python ../samples/vsphere/vcenter/setup/main.py -sv
189+
$ python samples/vsphere/vcenter/setup/main.py -h
142190
```
143191

144-
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.
192+
#### Run the vAPI vCenter sample suite:
145193

146-
### Running a complex sample
147-
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:
194+
```cmd
195+
$ python samples/vsphere/vcenter/setup/main.py -riv
196+
```
148197

149-
**Run the vAPI vCenter sample suite:**
198+
#### Run a specific sample in a standalone mode:
150199

151200
```cmd
152-
$ python ../samples/vsphere/vcenter/setup/main.py -riv
201+
$ python samples/vsphere/vcenter/vm/list_vms.py -v
153202
```
154203

155204
## API Documentation
205+
156206
The API documentation can be found [here](doc/client.zip)
157207

158208
## Submitting samples
@@ -162,10 +212,12 @@ The API documentation can be found [here](doc/client.zip)
162212
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.
163213

164214
### Sample Template
215+
165216
[Sample template](sample_template) contains boilerplate code that can be used to build a new sample.
166217
Please copy the file and use it as a starting point to write a new sample.
167218

168219
### Required Information
220+
169221
The following information must be included in the README.md or in the sample docstring in case README already exists in same folder.
170222
* Author Name
171223
* This can include full name, email address or other identifiable piece of information that would allow interested parties to contact author with questions.
@@ -174,6 +226,7 @@ The following information must be included in the README.md or in the sample doc
174226
* Any KNOWN limitations or dependencies
175227

176228
### Suggested Information
229+
177230
The following information should be included when possible. Inclusion of information provides valuable information to consumers of the resource.
178231
* vSphere version against which the sample was developed/tested
179232
* SDK version against which the sample was developed/tested
@@ -194,18 +247,25 @@ Please conform to pep8 standards. Check your code by running the pep8 tool.
194247

195248
## Resource Maintenance
196249
### Maintenance Ownership
250+
197251
Ownership of any and all submitted samples are maintained by the submitter.
252+
198253
### Filing Issues
254+
199255
Any bugs or other issues should be filed within GitHub by way of the repository’s Issue Tracker.
256+
200257
### Resolving Issues
258+
201259
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.
202260

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

206265
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.
207266

208267
## Repository Administrator Resources
268+
209269
### Board Members
210270

211271
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.
@@ -215,6 +275,7 @@ Members:
215275
* Steve Trefethen (VMware)
216276

217277
### Approval of Additions
278+
218279
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.
219280

220281
## VMware Resources

0 commit comments

Comments
 (0)