diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index ef8b288f..e3943508 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -3336,6 +3336,54 @@ class TestPolicyTier1(NsxPolicyLibTestCase): self.assert_called_with_def(api_call, expected_def) + def test_get_multicast(self): + tier1_id = '111' + with mock.patch.object(self.policy_api, "get") as api_call: + api_call.return_value = {'enabled': True} + enabled = self.resourceApi.get_multicast( + tier1_id, + tenant=TEST_TENANT) + + expected_def = core_defs.Tier1MulticastDef( + tier1_id=tier1_id, + service_id=self.resourceApi._locale_service_id(tier1_id), + tenant=TEST_TENANT) + + self.assert_called_with_def(api_call, expected_def) + self.assertTrue(enabled) + + def test_enable_multicast(self): + tier1_id = '111' + with mock.patch.object(self.policy_api, + "create_or_update") as api_call: + self.resourceApi.enable_multicast( + tier1_id, + tenant=TEST_TENANT) + + expected_def = core_defs.Tier1MulticastDef( + tier1_id=tier1_id, + service_id=self.resourceApi._locale_service_id(tier1_id), + enabled=True, + tenant=TEST_TENANT) + + self.assert_called_with_def(api_call, expected_def) + + def test_disable_multicast(self): + tier1_id = '111' + with mock.patch.object(self.policy_api, + "create_or_update") as api_call: + self.resourceApi.disable_multicast( + tier1_id, + tenant=TEST_TENANT) + + expected_def = core_defs.Tier1MulticastDef( + tier1_id=tier1_id, + service_id=self.resourceApi._locale_service_id(tier1_id), + enabled=False, + tenant=TEST_TENANT) + + self.assert_called_with_def(api_call, expected_def) + def test_add_advertisement_rule(self): tier1_id = '111' rule_name = 'rule_name' diff --git a/vmware_nsxlib/v3/policy/core_defs.py b/vmware_nsxlib/v3/policy/core_defs.py index 1f1e68d5..dfaca1a9 100644 --- a/vmware_nsxlib/v3/policy/core_defs.py +++ b/vmware_nsxlib/v3/policy/core_defs.py @@ -564,6 +564,24 @@ class Tier1LocaleServiceDef(RouterLocaleServiceDef): return (TenantDef, Tier1Def) +class Tier1MulticastDef(ResourceDef): + + @property + def path_pattern(self): + return TIER1_LOCALE_SERVICES_PATH_PATTERN + "%s/multicast" + + @property + def path_ids(self): + # 'Dummy' used since multicast is a sub-attribute of a Tier1 GW + # which is however set with its own API endpoint + return ('tenant', 'tier1_id', 'service_id', 'dummy') + + def get_obj_dict(self): + body = super(Tier1MulticastDef, self).get_obj_dict() + self._set_attr_if_specified(body, 'enabled') + return body + + class Tier0InterfaceDef(ResourceDef): @staticmethod diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 15211c81..254b106f 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -1327,6 +1327,30 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase): tenant=tenant) return self._list(t1interface_def) + def get_multicast(self, tier1_id, tenant=constants.POLICY_INFRA_TENANT): + mcast_def = core_defs.Tier1MulticastDef( + tier1_id=tier1_id, + service_id=self._locale_service_id(tier1_id), + tenant=tenant) + mcast_data = self.policy_api.get(mcast_def) + return mcast_data.get('enabled') + + def _set_multicast(self, tier1_id, enabled, tenant): + args = {'tier1_id': tier1_id, + 'service_id': self._locale_service_id(tier1_id), + 'enabled': enabled, + 'tenant': tenant} + mcast_def = core_defs.Tier1MulticastDef(**args) + self.policy_api.create_or_update(mcast_def) + + def enable_multicast(self, tier1_id, + tenant=constants.POLICY_INFRA_TENANT): + self._set_multicast(tier1_id, True, tenant) + + def disable_multicast(self, tier1_id, + tenant=constants.POLICY_INFRA_TENANT): + self._set_multicast(tier1_id, False, tenant) + def get_realized_state(self, tier1_id, entity_type=None, tenant=constants.POLICY_INFRA_TENANT, realization_info=None):