Add MTU to network creation/modification

Addresses #144
This commit is contained in:
Joshua Boniface 2021-10-09 17:43:56 -04:00
parent 3690a2c1e0
commit 24de0f4189
4 changed files with 54 additions and 6 deletions

View File

@ -2109,6 +2109,9 @@ class API_Network_Root(Resource):
enum: enum:
- managed - managed
- bridged - bridged
mtu:
type: integer
description: The MTU of the network, if set; empty otherwise
domain: domain:
type: string type: string
description: The DNS domain of the network ("managed" networks only) description: The DNS domain of the network ("managed" networks only)
@ -2169,6 +2172,7 @@ class API_Network_Root(Resource):
{'name': 'vni', 'required': True}, {'name': 'vni', 'required': True},
{'name': 'description', 'required': True}, {'name': 'description', 'required': True},
{'name': 'nettype', 'choices': ('managed', 'bridged'), 'helptext': 'A valid nettype must be specified', 'required': True}, {'name': 'nettype', 'choices': ('managed', 'bridged'), 'helptext': 'A valid nettype must be specified', 'required': True},
{'name': 'mtu'},
{'name': 'domain'}, {'name': 'domain'},
{'name': 'name_servers'}, {'name': 'name_servers'},
{'name': 'ip4_network'}, {'name': 'ip4_network'},
@ -2205,6 +2209,10 @@ class API_Network_Root(Resource):
enum: enum:
- managed - managed
- bridged - bridged
- in: query
name: mtu
type: integer
description: The MTU of the network; defaults to the underlying interface MTU if not set
- in: query - in: query
name: domain name: domain
type: string type: string
@ -2261,6 +2269,7 @@ class API_Network_Root(Resource):
reqargs.get('vni', None), reqargs.get('vni', None),
reqargs.get('description', None), reqargs.get('description', None),
reqargs.get('nettype', None), reqargs.get('nettype', None),
reqargs.get('mtu', ''),
reqargs.get('domain', None), reqargs.get('domain', None),
name_servers, name_servers,
reqargs.get('ip4_network', None), reqargs.get('ip4_network', None),
@ -2301,6 +2310,7 @@ class API_Network_Element(Resource):
@RequestParser([ @RequestParser([
{'name': 'description', 'required': True}, {'name': 'description', 'required': True},
{'name': 'nettype', 'choices': ('managed', 'bridged'), 'helptext': 'A valid nettype must be specified', 'required': True}, {'name': 'nettype', 'choices': ('managed', 'bridged'), 'helptext': 'A valid nettype must be specified', 'required': True},
{'name': 'mtu'},
{'name': 'domain'}, {'name': 'domain'},
{'name': 'name_servers'}, {'name': 'name_servers'},
{'name': 'ip4_network'}, {'name': 'ip4_network'},
@ -2332,6 +2342,10 @@ class API_Network_Element(Resource):
enum: enum:
- managed - managed
- bridged - bridged
- in: query
name: mtu
type: integer
description: The MTU of the network; defaults to the underlying interface MTU if not set
- in: query - in: query
name: domain name: domain
type: string type: string
@ -2388,6 +2402,7 @@ class API_Network_Element(Resource):
reqargs.get('vni', None), reqargs.get('vni', None),
reqargs.get('description', None), reqargs.get('description', None),
reqargs.get('nettype', None), reqargs.get('nettype', None),
reqargs.get('mtu', ''),
reqargs.get('domain', None), reqargs.get('domain', None),
name_servers, name_servers,
reqargs.get('ip4_network', None), reqargs.get('ip4_network', None),
@ -2401,6 +2416,7 @@ class API_Network_Element(Resource):
@RequestParser([ @RequestParser([
{'name': 'description'}, {'name': 'description'},
{'name': 'mtu'},
{'name': 'domain'}, {'name': 'domain'},
{'name': 'name_servers'}, {'name': 'name_servers'},
{'name': 'ip4_network'}, {'name': 'ip4_network'},
@ -2424,6 +2440,10 @@ class API_Network_Element(Resource):
name: description name: description
type: string type: string
description: The description of the network description: The description of the network
- in: query
name: mtu
type: integer
description: The MTU of the network
- in: query - in: query
name: domain name: domain
type: string type: string
@ -2484,6 +2504,7 @@ class API_Network_Element(Resource):
return api_helper.net_modify( return api_helper.net_modify(
vni, vni,
reqargs.get('description', None), reqargs.get('description', None),
reqargs.get('mtu', None),
reqargs.get('domain', None), reqargs.get('domain', None),
name_servers, name_servers,
reqargs.get('ip4_network', None), reqargs.get('ip4_network', None),

View File

@ -927,7 +927,7 @@ def net_list(zkhandler, limit=None, is_fuzzy=True):
@ZKConnection(config) @ZKConnection(config)
def net_add(zkhandler, vni, description, nettype, domain, name_servers, def net_add(zkhandler, vni, description, nettype, mtu, domain, name_servers,
ip4_network, ip4_gateway, ip6_network, ip6_gateway, ip4_network, ip4_gateway, ip6_network, ip6_gateway,
dhcp4_flag, dhcp4_start, dhcp4_end): dhcp4_flag, dhcp4_start, dhcp4_end):
""" """
@ -935,7 +935,7 @@ def net_add(zkhandler, vni, description, nettype, domain, name_servers,
""" """
if dhcp4_flag: if dhcp4_flag:
dhcp4_flag = bool(strtobool(dhcp4_flag)) dhcp4_flag = bool(strtobool(dhcp4_flag))
retflag, retdata = pvc_network.add_network(zkhandler, vni, description, nettype, domain, name_servers, retflag, retdata = pvc_network.add_network(zkhandler, vni, description, nettype, mtu, domain, name_servers,
ip4_network, ip4_gateway, ip6_network, ip6_gateway, ip4_network, ip4_gateway, ip6_network, ip6_gateway,
dhcp4_flag, dhcp4_start, dhcp4_end) dhcp4_flag, dhcp4_start, dhcp4_end)
@ -951,7 +951,7 @@ def net_add(zkhandler, vni, description, nettype, domain, name_servers,
@ZKConnection(config) @ZKConnection(config)
def net_modify(zkhandler, vni, description, domain, name_servers, def net_modify(zkhandler, vni, description, mtu, domain, name_servers,
ip4_network, ip4_gateway, ip4_network, ip4_gateway,
ip6_network, ip6_gateway, ip6_network, ip6_gateway,
dhcp4_flag, dhcp4_start, dhcp4_end): dhcp4_flag, dhcp4_start, dhcp4_end):
@ -960,7 +960,7 @@ def net_modify(zkhandler, vni, description, domain, name_servers,
""" """
if dhcp4_flag is not None: if dhcp4_flag is not None:
dhcp4_flag = bool(strtobool(dhcp4_flag)) dhcp4_flag = bool(strtobool(dhcp4_flag))
retflag, retdata = pvc_network.modify_network(zkhandler, vni, description, domain, name_servers, retflag, retdata = pvc_network.modify_network(zkhandler, vni, description, mtu, domain, name_servers,
ip4_network, ip4_gateway, ip6_network, ip6_gateway, ip4_network, ip4_gateway, ip6_network, ip6_gateway,
dhcp4_flag, dhcp4_start, dhcp4_end) dhcp4_flag, dhcp4_start, dhcp4_end)

View File

@ -135,6 +135,7 @@ def getNetworkACLs(zkhandler, vni, _direction):
def getNetworkInformation(zkhandler, vni): def getNetworkInformation(zkhandler, vni):
description = zkhandler.read(('network', vni)) description = zkhandler.read(('network', vni))
nettype = zkhandler.read(('network.type', vni)) nettype = zkhandler.read(('network.type', vni))
mtu = zkhandler.read(('network.mtu', vni))
domain = zkhandler.read(('network.domain', vni)) domain = zkhandler.read(('network.domain', vni))
name_servers = zkhandler.read(('network.nameservers', vni)) name_servers = zkhandler.read(('network.nameservers', vni))
ip6_network = zkhandler.read(('network.ip6.network', vni)) ip6_network = zkhandler.read(('network.ip6.network', vni))
@ -151,6 +152,7 @@ def getNetworkInformation(zkhandler, vni):
'vni': int(vni), 'vni': int(vni),
'description': description, 'description': description,
'type': nettype, 'type': nettype,
'mtu': mtu,
'domain': domain, 'domain': domain,
'name_servers': name_servers.split(','), 'name_servers': name_servers.split(','),
'ip6': { 'ip6': {
@ -235,7 +237,7 @@ def isValidIP(ipaddr):
# #
# Direct functions # Direct functions
# #
def add_network(zkhandler, vni, description, nettype, def add_network(zkhandler, vni, description, nettype, mtu,
domain, name_servers, ip4_network, ip4_gateway, ip6_network, ip6_gateway, domain, name_servers, ip4_network, ip4_gateway, ip6_network, ip6_gateway,
dhcp4_flag, dhcp4_start, dhcp4_end): dhcp4_flag, dhcp4_start, dhcp4_end):
# Ensure start and end DHCP ranges are set if the flag is set # Ensure start and end DHCP ranges are set if the flag is set
@ -267,6 +269,7 @@ def add_network(zkhandler, vni, description, nettype,
result = zkhandler.write([ result = zkhandler.write([
(('network', vni), description), (('network', vni), description),
(('network.type', vni), nettype), (('network.type', vni), nettype),
(('network.mtu', vni), mtu),
(('network.domain', vni), domain), (('network.domain', vni), domain),
(('network.nameservers', vni), name_servers), (('network.nameservers', vni), name_servers),
(('network.ip6.network', vni), ip6_network), (('network.ip6.network', vni), ip6_network),
@ -290,13 +293,15 @@ def add_network(zkhandler, vni, description, nettype,
return False, 'ERROR: Failed to add network.' return False, 'ERROR: Failed to add network.'
def modify_network(zkhandler, vni, description=None, domain=None, name_servers=None, def modify_network(zkhandler, vni, description=None, mtu=None, domain=None, name_servers=None,
ip4_network=None, ip4_gateway=None, ip6_network=None, ip6_gateway=None, ip4_network=None, ip4_gateway=None, ip6_network=None, ip6_gateway=None,
dhcp4_flag=None, dhcp4_start=None, dhcp4_end=None): dhcp4_flag=None, dhcp4_start=None, dhcp4_end=None):
# Add the modified parameters to Zookeeper # Add the modified parameters to Zookeeper
update_data = list() update_data = list()
if description is not None: if description is not None:
update_data.append((('network', vni), description)) update_data.append((('network', vni), description))
if mtu is not None:
update_data.append((('mtu', vni), mtu))
if domain is not None: if domain is not None:
update_data.append((('network.domain', vni), domain)) update_data.append((('network.domain', vni), domain))
if name_servers is not None: if name_servers is not None:

View File

@ -364,6 +364,10 @@
}, },
"type": "object" "type": "object"
}, },
"mtu": {
"description": "The MTU of the network, if set; empty otherwise",
"type": "integer"
},
"name_servers": { "name_servers": {
"description": "The configured DNS nameservers of the network for NS records (\"managed\" networks only)", "description": "The configured DNS nameservers of the network for NS records (\"managed\" networks only)",
"items": { "items": {
@ -1765,6 +1769,12 @@
"required": true, "required": true,
"type": "string" "type": "string"
}, },
{
"description": "The MTU of the network; defaults to the underlying interface MTU if not set",
"in": "query",
"name": "mtu",
"type": "integer"
},
{ {
"description": "The DNS domain of the network (\"managed\" networks only)", "description": "The DNS domain of the network (\"managed\" networks only)",
"in": "query", "in": "query",
@ -1910,6 +1920,12 @@
"required": true, "required": true,
"type": "string" "type": "string"
}, },
{
"description": "The MTU of the network; defaults to the underlying interface MTU if not set",
"in": "query",
"name": "mtu",
"type": "integer"
},
{ {
"description": "The DNS domain of the network (\"managed\" networks only)", "description": "The DNS domain of the network (\"managed\" networks only)",
"in": "query", "in": "query",
@ -1993,6 +2009,12 @@
"name": "description", "name": "description",
"type": "string" "type": "string"
}, },
{
"description": "The MTU of the network",
"in": "query",
"name": "mtu",
"type": "integer"
},
{ {
"description": "The DNS domain of the network (\"managed\" networks only)", "description": "The DNS domain of the network (\"managed\" networks only)",
"in": "query", "in": "query",