Skip to content

Commit 8fd5154

Browse files
authored
Merge pull request #22 from pgbidkar/master
SSO samples are failing with 6.0 vCenter server. com.vmware.vapi.vcen…
2 parents 8c22814 + f4c82a3 commit 8fd5154

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

samples/vsphere/sso/embedded_psc_sso_workflow.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
1414
"""
1515

16-
1716
__author__ = 'VMware, Inc.'
1817
__copyright__ = 'Copyright 2017 VMware, Inc. All rights reserved.'
1918
__vcenter_version__ = '6.0+'
@@ -22,11 +21,11 @@
2221
import requests
2322

2423
from com.vmware.cis_client import Session
25-
from com.vmware.vcenter_client import Datacenter
2624
from vmware.vapi.lib.connect import get_requests_connector
2725
from vmware.vapi.security.session import create_session_security_context
2826
from vmware.vapi.security.sso import create_saml_bearer_security_context
2927
from vmware.vapi.stdlib.client.factories import StubConfigurationFactory
28+
from com.vmware.cis.tagging_client import (Category, CategoryModel)
3029

3130
from samples.vsphere.common.ssl_helper import get_unverified_context
3231
from samples.vsphere.common.vapiconnect import create_unverified_session
@@ -47,6 +46,8 @@ def __init__(self):
4746
self.session = None
4847
self.session_id = None
4948
self.skip_verification = False
49+
self.category_svc = None
50+
self.category_id = None
5051

5152
def setup(self):
5253
self.server, self.username, self.password, _, self.skip_verification = \
@@ -100,14 +101,31 @@ def run(self):
100101
session_sec_ctx = create_session_security_context(self.session_id)
101102
connector.set_security_context(session_sec_ctx)
102103

103-
print('\nStep 3: List available datacenters using the vAPI services')
104+
# Create and Delete TagCategory to Verify connection is successful
105+
print('\nStep 3: Creating and Deleting Tag Category...\n')
106+
self.category_svc = Category(stub_config)
107+
108+
self.category_id = self.create_tag_category('TestTagCat', 'TestTagDesc',
109+
CategoryModel.Cardinality.MULTIPLE)
110+
assert self.category_id is not None
111+
print('Tag category created; Id: {0}\n'.format(self.category_id))
104112

105-
datacenter_svc = Datacenter(stub_config)
106-
pprint(datacenter_svc.list())
113+
# Delete TagCategory
114+
self.category_svc.delete(self.category_id)
107115

108116
self.session.delete()
109117
print('VAPI session disconnected successfully...')
110118

119+
def create_tag_category(self, name, description, cardinality):
120+
"""create a category. User who invokes this needs create category privilege."""
121+
create_spec = self.category_svc.CreateSpec()
122+
create_spec.name = name
123+
create_spec.description = description
124+
create_spec.cardinality = cardinality
125+
associableTypes = set()
126+
create_spec.associable_types = associableTypes
127+
return self.category_svc.create(create_spec)
128+
111129

112130
def main():
113131
embedded_psc_sso_workflow = EmbeddedPscSsoWorkflow()

samples/vsphere/sso/external_psc_sso_workflow.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
from six.moves.urllib import request, parse
2626

2727
from com.vmware.cis_client import Session
28-
from com.vmware.vcenter_client import Datacenter
2928

3029
from vmware.vapi.lib.connect import get_requests_connector
3130
from vmware.vapi.security.session import create_session_security_context
3231
from vmware.vapi.security.sso import create_saml_bearer_security_context
3332
from vmware.vapi.stdlib.client.factories import StubConfigurationFactory
33+
from com.vmware.cis.tagging_client import (Category, CategoryModel)
3434

3535
from samples.vsphere.common import sso
3636
from samples.vsphere.common.lookup_service_helper import LookupServiceHelper
@@ -56,6 +56,8 @@ def __init__(self):
5656
self.argparser = None
5757
self.mgmtinstancename = None
5858
self.skip_verification = False
59+
self.category_svc = None
60+
self.category_id = None
5961

6062
def options(self):
6163
self.argparser = argparse.ArgumentParser(description=self.__doc__)
@@ -170,10 +172,30 @@ def run(self):
170172
session_sec_ctx = create_session_security_context(self.session_id)
171173
connector.set_security_context(session_sec_ctx)
172174

173-
print('\nStep 6: List available datacenters using the vAPI service')
175+
# Create and Delete TagCategory to Verify connection is successful
176+
print('\nStep 6: Creating and Deleting Tag Category...\n')
177+
self.category_svc = Category(stub_config)
174178

175-
datacenter_svc = Datacenter(stub_config)
176-
pprint(datacenter_svc.list())
179+
self.category_id = self.create_tag_category('TestTagCat', 'TestTagDesc',
180+
CategoryModel.Cardinality.MULTIPLE)
181+
assert self.category_id is not None
182+
print('Tag category created; Id: {0}\n'.format(self.category_id))
183+
184+
# Delete TagCategory
185+
self.category_svc.delete(self.category_id)
186+
187+
self.session.delete()
188+
print('VAPI session disconnected successfully...')
189+
190+
def create_tag_category(self, name, description, cardinality):
191+
"""create a category. User who invokes this needs create category privilege."""
192+
create_spec = self.category_svc.CreateSpec()
193+
create_spec.name = name
194+
create_spec.description = description
195+
create_spec.cardinality = cardinality
196+
associableTypes = set()
197+
create_spec.associable_types = associableTypes
198+
return self.category_svc.create(create_spec)
177199

178200
self.session.delete()
179201
print('VAPI session disconnected successfully...')

0 commit comments

Comments
 (0)