Skip to content

Commit 98fcd5d

Browse files
authored
Merge pull request #153 from tianhao64/master
API bindings for VMware Cloud on AWS 1.7 release
2 parents ff4500a + a1dac86 commit 98fcd5d

16 files changed

+405
-4
lines changed

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-1.5.0-py2.py3-none-any.whl'>vapi_client_bindings-1.5.0-py2.py3-none-any.whl</a><br />
1+
<a href='vapi_client_bindings-3.0.0-py2.py3-none-any.whl'>vapi_client_bindings-3.0.0-py2.py3-none-any.whl</a><br />
Binary file not shown.
Binary file not shown.

lib/vapi-common-client/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<a href='vapi_common_client-2.10.2-py2.py3-none-any.whl'>vapi_common_client-2.10.2-py2.py3-none-any.whl</a><br />
1+
<a href='vapi_common_client-2.12.0-py2.py3-none-any.whl'>vapi_common_client-2.12.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.10.2-py2.py3-none-any.whl'>vapi_runtime-2.10.2-py2.py3-none-any.whl</a><br />
1+
<a href='vapi_runtime-2.12.0-py2.py3-none-any.whl'>vapi_runtime-2.12.0-py2.py3-none-any.whl</a><br />
Binary file not shown.
Binary file not shown.
Binary file not shown.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ lxml >= 4.3.0
22
pyVmomi >= 6.7
33
suds ; python_version < '3'
44
suds-jurko ; python_version >= '3.0'
5-
vapi-client-bindings == 1.5.0
5+
vapi-client-bindings == 3.0.0
66
vmc-client-bindings
77
nsx-python-sdk
88
nsx-policy-python-sdk

samples/vsphere/oauth/__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. 2019. 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: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
"""
2+
* *******************************************************
3+
* Copyright VMware, Inc. 2019. 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+
__vcenter_version__ = '6.8.7+'
16+
17+
import argparse
18+
import base64
19+
import requests
20+
from com.vmware.vcenter.tokenservice_client import TokenExchange
21+
from lxml import etree
22+
from vmware.vapi.lib.connect import get_requests_connector
23+
from vmware.vapi.security.oauth import create_oauth_security_context
24+
from vmware.vapi.stdlib.client.factories import StubConfigurationFactory
25+
from vmware.vapi.vsphere.client import create_vsphere_client
26+
27+
from samples.vsphere.common.ssl_helper import get_unverified_session
28+
29+
'''
30+
This sample demonstrates obtaining saml token from access(subject) and id(actor) tokens
31+
The SAML token is then used to connect to VCenter and list all the VM Details
32+
33+
Pre-requisites:
34+
- a VCenter
35+
- access/subject token
36+
- id/actor token
37+
38+
To run the sample,
39+
$ python exchange_access_id_token_for_saml_token.py --vc <VC> --subject_token <Subject Token> --actor_token <Actor Token> --skipverification
40+
'''
41+
42+
HTTP_ENDPOINT = "https://{}/api"
43+
UTF8 = 'utf-8'
44+
45+
parser = argparse.ArgumentParser(description='arguments for obtaining SAML token from access(subject) and id(actor) tokens')
46+
47+
parser.add_argument('--vc', dest='vcenter_server',
48+
help='VCenter hostname or IP')
49+
parser.add_argument('--subject_token', dest='subject_token',
50+
help='Subject/Access token')
51+
parser.add_argument('--actor_token', dest='actor_token',
52+
help='Actor/ID token')
53+
parser.add_argument('--skipverification',
54+
action='store_true',
55+
help='Skip Server Certificate Verification')
56+
57+
args = parser.parse_args()
58+
59+
session = requests.session()
60+
if args.skipverification:
61+
session = get_unverified_session()
62+
63+
stub_config = StubConfigurationFactory.new_std_configuration(
64+
get_requests_connector(
65+
session=session,
66+
url=HTTP_ENDPOINT.format(args.vcenter_server)
67+
)
68+
)
69+
70+
# create oauth security context for authentication
71+
oauth_security_context = create_oauth_security_context(args.subject_token)
72+
stub_config.connector.set_security_context(oauth_security_context)
73+
74+
token_exchange = TokenExchange(stub_config)
75+
exchange_spec = token_exchange.ExchangeSpec(
76+
grant_type=token_exchange.TOKEN_EXCHANGE_GRANT,
77+
subject_token_type=token_exchange.ACCESS_TOKEN_TYPE,
78+
actor_token_type=token_exchange.ID_TOKEN_TYPE,
79+
requested_token_type=token_exchange.SAML2_TOKEN_TYPE,
80+
actor_token=args.actor_token, subject_token=args.subject_token)
81+
response = token_exchange.exchange(exchange_spec)
82+
saml_token = response.access_token
83+
84+
# convert saml token to saml assertion
85+
samlAssertion = etree.tostring(
86+
etree.XML(base64.decodebytes(
87+
bytes(saml_token, UTF8)
88+
))
89+
).decode(UTF8)
90+
91+
# create vsphere client to connect to VC and list VM Details
92+
client = create_vsphere_client(server=args.vcenter_server, bearer_token=samlAssertion, session=session)
93+
vms = client.vcenter.VM.list()
94+
95+
print("VM List\n", "-" * 50)
96+
for vm in vms:
97+
print(vm.name)
98+
print("-" * 50)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""
2+
* *******************************************************
3+
* Copyright VMware, Inc. 2019. 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+
__vcenter_version__ = '6.8.7+'
16+
17+
import argparse
18+
import requests
19+
from com.vmware.vcenter.identity_client import Providers
20+
from vmware.vapi.stdlib.client.factories import StubConfigurationFactory
21+
from samples.vsphere.common.ssl_helper import get_unverified_session
22+
from vmware.vapi.lib.connect import get_requests_connector
23+
24+
'''
25+
This sample lists all the external Identity Providers for the given VCenter
26+
27+
Pre-requisites:
28+
- a VCenter
29+
30+
To run the sample,
31+
$ python list_external_identity_providers.py --vc <VC> --skipverification
32+
'''
33+
34+
HTTP_ENDPOINT = "https://{}/api"
35+
36+
parser = argparse.ArgumentParser(description='arguments for listing external Identity Providers')
37+
38+
parser.add_argument('--vc', dest='vcenter_server',
39+
help='VCenter hostname or IP')
40+
parser.add_argument('--skipverification',
41+
action='store_true',
42+
help='Skip Server Certificate Verification')
43+
44+
args = parser.parse_args()
45+
46+
session = requests.session()
47+
if args.skipverification:
48+
session = get_unverified_session()
49+
50+
stub_config = StubConfigurationFactory.new_std_configuration(get_requests_connector(session=session, url=HTTP_ENDPOINT.format(args.vcenter_server)))
51+
52+
# use the identity client to list the providers
53+
id_client = Providers(stub_config)
54+
providers = id_client.list()
55+
print("Total providers: {}\n".format(len(providers)))
56+
print("-" * 100)
57+
58+
# print summary of the providers
59+
for p in providers:
60+
print("Auth Endpoint: {}\n".format(p.oauth2.auth_endpoint))
61+
print("Token Endpoint: {}\n".format(p.oauth2.token_endpoint))
62+
print("-" * 100)
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env python
2+
"""
3+
* *******************************************************
4+
* Copyright (c) VMware, Inc. 2019. All Rights Reserved.
5+
* SPDX-License-Identifier: MIT
6+
* *******************************************************
7+
*
8+
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
9+
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
10+
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
11+
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
12+
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
13+
"""
14+
15+
__author__ = 'VMware, Inc.'
16+
17+
import os
18+
import requests
19+
20+
from com.vmware.vcenter.system_config_client import DeploymentType
21+
22+
from samples.vsphere.common import sample_cli, sample_util
23+
from samples.vsphere.common.ssl_helper import get_unverified_session
24+
25+
from vmware.vapi.core import ApplicationContext
26+
from vmware.vapi.lib.constants import SHOW_UNRELEASED_APIS
27+
from vmware.vapi.lib.connect import get_connector, get_requests_connector
28+
from vmware.vapi.stdlib.client.factories import StubConfigurationFactory
29+
from vmware.vapi.security.client.security_context_filter import \
30+
LegacySecurityContextFilter, ApiProviderFilter
31+
from vmware.vapi.security.user_password import \
32+
create_user_password_security_context
33+
34+
35+
class SampleConverge(object):
36+
"""
37+
Sample demonstrating vCenter External to Embedded Convergence operation
38+
Sample Prerequisites:
39+
vCenter on linux platform with external Platform Services Controller
40+
"""
41+
def __init__(self):
42+
parser = sample_cli.build_arg_parser()
43+
parser.add_argument(
44+
'-a', '--sso_admin_username', action='store', required=True,
45+
default='Sample_PSC_username',
46+
help='Platform Services Controller admin username')
47+
parser.add_argument(
48+
'-w', '--sso_admin_password', action='store', required=True,
49+
default='Sample_PSC_Admin_Password',
50+
help='Platform Services Controller admin password')
51+
52+
args = sample_util.process_cli_args(parser.parse_args())
53+
self.username = args.username
54+
self.password = args.password
55+
self.sso_admin_username = args.sso_admin_username
56+
self.sso_admin_password = args.sso_admin_password
57+
self.server = args.server
58+
self.skipverification = args.skipverification
59+
60+
def run(self):
61+
"""
62+
Converges the external PSC into the Management Node without shutting
63+
down the Platform Services Controller.
64+
"""
65+
session = get_unverified_session() if self.skipverification else None
66+
67+
sec_ctx = create_user_password_security_context(
68+
self.username, self.password)
69+
# TODO The following line to be deleted when API is changed to
70+
# @Release type. As of now this is only for testing
71+
app_ctx = ApplicationContext({SHOW_UNRELEASED_APIS: "True"})
72+
73+
connector = get_requests_connector(
74+
session=session,
75+
msg_protocol='json',
76+
url='https://{0}:5480/api'.format(self.server),
77+
provider_filter_chain=[
78+
LegacySecurityContextFilter(
79+
security_context=sec_ctx)])
80+
connector.set_application_context(app_ctx)
81+
stub_config = StubConfigurationFactory.new_std_configuration(connector)
82+
deployment_type = DeploymentType(stub_config)
83+
"""
84+
Running convergence task precheck.
85+
Remove the line ", only_precheck = True" to perform convergence.
86+
"""
87+
convergence_task = deployment_type.convert_to_vcsa_embedded_task(
88+
DeploymentType.ConvergenceSpec(DeploymentType.PscInfo(
89+
sso_admin_username=self.sso_admin_username,
90+
sso_admin_password=self.sso_admin_password),
91+
only_precheck=True))
92+
93+
print('Converge operation started with task ID: \n{0}'.format(
94+
convergence_task.get_task_id()))
95+
96+
97+
def main():
98+
"""
99+
Entry point for the sample client
100+
"""
101+
converge = SampleConverge()
102+
converge.run()
103+
104+
105+
if __name__ == '__main__':
106+
main()

0 commit comments

Comments
 (0)