NSXv3: Enhance NSGroup create and update functions
- Allow passing direct members when creating a new NSGroup - Allow removing membership_criteria when updating a NSGroup Change-Id: Ib0e5f5193f2d9ed455e0918fdf67da7a0acfdb62
This commit is contained in:
parent
0834c3226e
commit
9bf329a0e3
@ -188,10 +188,14 @@ class TestNsxLibNSGroup(nsxlib_testcase.NsxClientTestCase):
|
||||
|
||||
def test_update(self):
|
||||
nsg_tags = [{"scope": "name", "tag": "new_name"}]
|
||||
membership_criteria = []
|
||||
with mock.patch.object(self.nsxlib.client, 'update') as update:
|
||||
with mock.patch.object(self.nsxlib.client, 'get') as get:
|
||||
get.return_value = {}
|
||||
self.nsxlib.ns_group.update('nsgroupid', tags_update=nsg_tags)
|
||||
self.nsxlib.ns_group.update(
|
||||
'nsgroupid', tags_update=nsg_tags,
|
||||
membership_criteria=membership_criteria)
|
||||
resource = 'ns-groups/nsgroupid'
|
||||
data = {'tags': nsg_tags}
|
||||
data = {'tags': nsg_tags,
|
||||
'membership_criteria': membership_criteria}
|
||||
update.assert_called_with(resource, data, headers=None)
|
||||
|
@ -125,11 +125,11 @@ class NsxLibNsGroup(utils.NsxLibApiBase):
|
||||
'tag': tag}
|
||||
|
||||
def create(self, display_name, description, tags,
|
||||
membership_criteria=None):
|
||||
membership_criteria=None, members=None):
|
||||
body = {'display_name': display_name,
|
||||
'description': description,
|
||||
'tags': tags,
|
||||
'members': []}
|
||||
'members': [] if members is None else members}
|
||||
if membership_criteria:
|
||||
# Allow caller to pass a list of membership criterias.
|
||||
# The 'else' block is maintained for backwards compatibility
|
||||
@ -155,7 +155,10 @@ class NsxLibNsGroup(utils.NsxLibApiBase):
|
||||
if members is not None:
|
||||
nsgroup['members'] = members
|
||||
if membership_criteria is not None:
|
||||
nsgroup['membership_criteria'] = [membership_criteria]
|
||||
if isinstance(membership_criteria, list):
|
||||
nsgroup['membership_criteria'] = membership_criteria
|
||||
else:
|
||||
nsgroup['membership_criteria'] = [membership_criteria]
|
||||
if tags_update is not None:
|
||||
nsgroup['tags_update'] = tags_update
|
||||
return self._update_resource(
|
||||
|
Loading…
Reference in New Issue
Block a user