Browse Source

Add DHCP Config build and T1 Adv Rule Update

- Expose Building DHCP Config V4 and V6 in NsxPolicyTier1SegmentApi
- Update update_advertisement_rules to allow batch removal of existings
  rules via prefix matching even if no new rules are to be added

Change-Id: I215630fb2af41d71431774d88129c08c4aeac904
changes/04/756604/2
Shawn Wang 2 years ago
parent
commit
a8732a94af
No known key found for this signature in database
GPG Key ID: C98A86CC967E89A7
  1. 44
      vmware_nsxlib/tests/unit/v3/policy/test_resources.py
  2. 38
      vmware_nsxlib/v3/policy/core_resources.py

44
vmware_nsxlib/tests/unit/v3/policy/test_resources.py

@ -3414,6 +3414,30 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
tenant=TEST_TENANT)
self.assert_called_with_def(api_call, expected_def)
def test_update_advertisement_rules_remove(self):
tier1_id = '111'
old_rule1 = 'old1'
old_rule2 = 'old2'
get_retval = {
'id': tier1_id,
'route_advertisement_rules': [
{'name': old_rule1},
{'name': old_rule2}]}
with mock.patch.object(self.policy_api,
"get",
return_value=get_retval),\
mock.patch.object(self.policy_api,
'create_or_update') as api_call:
self.resourceApi.update_advertisement_rules(
tier1_id, None, name_prefix='old1', tenant=TEST_TENANT)
expected_def = core_defs.Tier1Def(
tier1_id=tier1_id,
route_advertisement_rules=[
{'name': old_rule2}],
tenant=TEST_TENANT)
self.assert_called_with_def(api_call, expected_def)
def test_create_with_unsupported_attr(self):
name = 'test'
description = 'test_version_support'
@ -4084,6 +4108,26 @@ class TestPolicyTier1Segment(NsxPolicyLibTestCase):
self.assertEqual(gateway_address, subnet.gateway_address)
self.assertEqual(dhcp_ranges, subnet.dhcp_ranges)
def test_build_dhcp_config_v4(self):
server_address = "10.0.0.2/24"
dns_servers = ["10.0.0.3/24"]
lease_time = 36600
dhcp_config_v4 = self.resourceApi.build_dhcp_config_v4(
server_address, dns_servers=dns_servers, lease_time=lease_time)
self.assertEqual(server_address, dhcp_config_v4.server_address)
self.assertEqual(dns_servers, dhcp_config_v4.dns_servers)
self.assertEqual(lease_time, dhcp_config_v4.lease_time)
def test_build_dhcp_config_v6(self):
server_address = "2000::01ab/64"
dns_servers = ["2000::01ac/64"]
lease_time = 36600
dhcp_config_v6 = self.resourceApi.build_dhcp_config_v6(
server_address, dns_servers=dns_servers, lease_time=lease_time)
self.assertEqual(server_address, dhcp_config_v6.server_address)
self.assertEqual(dns_servers, dhcp_config_v6.dns_servers)
self.assertEqual(lease_time, dhcp_config_v6.lease_time)
class TestPolicySegment(NsxPolicyLibTestCase):

38
vmware_nsxlib/v3/policy/core_resources.py

@ -1129,7 +1129,8 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
route_advertisement_types=route_advertisement_types,
subnets=subnets)
def update_advertisement_rules(self, tier1_id, rules, name_prefix=None,
def update_advertisement_rules(self, tier1_id, rules=None,
name_prefix=None,
tenant=constants.POLICY_INFRA_TENANT):
"""Update the router advertisement rules
@ -1147,8 +1148,9 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
if (not rule.get('name') or
not rule['name'].startswith(name_prefix)):
new_rules.append(rule)
# add new rules
new_rules.extend(rules)
# add new rules if provided
if rules:
new_rules.extend(rules)
else:
new_rules = rules
@ -1856,8 +1858,19 @@ class NsxPolicyTier1SegmentApi(NsxPolicyResourceBase):
def entry_def(self):
return core_defs.Tier1SegmentDef
def build_subnet(self, gateway_address, dhcp_ranges=None):
return core_defs.Subnet(gateway_address, dhcp_ranges)
def build_subnet(self, gateway_address, dhcp_ranges=None,
dhcp_config=None):
return core_defs.Subnet(gateway_address, dhcp_ranges, dhcp_config)
def build_dhcp_config_v4(self, server_address, dns_servers=None,
lease_time=None, options=None):
return core_defs.SegmentDhcpConfigV4(server_address, dns_servers,
lease_time, options)
def build_dhcp_config_v6(self, server_address, dns_servers=None,
lease_time=None, domain_names=None):
return core_defs.SegmentDhcpConfigV6(server_address, dns_servers,
lease_time, domain_names)
def create_or_overwrite(self, name, tier1_id,
segment_id=None,
@ -1935,8 +1948,19 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase):
def entry_def(self):
return core_defs.SegmentDef
def build_subnet(self, gateway_address, dhcp_ranges=None):
return core_defs.Subnet(gateway_address, dhcp_ranges)
def build_subnet(self, gateway_address, dhcp_ranges=None,
dhcp_config=None):
return core_defs.Subnet(gateway_address, dhcp_ranges, dhcp_config)
def build_dhcp_config_v4(self, server_address, dns_servers=None,
lease_time=None, options=None):
return core_defs.SegmentDhcpConfigV4(server_address, dns_servers,
lease_time, options)
def build_dhcp_config_v6(self, server_address, dns_servers=None,
lease_time=None, domain_names=None):
return core_defs.SegmentDhcpConfigV6(server_address, dns_servers,
lease_time, domain_names)
def create_or_overwrite(self, name,
segment_id=None,

Loading…
Cancel
Save