Set empty values in segment subnet when not set

This will allow updating subnets witout DHCP settings

Change-Id: I78e795ca9228d92a5d1eb77fa11b842c0f9f145c
This commit is contained in:
asarfaty 2020-02-19 14:09:20 +02:00 committed by Adit Sarfaty
parent 3a4fe9b6bb
commit 889037c399
1 changed files with 8 additions and 5 deletions

View File

@ -26,8 +26,6 @@ from vmware_nsxlib.v3 import utils
LOG = logging.getLogger(__name__)
LOG = logging.getLogger(__name__)
TENANTS_PATH_PATTERN = "%s/"
DOMAINS_PATH_PATTERN = TENANTS_PATH_PATTERN + "domains/"
IP_BLOCKS_PATH_PATTERN = TENANTS_PATH_PATTERN + "ip-blocks/"
@ -785,15 +783,20 @@ class Subnet(object):
self.dhcp_ranges = dhcp_ranges
self.dhcp_config = dhcp_config
def get_obj_dict(self):
def get_obj_dict(self, nsx_version):
body = {'gateway_address': self.gateway_address}
if self.dhcp_ranges:
body['dhcp_ranges'] = self.dhcp_ranges
if self.dhcp_config:
if self.dhcp_config is not None:
body['dhcp_config'] = (
self.dhcp_config.get_obj_dict()
if isinstance(self.dhcp_config, SegmentDhcpConfig)
else self.dhcp_config)
elif (version.LooseVersion(nsx_version) >=
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
body['dhcp_config'] = None
return body
@ -866,7 +869,7 @@ class BaseSegmentDef(ResourceDef):
if self.has_attr('subnets'):
subnets = []
if self.get_attr('subnets'):
subnets = [subnet.get_obj_dict()
subnets = [subnet.get_obj_dict(self.nsx_version)
for subnet in self.get_attr('subnets')]
self._set_attr_if_specified(body, 'subnets', value=subnets)