Skip to content

Commit

Permalink
Merge pull request #2 from nuagenetworks/dev
Browse files Browse the repository at this point in the history
Improvements related to dhcp flag and shared subnets
  • Loading branch information
dieterdm committed Jul 3, 2017
2 parents 6b6f84a + 655098d commit 71504b4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 40 deletions.
95 changes: 56 additions & 39 deletions nuageneutronsync/operations/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,43 @@ def get_cidr_and_gateway(self, nuage_subnet):
# shared subnet
shared_network = vspk.NUSharedNetworkResource(id=nuage_subnet.associated_shared_network_resource_id)
shared_network.fetch()
if shared_network.dhcp_managed:
if shared_network.type == "PUBLIC":
# shared L3 subnet
address = shared_network.address
netmask = shared_network.netmask
gateway = shared_network.gateway
enable_dhcp = True
else:
address = self.cfg.get_unmanged_networks_subnet()
netmask = self.cfg.get_unmanged_networks_netmask()
gateway = None
elif nuage_subnet.parent_type != "enterprise" or nuage_subnet.dhcp_managed is True:
# L3 subnet or (L2 and DHCP managed)
# note: dhcp_managed parameter only exist for L3 subnet
# shared L2 subnet
if shared_network.dhcp_managed:
enable_dhcp = True
address = shared_network.address
netmask = shared_network.netmask
else:
address = self.cfg.get_unmanaged_networks_subnet()
netmask = self.cfg.get_unmanaged_networks_netmask()
enable_dhcp = False
# gateway = None if dhcp option does not exist
gateway = shared_network.dhcp_options.get_first(filter="type=='03'")
elif nuage_subnet.parent_type != "enterprise":
# L3 subnet
address = nuage_subnet.address
netmask = nuage_subnet.netmask
gateway = nuage_subnet.gateway
enable_dhcp = True
elif nuage_subnet.dhcp_managed is True:
# managed L2 (dhcp_managed attribute only exist for l2domain)
address = nuage_subnet.address
netmask = nuage_subnet.netmask
# gateway = None if dhcp option does not exist
gateway = nuage_subnet.dhcp_options.get_first(filter="type=='03'")
enable_dhcp = True
else:
# unmanaged L2
address = self.cfg.get_unmanaged_networks_subnet()
netmask = self.cfg.get_unmanaged_networks_netmask()
gateway = None
enable_dhcp = False

# generate subnet
cidr = self.net_nm_sanitizer(address, netmask)
Expand All @@ -141,26 +159,9 @@ def get_cidr_and_gateway(self, nuage_subnet):
self.logger.error("Invalid cidr ({0}) set in metadata of nuage subnet {1}. Ignoring"
.format(metadata_cidr.blob, nuage_subnet.id))
self.logger.error(str(e))
return cidr, gateway
return cidr, gateway, enable_dhcp

def add_neutron_subnet(self, nuage_subnet, project, enterprise):
# Ignore shared subnets if not enabled in the configuration file
if nuage_subnet.associated_shared_network_resource_id is not None and \
not self.cfg.get_value('sync', 'sync_shared_subnets'):
self.logger.debug("Ignoring vsd subnet {0}. Sync of shared subnets is disabled in configuration.".format(
nuage_subnet['ID']))
return

# ignore L3 shared subnet with nothing attached
if nuage_subnet.parent_type != "enterprise" and nuage_subnet.address is None \
and nuage_subnet.associated_shared_network_resource_id is None:
if self.cfg.get_value('sync', 'sync_shared_subnets'):
self.logger.debug("Ignoring vsd subnet {0}. Sync of shared subnets is disabled in configuration."
.format(nuage_subnet['ID']))
else:
self.logger.info("vsd subnet {0} is a shared L3 subnet without the subnet attached. Ignoring")
return

net_name = self.calc_subnetname(nuage_subnet)

# create network
Expand All @@ -180,7 +181,7 @@ def add_neutron_subnet(self, nuage_subnet, project, enterprise):
self.logger.error(str(e))
return

cidr, gateway = self.get_cidr_and_gateway(nuage_subnet)
cidr, gateway, enable_dhcp = self.get_cidr_and_gateway(nuage_subnet)

body_subnet = {
"subnets": [
Expand All @@ -196,9 +197,9 @@ def add_neutron_subnet(self, nuage_subnet, project, enterprise):
]
}

if gateway is None:
body_subnet['subnets'][0]['enable_dhcp'] = False
else:
body_subnet['subnets'][0]['enable_dhcp'] = enable_dhcp

if gateway is not None:
body_subnet['subnets'][0]['gateway_ip'] = gateway

try:
Expand Down Expand Up @@ -232,16 +233,15 @@ def check_if_correct(self, nuage_subnet, openstack_subnet_id):
openstack_subnet['name'],
subnet_name))

cidr, gateway = self.get_cidr_and_gateway(nuage_subnet)
if gateway is None:
if openstack_subnet['enable_dhcp'] is True:
mapping_correct = False
self.logger.debug("DHCP removed in subnet {0} (\"{1}\")".format(nuage_subnet.id, subnet_name))
else:
if openstack_subnet['gateway_ip'] != gateway:
mapping_correct = False
self.logger.debug("Gateway IP of subnet {0} (\"{1}\") changed to {2}".
format(nuage_subnet.id, subnet_name, gateway))
cidr, gateway, enable_dhcp = self.get_cidr_and_gateway(nuage_subnet)
if enable_dhcp != openstack_subnet['enable_dhcp']:
mapping_correct = False
self.logger.debug("DHCP not correct in subnet {0} (\"{1}\")".format(nuage_subnet.id, subnet_name))

if openstack_subnet['gateway_ip'] != gateway:
mapping_correct = False
self.logger.debug("Gateway IP of subnet {0} (\"{1}\") changed to {2}".
format(nuage_subnet.id, subnet_name, gateway))

if cidr != openstack_subnet['cidr']:
self.logger.debug("CIDR of subnet {0} (\"{1}\") changed to {2}".format(nuage_subnet.id, subnet_name, cidr))
Expand Down Expand Up @@ -275,6 +275,23 @@ def sync_once_enterprise(self, enterprise, project):
self.logger.error(str(e))

def sync_subnet(self, enterprise, nuage_subnet, project, subnet_mappings):
# Ignore shared subnets if not enabled in the configuration file
if nuage_subnet.associated_shared_network_resource_id is not None and \
not self.cfg.get_boolean('sync', 'sync_shared_subnets'):
self.logger.debug("Ignoring vsd subnet {0}. Sync of shared subnets is disabled in configuration.".format(
nuage_subnet.id))
return

# ignore L3 shared subnet with nothing attached
if nuage_subnet.parent_type != "enterprise" and nuage_subnet.address is None \
and nuage_subnet.associated_shared_network_resource_id is None:
if self.cfg.get_boolean('sync', 'sync_shared_subnets'):
self.logger.debug("Ignoring vsd subnet {0}. Sync of shared subnets is disabled in configuration."
.format(nuage_subnet.id))
else:
self.logger.info("vsd subnet {0} is a shared L3 subnet without the subnet attached. Ignoring")
return

synced = False
if nuage_subnet.id in subnet_mappings:
synced = True
Expand Down
3 changes: 3 additions & 0 deletions nuageneutronsync/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def __init__(self, path, logger):
def get_value(self, section, name):
return self.cfg.get(section, name)

def get_boolean(self, section, name):
return self.cfg.getboolean(section, name)

def get_log_config(self):
# default values
enable_rotate = False
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='nuageneutronsync',
version='1.0.0',
version='1.0.1',
packages=['nuageneutronsync', 'nuageneutronsync.utils', 'nuageneutronsync.operations'],
data_files=[('/etc/nuage-neutron-sync', ['config/nuage-neutron-sync.conf']),
('/etc/init.d', ['config/nuage-neutron-syncd'])],
Expand Down

0 comments on commit 71504b4

Please sign in to comment.