Add support for enabling/disabling multicast on Tier-1 GW
This patch allow for enabling or disabling multicast on a Tier-1 GW router. This is simply done by setting a boolean flag in the router's multicast configuration, which is however a sub-attribute of the Tier-1 GW object accessed via its own API endpoint. For the above reason, this patch introduces a definition object for the Tier-1 Multicast settings. Change-Id: I8308442ecd9b4d14f4ceb0ea55c4dcd4ee240e17
This commit is contained in:
parent
0ec8b223b4
commit
ea8d433643
@ -3336,6 +3336,54 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
|
|||||||
|
|
||||||
self.assert_called_with_def(api_call, expected_def)
|
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):
|
def test_add_advertisement_rule(self):
|
||||||
tier1_id = '111'
|
tier1_id = '111'
|
||||||
rule_name = 'rule_name'
|
rule_name = 'rule_name'
|
||||||
|
@ -564,6 +564,24 @@ class Tier1LocaleServiceDef(RouterLocaleServiceDef):
|
|||||||
return (TenantDef, Tier1Def)
|
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):
|
class Tier0InterfaceDef(ResourceDef):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -1327,6 +1327,30 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
|
|||||||
tenant=tenant)
|
tenant=tenant)
|
||||||
return self._list(t1interface_def)
|
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,
|
def get_realized_state(self, tier1_id, entity_type=None,
|
||||||
tenant=constants.POLICY_INFRA_TENANT,
|
tenant=constants.POLICY_INFRA_TENANT,
|
||||||
realization_info=None):
|
realization_info=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user