Add function to get security policy rule

Add function to get a specific security policy rule

Change-Id: I07da7baba990206087cf9a67e3baea92d67a4884
This commit is contained in:
Xiaopei Liu
2019-03-07 03:01:35 +08:00
parent 04411a7e3b
commit 402e505932
2 changed files with 25 additions and 0 deletions

View File

@@ -1420,6 +1420,22 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase):
self.assert_called_with_def(api_call, expected_def)
self.assertEqual(map_id, result['id'])
def test_get_entry(self):
domain_id = '111'
map_id = '222'
entry_id = '333'
with mock.patch.object(self.policy_api, "get",
return_value={'id': entry_id}) as api_call:
result = self.resourceApi.get_entry(domain_id, map_id,
entry_id, tenant=TEST_TENANT)
expected_def = self.entryDef(
domain_id=domain_id,
map_id=map_id,
entry_id=entry_id,
tenant=TEST_TENANT)
self.assert_called_with_def(api_call, expected_def)
self.assertEqual(entry_id, result['id'])
def test_get_by_name(self):
domain_id = '111'
name = 'cm1'

View File

@@ -2572,6 +2572,15 @@ class NsxPolicySecurityPolicyBaseApi(NsxPolicyResourceBase):
tenant=tenant)
return self.policy_api.get(map_def, silent=silent)
def get_entry(self, domain_id, map_id, entry_id,
tenant=constants.POLICY_INFRA_TENANT, silent=False):
entry_def = self.entry_def(
domain_id=domain_id,
map_id=map_id,
entry_id=entry_id,
tenant=tenant)
return self.policy_api.get(entry_def, silent=silent)
def get_by_name(self, domain_id, name,
tenant=constants.POLICY_INFRA_TENANT):
"""Return first communication map entry matched by name"""