Skip to content

Commit fd6fff9

Browse files
authored
Merge pull request #40 from tianhao64/master
Add VMware Cloud on AWS APIs
2 parents 32ce083 + 775dbef commit fd6fff9

Some content is hidden

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

44 files changed

+937
-36
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ python:
44
- "3.6"
55
# command to install dependencies
66
install:
7-
- pip install -r requirements.txt --extra-index-url file://$PWD/lib --upgrade --ignore-installed six
7+
- pip install -r requirements.txt --extra-index-url file://$PWD/lib --upgrade --ignore-installed six
88
- pip install -r test-requirements.txt
99
- pip install pycodestyle
1010
# command to run tests
11-
script: pycodestyle samples/*
11+
script: pycodestyle samples/*.py

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
[![Build Status](https://travis-ci.com/vmware/vsphere-automation-sdk-python.svg?token=v9mEJjcpDiQ9DrYbzyaQ&branch=master)](https://travis-ci.com/vmware/vsphere-automation-sdk-python)
33
## Table of Contents
44
- [Abstract](#abstract)
5+
- [Supported vCenter Releases](#supported-vcenter-releases)
6+
- [VMware Cloud on AWS Support](#vmware-cloud-on-aws-support)
57
- [Quick Start Guide](#quick-start-guide)
68
- [Installing the required Python Packages](#installing-the-required-python-packages)
79
- [Setting up a vSphere Test Environment](#setting-up-a-vsphere-test-environment)
@@ -29,10 +31,13 @@ vSphere Automation and vSphere APIs. To support this combined use, the vSphere A
2931
samples require the vSphere Management SDK packages (pyVmomi) to be installed on the client.
3032
The samples have been developed to work with python 2.7.x and 3.3+
3133

32-
## Supported vCenter Releases:
34+
## Supported vCenter Releases
3335
vCenter 6.0 and 6.5.
3436
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.
3537

38+
## VMware Cloud on AWS Support
39+
The VMware Cloud on AWS API and samples are currently available as a preview and are subject to change in the future.
40+
3641
## Quick Start Guide
3742
This document will walk you through getting up and running with the Python SDK Samples.
3843
Prior to running the samples you will need to setup a vCenter test environment and
@@ -55,11 +60,13 @@ The required packages are:
5560
* pyVmomi
5661
* suds (suds-jurko for python3+)
5762
* vapi-client-bindings
63+
* vmc-client-bindings
64+
* vapi-vmc-client
5865

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

6168
```cmd
62-
pip install -r requirements.txt --extra-index-url <file:///abs_path/to/sdk/lib/>
69+
pip install --upgrade --force-reinstall --no-cache -r requirements.txt --extra-index-url <file:///abs_path/to/sdk/lib/>
6370
```
6471

6572
**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

doc/client.zip

26.8 KB
Binary file not shown.

doc/vmc.zip

251 KB
Binary file not shown.

lib/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ For python developers, client libraries are supplied for testing and development
44

55
Name | Description
66
------------------------------------| -------------
7-
vapi_runtime | vAPI runtime responsible for serialization/de-serialization of objects and wire protocol
7+
vapi_runtime | vAPI runtime responsible for serialization/de-serialization of objects and wire protocol
8+
vapi_vmc_client | Handles VMC CSP authentication process
89
vapi_client_bindings | Client stubs for vSphere Automation APIs
10+
vmc_client_bindings | Client stubs for VMware Cloud Services APIs

lib/index.html

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
<html><head><title>Simple Index</title><meta name='api-version' value='2' /></head><body>
2-
<a href='vapi-client-bindings/'>vapi-client-bindings</a><br />
3-
<a href='vapi-runtime/'>vapi-runtime</a><br />
4-
</body></html>
1+
<html>
2+
<head><title>Simple Index</title>
3+
<meta name='api-version' value='2'/>
4+
</head>
5+
<body>
6+
<a href='vapi-client-bindings/'>vapi-client-bindings</a><br/>
7+
<a href='vmc-client-bindings/'>vmc-client-bindings</a><br/>
8+
<a href='vapi-runtime/'>vapi-runtime</a><br/>
9+
</body>
10+
</html>

lib/vapi-client-bindings/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<a href='vapi_client_bindings-2.7.0-py2.py3-none-any.whl'>vapi_client_bindings-2.7.0-py2.py3-none-any.whl</a><br />
1+
<a href='vapi_client_bindings-1.0.0-py2.py3-none-any.whl'>vapi_client_bindings-1.0.0-py2.py3-none-any.whl</a><br />
Binary file not shown.
Binary file not shown.

lib/vapi-runtime/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<a href='vapi_runtime-2.7.0-py2.py3-none-any.whl'>vapi_runtime-2.7.0-py2.py3-none-any.whl</a><br />
1+
<a href='vapi_runtime-2.7.1-py2.py3-none-any.whl'>vapi_runtime-2.7.1-py2.py3-none-any.whl</a><br />
Binary file not shown.
Binary file not shown.

lib/vapi-vmc-client/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<a href='vapi_vmc_client-2.7.1-py2.py3-none-any.whl'>vapi_vmc_client-2.7.1-py2.py3-none-any.whl</a><br />
Binary file not shown.

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.

lib/vmc-client-bindings/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<a href='vmc_client_bindings-1.0.0-py2.py3-none-any.whl'>vmc_client_bindings-1.0.0-py2.py3-none-any.whl</a><br />
Binary file not shown.

requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
pyVmomi >= 6.5
22
suds ; python_version < '3'
33
suds-jurko ; python_version >= '3.0'
4-
vapi-client-bindings
4+
tabulate
5+
vapi-client-bindings == 1.0.0
6+
vmc-client-bindings
7+
vapi-vmc-client

samples/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Directory | Description
2+
----------------| -------------
3+
vSphere | Samples for vSphere APIs
4+
vmc | Samples for VMware Cloud on AWS Services (currently in preview)

samples/vmc/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Samples for VMware Cloud on AWS APIs (currently in preview)
2+
3+
The following table shows the sample sub-directories and their contents.
4+
5+
Directory | Description
6+
----------------| -------------
7+
orgs | Samples for operations on organizations
8+
sddc | Samples for operations on SDDCs
9+
helpers | Helper methods used by VMware Cloud on AWS API samples

samples/vmc/__init__.py

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

samples/vmc/helpers/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
* *******************************************************
3+
* Copyright VMware, Inc. 2017. All Rights Reserved.
4+
* SPDX-License-Identifier: MIT
5+
* *******************************************************
6+
*
7+
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8+
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9+
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10+
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11+
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12+
"""
13+
14+
__author__ = 'VMware, Inc.'
15+
16+
# Required to distribute different parts of this
17+
# package as multiple distribution
18+
try:
19+
import pkg_resources
20+
21+
pkg_resources.declare_namespace(__name__)
22+
except ImportError:
23+
from pkgutil import extend_path
24+
25+
__path__ = extend_path(__path__, __name__) # @ReservedAssignment
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
* *******************************************************
3+
* Copyright (c) VMware, Inc. 2017. All Rights Reserved.
4+
* SPDX-License-Identifier: MIT
5+
* *******************************************************
6+
*
7+
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8+
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9+
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10+
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11+
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12+
"""
13+
14+
__author__ = 'VMware, Inc.'
15+
16+
from time import sleep
17+
from tabulate import tabulate
18+
19+
from com.vmware.vmc.model_client import Task
20+
21+
22+
def wait_for_task(task_client, org_id, task_id, interval_sec=60):
23+
"""
24+
Helper method to wait for a task to finish
25+
:param task_client: task client to query the task object
26+
:param org_id: organization id
27+
:param task_id: task id
28+
:param interval_sec: task pulling interval_sec in sec
29+
:return: True if task finished successfully, False otherwise.
30+
"""
31+
print('Wait for task {} to finish'.format(task_id))
32+
print('Checking task status every {} seconds'.format(interval_sec))
33+
34+
while True:
35+
task = task_client.get(org_id, task_id)
36+
37+
if task.status == Task.STATUS_FINISHED:
38+
print('\nTask {} finished successfully'.format(task_id))
39+
return True
40+
elif task.status == Task.STATUS_FAILED:
41+
print('\nTask {} failed'.format(task_id))
42+
return False
43+
elif task.status == Task.STATUS_CANCELED:
44+
print('\nTask {} cancelled'.format(task_id))
45+
return False
46+
else:
47+
print("Estimated time remaining: {} minutes".
48+
format(task.estimated_remaining_minutes))
49+
sleep(interval_sec)
50+
51+
52+
def list_all_tasks(task_client, org_id):
53+
"""
54+
List all tasks in a given org
55+
:param task_client: task client to query the task object
56+
:param org_id: organization id
57+
"""
58+
tasks = task_client.list(org_id)
59+
headers = ['ID', 'Status', 'Progress', 'Started', 'User']
60+
table = []
61+
for task in tasks:
62+
table.append([task.id, task.status, task.progress_percent,
63+
task.start_time, task.user_name])
64+
print(tabulate(table, headers))

samples/vmc/orgs/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This directory contains samples for VMC organization APIs:
2+
3+
Running the samples
4+
5+
$ python organization_operations.py <refresh_token>
6+
7+
* Testbed Requirement:
8+
- At least one org associated with the calling user.
9+

samples/vmc/orgs/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
* *******************************************************
3+
* Copyright VMware, Inc. 2017. All Rights Reserved.
4+
* SPDX-License-Identifier: MIT
5+
* *******************************************************
6+
*
7+
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
8+
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
9+
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
10+
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
11+
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
12+
"""
13+
14+
__author__ = 'VMware, Inc.'
15+
16+
# Required to distribute different parts of this
17+
# package as multiple distribution
18+
try:
19+
import pkg_resources
20+
21+
pkg_resources.declare_namespace(__name__)
22+
except ImportError:
23+
from pkgutil import extend_path
24+
25+
__path__ = extend_path(__path__, __name__) # @ReservedAssignment
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
* *******************************************************
5+
* Copyright (c) VMware, Inc. 2017. All Rights Reserved.
6+
* SPDX-License-Identifier: MIT
7+
* *******************************************************
8+
*
9+
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
10+
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
11+
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
12+
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
13+
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
14+
"""
15+
16+
__author__ = 'VMware, Inc.'
17+
18+
import requests
19+
import argparse
20+
import atexit
21+
from tabulate import tabulate
22+
23+
from vmware.vapi.vmc.client import create_vmc_client
24+
25+
26+
class OperationsOnOrganizations(object):
27+
"""
28+
Demonstrates operations on organizations and features
29+
30+
Sample Prerequisites:
31+
- At least one org associated with the calling user.
32+
"""
33+
34+
def __init__(self):
35+
self.org = None
36+
self.feature = None
37+
self.vmc_client = None
38+
self.refresh_token = None
39+
40+
def options(self):
41+
parser = argparse.ArgumentParser(
42+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
43+
44+
parser.add_argument('refresh_token',
45+
help='VMware Cloud API refresh token')
46+
self.refresh_token = parser.parse_args().refresh_token
47+
48+
def setup(self):
49+
# Login to VMware Cloud on AWS
50+
session = requests.Session()
51+
self.vmc_client = create_vmc_client(self.refresh_token, session)
52+
atexit.register(session.close)
53+
54+
def list_orgs(self):
55+
orgs = self.vmc_client.Orgs.list()
56+
if not orgs:
57+
raise ValueError('The sample requires at least one org associated'
58+
'with the calling user')
59+
print("\n# Example: List organizations")
60+
table = []
61+
for org in orgs:
62+
table.append([org.id, org.display_name])
63+
print(tabulate(table, ['ID', 'Display Name']))
64+
65+
self.org = orgs[0]
66+
67+
def get_org_detail(self):
68+
org = self.org
69+
print('\n# Example: List details of the first organization {}:'.
70+
format(org.id))
71+
72+
headers = ['ID', 'Display Name', 'Name', 'Created', 'Updated',
73+
'Project State', 'SLA']
74+
data = [org.id, org.display_name, org.name,
75+
org.created.strftime('%m/%d/%Y'),
76+
org.updated.strftime('%m/%d/%Y'),
77+
org.project_state, org.sla]
78+
print(tabulate([data], headers))
79+
80+
81+
def main():
82+
org_operations = OperationsOnOrganizations()
83+
org_operations.options()
84+
org_operations.setup()
85+
org_operations.list_orgs()
86+
org_operations.get_org_detail()
87+
88+
89+
if __name__ == '__main__':
90+
main()

samples/vmc/sddc/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
This directory contains samples for VMC SDDC APIs:
2+
3+
Use -h to check the required parameter for each sample:
4+
5+
$ python add_remove_hosts.py -h
6+
7+
To run the sample:
8+
9+
$ python add_remove_hosts.py <refresh_token> <org_id> <sddc_id>
10+
11+
* Testbed Requirement:
12+
- An organization associated with the calling user.
13+
- A SDDC in the organization
14+

samples/vmc/sddc/__init__.py

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

0 commit comments

Comments
 (0)