diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index 3b9430eb..ad09381b 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -5005,6 +5005,34 @@ class TestPolicyIpPool(NsxPolicyLibTestCase): start_ip=start_ip) self.assert_called_with_def(api_call, expected_def) + def test_allocate_block_subnet_sync_realization(self): + ip_pool_id = '111' + ip_block_id = 'block-id' + size = 256 + ip_subnet_id = 'subnet-id' + start_ip = '192.168.1.0' + sync_realization = True + + with mock.patch.object( + self.policy_api, "create_or_update") as api_call, \ + mock.patch.object(self.resourceApi, 'version', + nsx_constants.NSX_VERSION_4_1_1): + self.resourceApi.allocate_block_subnet( + ip_pool_id, ip_block_id, size, ip_subnet_id, + tenant=TEST_TENANT, start_ip=start_ip, + sync_realization=sync_realization) + + expected_def = core_defs.IpPoolBlockSubnetDef( + nsx_version=nsx_constants.NSX_VERSION_4_1_1, + ip_pool_id=ip_pool_id, + ip_block_id=ip_block_id, + ip_subnet_id=ip_subnet_id, + subnet_size='%s' % size, + tenant=TEST_TENANT, + start_ip=start_ip, + sync_realization=sync_realization) + self.assert_called_with_def(api_call, expected_def) + def test_allocate_block_subnet_with_unsupported_attribute(self): ip_pool_id = '111' ip_block_id = 'block-id' diff --git a/vmware_nsxlib/v3/nsx_constants.py b/vmware_nsxlib/v3/nsx_constants.py index fb7dbd9f..df4857fa 100644 --- a/vmware_nsxlib/v3/nsx_constants.py +++ b/vmware_nsxlib/v3/nsx_constants.py @@ -166,6 +166,7 @@ NSX_VERSION_3_2_0 = '3.2.0' NSX_VERSION_3_2_1 = '3.2.1' NSX_VERSION_4_0_0 = '4.0.0' NSX_VERSION_4_1_0 = '4.1.0' +NSX_VERSION_4_1_1 = '4.1.1' # Features available depending on the NSX Manager backend version FEATURE_MAC_LEARNING = 'MAC Learning' diff --git a/vmware_nsxlib/v3/policy/core_defs.py b/vmware_nsxlib/v3/policy/core_defs.py index 4f37e370..a83ab68b 100644 --- a/vmware_nsxlib/v3/policy/core_defs.py +++ b/vmware_nsxlib/v3/policy/core_defs.py @@ -1522,6 +1522,15 @@ class IpPoolDef(ResourceDef): def path_defs(self): return (TenantDef,) + @property + def version_dependant_attr_map(self): + return {'sync_realization': nsx_constants.NSX_VERSION_4_1_1} + + def get_obj_dict(self): + body = super(IpPoolDef, self).get_obj_dict() + self._set_attr_if_supported(body, 'sync_realization') + return body + class IpPoolAllocationDef(ResourceDef): '''Infra IpPoolAllocation''' @@ -1590,6 +1599,8 @@ class IpPoolBlockSubnetDef(IpPoolSubnetDef): # Attrs supported from NSX 4.1.0 self._set_attrs_if_supported(body, ['subnet_size', 'allocation_range']) + # Attrs supported from NSX 4.1.1 + self._set_attr_if_supported(body, 'sync_realization') # Attribute "subnet size" is replacement for "size" attribute # thus, removing redundancy if 'subnet_size' in body: @@ -1598,9 +1609,11 @@ class IpPoolBlockSubnetDef(IpPoolSubnetDef): @property def version_dependant_attr_map(self): - return {'start_ip': nsx_constants.NSX_VERSION_3_0_0, - 'subnet_size': nsx_constants.NSX_VERSION_4_1_0, - 'allocation_range': nsx_constants.NSX_VERSION_4_1_0} + return { + 'start_ip': nsx_constants.NSX_VERSION_3_0_0, + 'subnet_size': nsx_constants.NSX_VERSION_4_1_0, + 'allocation_range': nsx_constants.NSX_VERSION_4_1_0, + 'sync_realization': nsx_constants.NSX_VERSION_4_1_1} class IpPoolStaticSubnetDef(IpPoolSubnetDef): diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 351a806a..964b6258 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -3346,14 +3346,18 @@ class NsxPolicyIpPoolApi(NsxPolicyResourceBase): ip_pool_id=None, description=IGNORE, tags=IGNORE, - tenant=constants.POLICY_INFRA_TENANT): + tenant=constants.POLICY_INFRA_TENANT, + sync_realization=False): ip_pool_id = self._init_obj_uuid(ip_pool_id) + ip_pool_def = self._init_def(ip_pool_id=ip_pool_id, name=name, description=description, tags=tags, - tenant=tenant) + tenant=tenant, + sync_realization=sync_realization) + self._create_or_store(ip_pool_def) return ip_pool_id @@ -3428,8 +3432,11 @@ class NsxPolicyIpPoolApi(NsxPolicyResourceBase): name=IGNORE, description=IGNORE, tags=IGNORE, tenant=constants.POLICY_INFRA_TENANT, start_ip=IGNORE, v6_allocation_range=IGNORE, - force=False): + force=False, sync_realization=False): ip_subnet_id = self._init_obj_uuid(ip_subnet_id) + # suppose all NSXT 4.1.0 build support sync_realization + # else we need to check if it supports sync_realization + # it's just a temp patch args = self._get_user_args( ip_pool_id=ip_pool_id, ip_block_id=ip_block_id, @@ -3442,7 +3449,8 @@ class NsxPolicyIpPoolApi(NsxPolicyResourceBase): tenant=tenant, start_ip=start_ip, subnet_size=str(size), - allocation_range=v6_allocation_range) + allocation_range=v6_allocation_range, + sync_realization=sync_realization) ip_subnet_def = core_defs.IpPoolBlockSubnetDef( nsx_version=self.version, **args)