Add util method to retrieve complex expressions for NSGroup
This patch adds a utility method to create complex expressions for NSGroups in order to create a dynamic membership criteria to match multiple tags. Change-Id: I8a15db52e8df889af7fb4b73579873bc86bfa30d
This commit is contained in:
parent
7c4f3e6867
commit
e32c31e3cc
|
@ -14,6 +14,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
import mock
|
||||
import six
|
||||
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
|
@ -137,3 +138,17 @@ class TestNsxLibIPSet(nsxlib_testcase.NsxClientTestCase):
|
|||
fake_ip_set['id'], ip_addresses=new_ip_addresses)
|
||||
resource = 'ip-sets/%s' % fake_ip_set['id']
|
||||
update.assert_called_with(resource, data)
|
||||
|
||||
|
||||
class TestNsxLibNSGroup(nsxlib_testcase.NsxClientTestCase):
|
||||
"""Tests for vmware_nsxlib.v3.security.NsxLibNSGroup"""
|
||||
|
||||
def test_get_nsgroup_complex_expression(self):
|
||||
port_tags = {'app': 'foo', 'project': 'myproject'}
|
||||
port_exp = [self.nsxlib.ns_group.get_port_tag_expression(k, v)
|
||||
for k, v in six.iteritems(port_tags)]
|
||||
complex_exp = self.nsxlib.ns_group.get_nsgroup_complex_expression(
|
||||
expressions=port_exp)
|
||||
expected_exp = {'resource_type': const.NSGROUP_COMPLEX_EXP,
|
||||
'expressions': port_exp}
|
||||
self.assertEqual(expected_exp, complex_exp)
|
||||
|
|
|
@ -48,6 +48,7 @@ SERVICE_DHCP = "dhcp"
|
|||
# NSX-V3 Distributed Firewall constants
|
||||
IP_SET = 'IPSet'
|
||||
NSGROUP = 'NSGroup'
|
||||
NSGROUP_COMPLEX_EXP = 'NSGroupComplexExpression'
|
||||
NSGROUP_SIMPLE_EXP = 'NSGroupSimpleExpression'
|
||||
NSGROUP_TAG_EXP = 'NSGroupTagExpression'
|
||||
EXCLUDE_PORT = 'Exclude-Port'
|
||||
|
|
|
@ -99,6 +99,10 @@ class NsxLibNsGroup(utils.NsxLibApiBase):
|
|||
service.update(properties)
|
||||
return {'service': service}
|
||||
|
||||
def get_nsgroup_complex_expression(self, expressions):
|
||||
return {'resource_type': consts.NSGROUP_COMPLEX_EXP,
|
||||
'expressions': expressions}
|
||||
|
||||
def get_switch_tag_expression(self, scope, tag):
|
||||
return {'resource_type': consts.NSGROUP_TAG_EXP,
|
||||
'target_type': consts.TARGET_TYPE_LOGICAL_SWITCH,
|
||||
|
|
Loading…
Reference in New Issue