Skip to content

Commit a7813fd

Browse files
authored
Merge pull request #239 from anusha94/master
vSphere 7.0 Update 1 GA
2 parents 97a9e5f + a26687a commit a7813fd

22 files changed

+758
-12
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ samples require the vSphere Management SDK packages (pyVmomi) to be installed on
2121
The samples have been developed to work with python 2.7.x and 3.3+
2222

2323
## Supported OnPrem vCenter Releases
24-
vCenter 6.0, 6.5, 6.7 and 7.0.
24+
vCenter 6.0, 6.5, 6.7, 7.0 and 7.0U1.
2525
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.
2626

2727
## Supported NSX-T Releases
@@ -214,8 +214,8 @@ $ python samples/vsphere/vcenter/vm/list_vms.py -v
214214
### vSphere API Documentation
215215

216216
* [VMware Cloud on AWS vSphere (latest version)](https://vmware.github.io/vsphere-automation-sdk-python/vsphere/cloud/index.html)
217-
* [vSphere 7.0 (latest)](https://vmware.github.io/vsphere-automation-sdk-python/vsphere/7.0.0.1/)
218-
* Previous releases: [6.7.1](https://vmware.github.io/vsphere-automation-sdk-python/vsphere/6.7.1/) [6.7.0](https://vmware.github.io/vsphere-automation-sdk-python/vsphere/6.7.0) [6.6.1](https://vmware.github.io/vsphere-automation-sdk-python/vsphere/6.6.1) [6.5](https://vmware.github.io/vsphere-automation-sdk-python/vsphere/6.5) [6.0](https://vmware.github.io/vsphere-automation-sdk-python/vsphere/6.0)
217+
* [vSphere 7.0 Update 1 (latest)](https://vmware.github.io/vsphere-automation-sdk-python/vsphere/7.0.1.0/)
218+
* Previous releases: [7.0](https://vmware.github.io/vsphere-automation-sdk-python/vsphere/7.0.0.1/) [6.7.0](https://vmware.github.io/vsphere-automation-sdk-python/vsphere/6.7.0) [6.6.1](https://vmware.github.io/vsphere-automation-sdk-python/vsphere/6.6.1) [6.5](https://vmware.github.io/vsphere-automation-sdk-python/vsphere/6.5) [6.0](https://vmware.github.io/vsphere-automation-sdk-python/vsphere/6.0)
219219

220220
### VMware Cloud on AWS API Documentation
221221

@@ -250,5 +250,5 @@ Members:
250250
* [VMware Sample Exchange](https://code.vmware.com/samples) It is highly recommended to add any and all submitted samples to the VMware Sample Exchange
251251
* [VMware Code](https://code.vmware.com/home)
252252
* [VMware Developer Community](https://communities.vmware.com/community/vmtn/developer)
253-
* VMware vSphere [REST API Reference documentation](https://code.vmware.com/apis/366/vsphere-automation).
253+
* VMware vSphere [REST API Reference documentation](https://developer.vmware.com/docs/vsphere-automation/latest/).
254254
* [VMware Python forum](https://code.vmware.com/forums/7508/vsphere-automation-sdk-for-python)

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-3.3.0-py2.py3-none-any.whl'>vapi_client_bindings-3.3.0-py2.py3-none-any.whl</a><br />
1+
<a href='vapi_client_bindings-3.5.0-py2.py3-none-any.whl'>vapi_client_bindings-3.5.0-py2.py3-none-any.whl</a><br />
Binary file not shown.
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.15.0-py2.py3-none-any.whl'>vapi_common_client-2.15.0-py2.py3-none-any.whl</a><br />
1+
<a href='vapi_common_client-2.19.0-py2.py3-none-any.whl'>vapi_common_client-2.19.0-py2.py3-none-any.whl</a><br />
Binary file not shown.
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.15.0-py2.py3-none-any.whl'>vapi_runtime-2.15.0-py2.py3-none-any.whl</a><br />
1+
<a href='vapi_runtime-2.19.0-py2.py3-none-any.whl'>vapi_runtime-2.19.0-py2.py3-none-any.whl</a><br />
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 == 3.3.0
5+
vapi-client-bindings == 3.5.0
66
vmc-client-bindings
77
nsx-python-sdk
88
nsx-policy-python-sdk
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## Grant types available
2+
3+
| sample | grant_type |
4+
| ------ | ------ |
5+
| list_vms_authotization_code.py | authorization_code |
6+
| list_vms_client_credentials.py | client_credentials |
7+
| list_vms_refresh_token.py | refresh_token |
8+
| list_vms_password.py | password |
9+
10+
## Login Steps
11+
1. From a given VC IP/hostname, find the Identity Provider (sample available at [list_external_identity_providers.py](https://github.com/vmware/vsphere-automation-sdk-python/blob/master/samples/vsphere/oauth/list_external_identity_providers.py))
12+
2. Make a note of the auth/discovery/token endpoints from the identity provider object
13+
3. Get access token by making the call to endpoints based on parameters relevant to different grant types
14+
4. Convert access token to saml token (sample avaialble at [exchange_access_id_token_for_saml.py](https://github.com/vmware/vsphere-automation-sdk-python/blob/master/samples/vsphere/oauth/exchange_access_id_token_for_saml.py))
15+
5. Use this saml assertion to login to vCenter as a bearer token
16+
17+
18+
## Executing the samples
19+
vCenter needs to be registered with an Identity Provider. Applicable for VC 7.0+
20+
### list_vms_authorization_code.py
21+
Create an OAuth app and make a note of the *app_id*, *app_secret* and *redirect_uri*
22+
23+
First start the webserver code at [webserver.py](https://github.com/vmware/vsphere-automation-sdk-python/blob/master/samples/vsphere/oauth/grant_types/webserver.py). Note, this server is not recommended in a production setting, this is only to demonstarte the sample workflow
24+
25+
`$ python3 webserver.py`
26+
27+
Run the sample,
28+
29+
`$ python list_vms_authorization_code.py --server <VC_IP> --client_id <client_id> --client_secret <client_secret> --org_id <org_id> --skipverification`
30+
31+
### list_vms_client_credentials.py
32+
Create an OAuth app and make a note of the *client_id* and *client_secret*
33+
34+
Run the sample,
35+
36+
`$ python list_vms_client_credentials.py --server <VC_IP> -- client_id <client_id> --client_secret <client_secret> --skipverification`
37+
38+
### list_vms_refresh_token.py
39+
Use the *refresh_token* that was returned along with the access token in authorization_code workflow
40+
41+
Run the sample,
42+
43+
`$ python list_vms_refresh_token.py --server <VC_IP> --client_id <client_id> --client_secret <client_secret> --refresh_token <refresh_token> --skipverification`
44+
45+
### list_vms_password.py
46+
Obtain access token using *username* and *password*
47+
48+
Run the sample,
49+
50+
`$ python list_vms_password --server <VC_IP> --username <username> --password <password> --skipverification`
51+
52+
53+
## References
54+
[Understanding vCenter Server Identity Provider Federation](https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.authentication.doc/GUID-0A3A19E6-150A-493B-8B57-37E19AB420F2.html)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
* *******************************************************
3+
* Copyright VMware, Inc. 2020. 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: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
* *******************************************************
5+
* Copyright (c) VMware, Inc. 2020. 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+
from vmware.vapi.vsphere.client import create_vsphere_client
16+
17+
from samples.vsphere.common.ssl_helper import get_unverified_session
18+
from samples.vsphere.oauth.grant_types.oauth_utility \
19+
import login_using_authorization_code
20+
21+
from urllib.parse import parse_qs
22+
import webbrowser
23+
import urllib.parse as urlparse
24+
import requests
25+
import uuid
26+
import argparse
27+
28+
__author__ = 'VMware, Inc.'
29+
__copyright__ = 'Copyright 2020 VMware, Inc. All rights reserved.'
30+
__vcenter_version__ = '7.0+'
31+
32+
"""
33+
To run this sample,
34+
35+
In a different tab, keep the webserver running,
36+
$ python webserver.py
37+
38+
Then execute the following
39+
$ python list_vms_authorization_code.py --server <VC_IP> \
40+
--client_id <client_id> --client_secret <client_secret> \
41+
--org_id <org_id> --skipverification
42+
"""
43+
44+
parser = argparse.ArgumentParser()
45+
parser.add_argument("--server",
46+
help="VC IP or hostname")
47+
parser.add_argument("--client_id",
48+
help="Client/Application ID of the webapp")
49+
parser.add_argument("--client_secret",
50+
help="Client/Application secret \
51+
of the webapp")
52+
parser.add_argument("--redirect_uri",
53+
help="Redirect uri \
54+
given at the time of client registration")
55+
parser.add_argument('--skipverification',
56+
action='store_true',
57+
help='Verify server certificate when connecting to vc.')
58+
59+
args = parser.parse_args()
60+
61+
62+
def get_auth_code_and_state(url):
63+
openbrowser(url)
64+
parsed = urlparse.urlparse(url)
65+
redirect_uri = parse_qs(parsed.query)['redirect_uri']
66+
67+
get_code_uri = redirect_uri[0].rsplit('/', 1)[0]
68+
get_code_uri = get_code_uri + "/getcode"
69+
70+
response = get_response(get_code_uri)
71+
while "code" not in response or response == '':
72+
response = get_response(get_code_uri)
73+
74+
res = response.split(':')
75+
code = res[1]
76+
state = res[3]
77+
return [code, state]
78+
79+
80+
def openbrowser(url):
81+
webbrowser.open(url)
82+
pass
83+
84+
85+
def get_response(url):
86+
response = requests.get(url)
87+
return response.text
88+
89+
90+
session = get_unverified_session() if args.skipverification else None
91+
saml_assertion = login_using_authorization_code(
92+
args.server,
93+
session,
94+
args.client_id,
95+
args.client_secret,
96+
args.redirect_uri,
97+
get_auth_code_and_state)
98+
client = create_vsphere_client(
99+
server=args.server,
100+
bearer_token=saml_assertion,
101+
session=session)
102+
vms = client.vcenter.VM.list()
103+
print(vms)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
* *******************************************************
5+
* Copyright (c) VMware, Inc. 2020. 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+
from vmware.vapi.vsphere.client import create_vsphere_client
16+
17+
from samples.vsphere.common import sample_cli
18+
from samples.vsphere.common import sample_util
19+
from samples.vsphere.common.ssl_helper import get_unverified_session
20+
from samples.vsphere.oauth.grant_types.oauth_utility \
21+
import login_using_client_credentials
22+
import argparse
23+
24+
__author__ = 'VMware, Inc.'
25+
__copyright__ = 'Copyright 2020 VMware, Inc. All rights reserved.'
26+
__vcenter_version__ = '7.0+'
27+
28+
"""
29+
To run this sample,
30+
$ python list_vms_client_credentials.py --server <VC_IP> \
31+
-- client_id <client_id> --client_secret <client_secret> --skipverification
32+
"""
33+
34+
parser = argparse.ArgumentParser()
35+
parser.add_argument("--server",
36+
help="VC IP or hostname")
37+
parser.add_argument("--client_id",
38+
help="Client/Application ID of the server to server app")
39+
parser.add_argument("--client_secret",
40+
help="Client/Application secret \
41+
of the server to server app")
42+
parser.add_argument('--skipverification',
43+
action='store_true',
44+
help='Verify server certificate when connecting to vc.')
45+
46+
args = parser.parse_args()
47+
48+
session = get_unverified_session() if args.skipverification else None
49+
saml_assertion = login_using_client_credentials(
50+
args.server,
51+
session,
52+
args.client_id,
53+
args.client_secret)
54+
55+
client = create_vsphere_client(
56+
server=args.server,
57+
bearer_token=saml_assertion,
58+
session=session)
59+
vms = client.vcenter.VM.list()
60+
print(vms)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
* *******************************************************
5+
* Copyright (c) VMware, Inc. 2020. 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+
from vmware.vapi.vsphere.client import create_vsphere_client
16+
17+
from samples.vsphere.common import sample_cli
18+
from samples.vsphere.common import sample_util
19+
from samples.vsphere.common.ssl_helper import get_unverified_session
20+
from samples.vsphere.oauth.grant_types.oauth_utility \
21+
import login_using_password
22+
import argparse
23+
24+
__author__ = 'VMware, Inc.'
25+
__copyright__ = 'Copyright 2020 VMware, Inc. All rights reserved.'
26+
__vcenter_version__ = '7.0+'
27+
28+
"""
29+
To run this sample,
30+
$ python list_vms_password --server <VC_IP> \
31+
--username <username> --password <password> --skipverification
32+
"""
33+
34+
parser = argparse.ArgumentParser()
35+
parser.add_argument("--server",
36+
help="VC IP or hostname")
37+
parser.add_argument("--username",
38+
help="username to login \
39+
to vCenter")
40+
parser.add_argument("--password",
41+
help="password to login \
42+
to vCenter")
43+
parser.add_argument('--skipverification',
44+
action='store_true',
45+
help='Verify server certificate when connecting to vc.')
46+
47+
args = parser.parse_args()
48+
49+
session = get_unverified_session() if args.skipverification else None
50+
saml_assertion = login_using_password(
51+
args.server,
52+
session,
53+
args.username,
54+
args.password)
55+
56+
client = create_vsphere_client(
57+
server=args.server,
58+
bearer_token=saml_assertion,
59+
session=session)
60+
vms = client.vcenter.VM.list()
61+
print(vms)

0 commit comments

Comments
 (0)