Skip to content

Add VMware Cloud on AWS APIs #40

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
Dec 6, 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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ python:
- "3.6"
# command to install dependencies
install:
- pip install -r requirements.txt --extra-index-url file://$PWD/lib --upgrade --ignore-installed six
- pip install -r requirements.txt --extra-index-url file://$PWD/lib --upgrade --ignore-installed six
- pip install -r test-requirements.txt
- pip install pycodestyle
# command to run tests
script: pycodestyle samples/*
script: pycodestyle samples/*.py
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
[![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)
## Table of Contents
- [Abstract](#abstract)
- [Supported vCenter Releases](#supported-vcenter-releases)
- [VMware Cloud on AWS Support](#vmware-cloud-on-aws-support)
- [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)
Expand Down Expand Up @@ -29,10 +31,13 @@ vSphere Automation and vSphere APIs. To support this combined use, the vSphere A
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:
## 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.

## VMware Cloud on AWS Support
The VMware Cloud on AWS API and samples are currently available as a preview and are subject to change in the future.

## 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
Expand All @@ -55,11 +60,13 @@ The required packages are:
* pyVmomi
* suds (suds-jurko for python3+)
* vapi-client-bindings
* vmc-client-bindings
* vapi-vmc-client

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

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

**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
Expand Down
Binary file modified doc/client.zip
Binary file not shown.
Binary file added doc/vmc.zip
Binary file not shown.
4 changes: 3 additions & 1 deletion lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ For python developers, client libraries are supplied for testing and development

Name | Description
------------------------------------| -------------
vapi_runtime | vAPI runtime responsible for serialization/de-serialization of objects and wire protocol
vapi_runtime | vAPI runtime responsible for serialization/de-serialization of objects and wire protocol
vapi_vmc_client | Handles VMC CSP authentication process
vapi_client_bindings | Client stubs for vSphere Automation APIs
vmc_client_bindings | Client stubs for VMware Cloud Services APIs
14 changes: 10 additions & 4 deletions lib/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<html><head><title>Simple Index</title><meta name='api-version' value='2' /></head><body>
<a href='vapi-client-bindings/'>vapi-client-bindings</a><br />
<a href='vapi-runtime/'>vapi-runtime</a><br />
</body></html>
<html>
<head><title>Simple Index</title>
<meta name='api-version' value='2'/>
</head>
<body>
<a href='vapi-client-bindings/'>vapi-client-bindings</a><br/>
<a href='vmc-client-bindings/'>vmc-client-bindings</a><br/>
<a href='vapi-runtime/'>vapi-runtime</a><br/>
</body>
</html>
2 changes: 1 addition & 1 deletion lib/vapi-client-bindings/index.html
Original file line number Diff line number Diff line change
@@ -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 />
<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.
2 changes: 1 addition & 1 deletion lib/vapi-runtime/index.html
Original file line number Diff line number Diff line change
@@ -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 />
<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.
1 change: 1 addition & 0 deletions lib/vapi-vmc-client/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +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.
Binary file removed lib/vapi_client_bindings-2.5.0.zip
Binary file not shown.
Binary file removed lib/vapi_common_client-2.5.0.zip
Binary file not shown.
Binary file removed lib/vapi_runtime-2.5.0.zip
Binary file not shown.
1 change: 1 addition & 0 deletions lib/vmc-client-bindings/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +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.
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
pyVmomi >= 6.5
suds ; python_version < '3'
suds-jurko ; python_version >= '3.0'
vapi-client-bindings
tabulate
vapi-client-bindings == 1.0.0
vmc-client-bindings
vapi-vmc-client
4 changes: 4 additions & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Directory | Description
----------------| -------------
vSphere | Samples for vSphere APIs
vmc | Samples for VMware Cloud on AWS Services (currently in preview)
9 changes: 9 additions & 0 deletions samples/vmc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Samples for VMware Cloud on AWS APIs (currently in preview)

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

Directory | Description
----------------| -------------
orgs | Samples for operations on organizations
sddc | Samples for operations on SDDCs
helpers | Helper methods used by VMware Cloud on AWS API samples
25 changes: 25 additions & 0 deletions samples/vmc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
* *******************************************************
* Copyright VMware, Inc. 2017. All Rights Reserved.
* SPDX-License-Identifier: MIT
* *******************************************************
*
* 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.'

# 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
25 changes: 25 additions & 0 deletions samples/vmc/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
* *******************************************************
* Copyright VMware, Inc. 2017. All Rights Reserved.
* SPDX-License-Identifier: MIT
* *******************************************************
*
* 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.'

# 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
64 changes: 64 additions & 0 deletions samples/vmc/helpers/vmc_task_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
* *******************************************************
* Copyright (c) VMware, Inc. 2017. All Rights Reserved.
* SPDX-License-Identifier: MIT
* *******************************************************
*
* 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.'

from time import sleep
from tabulate import tabulate

from com.vmware.vmc.model_client import Task


def wait_for_task(task_client, org_id, task_id, interval_sec=60):
"""
Helper method to wait for a task to finish
:param task_client: task client to query the task object
:param org_id: organization id
:param task_id: task id
:param interval_sec: task pulling interval_sec in sec
:return: True if task finished successfully, False otherwise.
"""
print('Wait for task {} to finish'.format(task_id))
print('Checking task status every {} seconds'.format(interval_sec))

while True:
task = task_client.get(org_id, task_id)

if task.status == Task.STATUS_FINISHED:
print('\nTask {} finished successfully'.format(task_id))
return True
elif task.status == Task.STATUS_FAILED:
print('\nTask {} failed'.format(task_id))
return False
elif task.status == Task.STATUS_CANCELED:
print('\nTask {} cancelled'.format(task_id))
return False
else:
print("Estimated time remaining: {} minutes".
format(task.estimated_remaining_minutes))
sleep(interval_sec)


def list_all_tasks(task_client, org_id):
"""
List all tasks in a given org
:param task_client: task client to query the task object
:param org_id: organization id
"""
tasks = task_client.list(org_id)
headers = ['ID', 'Status', 'Progress', 'Started', 'User']
table = []
for task in tasks:
table.append([task.id, task.status, task.progress_percent,
task.start_time, task.user_name])
print(tabulate(table, headers))
9 changes: 9 additions & 0 deletions samples/vmc/orgs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This directory contains samples for VMC organization APIs:

Running the samples

$ python organization_operations.py <refresh_token>

* Testbed Requirement:
- At least one org associated with the calling user.

25 changes: 25 additions & 0 deletions samples/vmc/orgs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
* *******************************************************
* Copyright VMware, Inc. 2017. All Rights Reserved.
* SPDX-License-Identifier: MIT
* *******************************************************
*
* 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.'

# 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
90 changes: 90 additions & 0 deletions samples/vmc/orgs/organization_operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env python

"""
* *******************************************************
* Copyright (c) VMware, Inc. 2017. All Rights Reserved.
* SPDX-License-Identifier: MIT
* *******************************************************
*
* 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.'

import requests
import argparse
import atexit
from tabulate import tabulate

from vmware.vapi.vmc.client import create_vmc_client


class OperationsOnOrganizations(object):
"""
Demonstrates operations on organizations and features

Sample Prerequisites:
- At least one org associated with the calling user.
"""

def __init__(self):
self.org = None
self.feature = None
self.vmc_client = None
self.refresh_token = None

def options(self):
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)

parser.add_argument('refresh_token',
help='VMware Cloud API refresh token')
self.refresh_token = parser.parse_args().refresh_token

def setup(self):
# Login to VMware Cloud on AWS
session = requests.Session()
self.vmc_client = create_vmc_client(self.refresh_token, session)
atexit.register(session.close)

def list_orgs(self):
orgs = self.vmc_client.Orgs.list()
if not orgs:
raise ValueError('The sample requires at least one org associated'
'with the calling user')
print("\n# Example: List organizations")
table = []
for org in orgs:
table.append([org.id, org.display_name])
print(tabulate(table, ['ID', 'Display Name']))

self.org = orgs[0]

def get_org_detail(self):
org = self.org
print('\n# Example: List details of the first organization {}:'.
format(org.id))

headers = ['ID', 'Display Name', 'Name', 'Created', 'Updated',
'Project State', 'SLA']
data = [org.id, org.display_name, org.name,
org.created.strftime('%m/%d/%Y'),
org.updated.strftime('%m/%d/%Y'),
org.project_state, org.sla]
print(tabulate([data], headers))


def main():
org_operations = OperationsOnOrganizations()
org_operations.options()
org_operations.setup()
org_operations.list_orgs()
org_operations.get_org_detail()


if __name__ == '__main__':
main()
14 changes: 14 additions & 0 deletions samples/vmc/sddc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
This directory contains samples for VMC SDDC APIs:

Use -h to check the required parameter for each sample:

$ python add_remove_hosts.py -h

To run the sample:

$ python add_remove_hosts.py <refresh_token> <org_id> <sddc_id>

* Testbed Requirement:
- An organization associated with the calling user.
- A SDDC in the organization

25 changes: 25 additions & 0 deletions samples/vmc/sddc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
* *******************************************************
* Copyright VMware, Inc. 2017. All Rights Reserved.
* SPDX-License-Identifier: MIT
* *******************************************************
*
* 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.'

# 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
Loading