Add MTU support to network add/modify commands

Addresses #144
This commit is contained in:
Joshua Boniface 2021-10-09 18:05:26 -04:00
parent b0b0b75605
commit 7f074847c4
2 changed files with 36 additions and 7 deletions

View File

@ -100,7 +100,7 @@ def net_list(config, limit):
return False, response.json().get('message', '') return False, response.json().get('message', '')
def net_add(config, vni, description, nettype, domain, name_servers, ip4_network, ip4_gateway, ip6_network, ip6_gateway, dhcp4_flag, dhcp4_start, dhcp4_end): def net_add(config, vni, description, nettype, mtu, domain, name_servers, ip4_network, ip4_gateway, ip6_network, ip6_gateway, dhcp4_flag, dhcp4_start, dhcp4_end):
""" """
Add new network Add new network
@ -112,6 +112,7 @@ def net_add(config, vni, description, nettype, domain, name_servers, ip4_network
'vni': vni, 'vni': vni,
'description': description, 'description': description,
'nettype': nettype, 'nettype': nettype,
'mtu': mtu,
'domain': domain, 'domain': domain,
'name_servers': name_servers, 'name_servers': name_servers,
'ip4_network': ip4_network, 'ip4_network': ip4_network,
@ -132,7 +133,7 @@ def net_add(config, vni, description, nettype, domain, name_servers, ip4_network
return retstatus, response.json().get('message', '') return retstatus, response.json().get('message', '')
def net_modify(config, net, description, domain, name_servers, ip4_network, ip4_gateway, ip6_network, ip6_gateway, dhcp4_flag, dhcp4_start, dhcp4_end): def net_modify(config, net, description, mtu, domain, name_servers, ip4_network, ip4_gateway, ip6_network, ip6_gateway, dhcp4_flag, dhcp4_start, dhcp4_end):
""" """
Modify a network Modify a network
@ -143,6 +144,8 @@ def net_modify(config, net, description, domain, name_servers, ip4_network, ip4_
params = dict() params = dict()
if description is not None: if description is not None:
params['description'] = description params['description'] = description
if mtu is not None:
params['mtu'] = mtu
if domain is not None: if domain is not None:
params['domain'] = domain params['domain'] = domain
if name_servers is not None: if name_servers is not None:
@ -519,6 +522,7 @@ def format_info(config, network_information, long_output):
# Basic information # Basic information
ainformation.append('{}VNI:{} {}'.format(ansiprint.purple(), ansiprint.end(), network_information['vni'])) ainformation.append('{}VNI:{} {}'.format(ansiprint.purple(), ansiprint.end(), network_information['vni']))
ainformation.append('{}Type:{} {}'.format(ansiprint.purple(), ansiprint.end(), network_information['type'])) ainformation.append('{}Type:{} {}'.format(ansiprint.purple(), ansiprint.end(), network_information['type']))
ainformation.append('{}MTU:{} {}'.format(ansiprint.purple(), ansiprint.end(), network_information['mtu']))
ainformation.append('{}Description:{} {}'.format(ansiprint.purple(), ansiprint.end(), network_information['description'])) ainformation.append('{}Description:{} {}'.format(ansiprint.purple(), ansiprint.end(), network_information['description']))
if network_information['type'] == 'managed': if network_information['type'] == 'managed':
ainformation.append('{}Domain:{} {}'.format(ansiprint.purple(), ansiprint.end(), network_information['domain'])) ainformation.append('{}Domain:{} {}'.format(ansiprint.purple(), ansiprint.end(), network_information['domain']))
@ -575,6 +579,7 @@ def format_list(config, network_list):
net_vni_length = 5 net_vni_length = 5
net_description_length = 12 net_description_length = 12
net_nettype_length = 8 net_nettype_length = 8
net_mtu_length = 4
net_domain_length = 6 net_domain_length = 6
net_v6_flag_length = 6 net_v6_flag_length = 6
net_dhcp6_flag_length = 7 net_dhcp6_flag_length = 7
@ -589,6 +594,10 @@ def format_list(config, network_list):
_net_description_length = len(network_information['description']) + 1 _net_description_length = len(network_information['description']) + 1
if _net_description_length > net_description_length: if _net_description_length > net_description_length:
net_description_length = _net_description_length net_description_length = _net_description_length
# mtu column
_net_mtu_length = len(str(network_information['mtu'])) + 1
if _net_mtu_length > net_mtu_length:
net_mtu_length = _net_mtu_length
# domain column # domain column
_net_domain_length = len(network_information['domain']) + 1 _net_domain_length = len(network_information['domain']) + 1
if _net_domain_length > net_domain_length: if _net_domain_length > net_domain_length:
@ -599,7 +608,7 @@ def format_list(config, network_list):
bold=ansiprint.bold(), bold=ansiprint.bold(),
end_bold=ansiprint.end(), end_bold=ansiprint.end(),
networks_header_length=net_vni_length + net_description_length + 1, networks_header_length=net_vni_length + net_description_length + 1,
config_header_length=net_nettype_length + net_domain_length + net_v6_flag_length + net_dhcp6_flag_length + net_v4_flag_length + net_dhcp4_flag_length + 6, config_header_length=net_nettype_length + net_mtu_length + net_domain_length + net_v6_flag_length + net_dhcp6_flag_length + net_v4_flag_length + net_dhcp4_flag_length + 7,
networks_header='Networks ' + ''.join(['-' for _ in range(9, net_vni_length + net_description_length)]), networks_header='Networks ' + ''.join(['-' for _ in range(9, net_vni_length + net_description_length)]),
config_header='Config ' + ''.join(['-' for _ in range(7, net_nettype_length + net_domain_length + net_v6_flag_length + net_dhcp6_flag_length + net_v4_flag_length + net_dhcp4_flag_length + 5)])) config_header='Config ' + ''.join(['-' for _ in range(7, net_nettype_length + net_domain_length + net_v6_flag_length + net_dhcp6_flag_length + net_v4_flag_length + net_dhcp4_flag_length + 5)]))
) )
@ -607,6 +616,7 @@ def format_list(config, network_list):
{net_vni: <{net_vni_length}} \ {net_vni: <{net_vni_length}} \
{net_description: <{net_description_length}} \ {net_description: <{net_description_length}} \
{net_nettype: <{net_nettype_length}} \ {net_nettype: <{net_nettype_length}} \
{net_mtu: <{net_mtu_length}} \
{net_domain: <{net_domain_length}} \ {net_domain: <{net_domain_length}} \
{net_v6_flag: <{net_v6_flag_length}} \ {net_v6_flag: <{net_v6_flag_length}} \
{net_dhcp6_flag: <{net_dhcp6_flag_length}} \ {net_dhcp6_flag: <{net_dhcp6_flag_length}} \
@ -618,6 +628,7 @@ def format_list(config, network_list):
net_vni_length=net_vni_length, net_vni_length=net_vni_length,
net_description_length=net_description_length, net_description_length=net_description_length,
net_nettype_length=net_nettype_length, net_nettype_length=net_nettype_length,
net_mtu_length=net_mtu_length,
net_domain_length=net_domain_length, net_domain_length=net_domain_length,
net_v6_flag_length=net_v6_flag_length, net_v6_flag_length=net_v6_flag_length,
net_dhcp6_flag_length=net_dhcp6_flag_length, net_dhcp6_flag_length=net_dhcp6_flag_length,
@ -626,6 +637,7 @@ def format_list(config, network_list):
net_vni='VNI', net_vni='VNI',
net_description='Description', net_description='Description',
net_nettype='Type', net_nettype='Type',
net_mtu='MTU',
net_domain='Domain', net_domain='Domain',
net_v6_flag='IPv6', net_v6_flag='IPv6',
net_dhcp6_flag='DHCPv6', net_dhcp6_flag='DHCPv6',
@ -649,6 +661,7 @@ def format_list(config, network_list):
{net_vni: <{net_vni_length}} \ {net_vni: <{net_vni_length}} \
{net_description: <{net_description_length}} \ {net_description: <{net_description_length}} \
{net_nettype: <{net_nettype_length}} \ {net_nettype: <{net_nettype_length}} \
{net_mtu: <{net_mtu_length}} \
{net_domain: <{net_domain_length}} \ {net_domain: <{net_domain_length}} \
{v6_flag_colour}{net_v6_flag: <{net_v6_flag_length}}{colour_off} \ {v6_flag_colour}{net_v6_flag: <{net_v6_flag_length}}{colour_off} \
{dhcp6_flag_colour}{net_dhcp6_flag: <{net_dhcp6_flag_length}}{colour_off} \ {dhcp6_flag_colour}{net_dhcp6_flag: <{net_dhcp6_flag_length}}{colour_off} \
@ -660,6 +673,7 @@ def format_list(config, network_list):
net_vni_length=net_vni_length, net_vni_length=net_vni_length,
net_description_length=net_description_length, net_description_length=net_description_length,
net_nettype_length=net_nettype_length, net_nettype_length=net_nettype_length,
net_mtu_length=net_mtu_length,
net_domain_length=net_domain_length, net_domain_length=net_domain_length,
net_v6_flag_length=net_v6_flag_length, net_v6_flag_length=net_v6_flag_length,
net_dhcp6_flag_length=net_dhcp6_flag_length, net_dhcp6_flag_length=net_dhcp6_flag_length,
@ -668,6 +682,7 @@ def format_list(config, network_list):
net_vni=network_information['vni'], net_vni=network_information['vni'],
net_description=network_information['description'], net_description=network_information['description'],
net_nettype=network_information['type'], net_nettype=network_information['type'],
net_mtu=network_information['mtu'],
net_domain=network_information['domain'], net_domain=network_information['domain'],
net_v6_flag=v6_flag, net_v6_flag=v6_flag,
v6_flag_colour=v6_flag_colour, v6_flag_colour=v6_flag_colour,

View File

@ -1874,6 +1874,11 @@ def cli_network():
type=click.Choice(['managed', 'bridged']), type=click.Choice(['managed', 'bridged']),
help='Network type; managed networks control IP addressing; bridged networks are simple vLAN bridges. All subsequent options are unused for bridged networks.' help='Network type; managed networks control IP addressing; bridged networks are simple vLAN bridges. All subsequent options are unused for bridged networks.'
) )
@click.option(
'-m', '--mtu', 'mtu',
default='',
help='MTU of the network interfaces.'
)
@click.option( @click.option(
'-n', '--domain', 'domain', '-n', '--domain', 'domain',
default=None, default=None,
@ -1924,10 +1929,12 @@ def cli_network():
'vni' 'vni'
) )
@cluster_req @cluster_req
def net_add(vni, description, nettype, domain, ip_network, ip_gateway, ip6_network, ip6_gateway, dhcp_flag, dhcp_start, dhcp_end, name_servers): def net_add(vni, description, nettype, mtu, domain, ip_network, ip_gateway, ip6_network, ip6_gateway, dhcp_flag, dhcp_start, dhcp_end, name_servers):
""" """
Add a new virtual network with VXLAN identifier VNI. Add a new virtual network with VXLAN identifier VNI.
NOTE: The MTU must be equal to, or less than, the underlying device MTU (either the node 'bridge_mtu' for bridged networks, or the node 'cluster_mtu' minus 50 for managed networks). Is only required if the device MTU should be lower than the underlying physical device MTU for compatibility. If unset, defaults to the underlying device MTU which will be set explcitly when the network is added to the nodes.
Examples: Examples:
pvc network add 101 --description my-bridged-net --type bridged pvc network add 101 --description my-bridged-net --type bridged
@ -1941,7 +1948,7 @@ def net_add(vni, description, nettype, domain, ip_network, ip_gateway, ip6_netwo
IPv6 is fully supported with --ipnet6 and --gateway6 in addition to or instead of IPv4. PVC will configure DHCPv6 in a semi-managed configuration for the network if set. IPv6 is fully supported with --ipnet6 and --gateway6 in addition to or instead of IPv4. PVC will configure DHCPv6 in a semi-managed configuration for the network if set.
""" """
retcode, retmsg = pvc_network.net_add(config, vni, description, nettype, domain, name_servers, ip_network, ip_gateway, ip6_network, ip6_gateway, dhcp_flag, dhcp_start, dhcp_end) retcode, retmsg = pvc_network.net_add(config, vni, description, nettype, mtu, domain, name_servers, ip_network, ip_gateway, ip6_network, ip6_gateway, dhcp_flag, dhcp_start, dhcp_end)
cleanup(retcode, retmsg) cleanup(retcode, retmsg)
@ -1954,6 +1961,11 @@ def net_add(vni, description, nettype, domain, ip_network, ip_gateway, ip6_netwo
default=None, default=None,
help='Description of the network; must be unique and not contain whitespace.' help='Description of the network; must be unique and not contain whitespace.'
) )
@click.option(
'-m', '--mtu', 'mtu',
default=None,
help='MTU of the network interfaces.'
)
@click.option( @click.option(
'-n', '--domain', 'domain', '-n', '--domain', 'domain',
default=None, default=None,
@ -2004,16 +2016,18 @@ def net_add(vni, description, nettype, domain, ip_network, ip_gateway, ip6_netwo
'vni' 'vni'
) )
@cluster_req @cluster_req
def net_modify(vni, description, domain, name_servers, ip6_network, ip6_gateway, ip4_network, ip4_gateway, dhcp_flag, dhcp_start, dhcp_end): def net_modify(vni, description, mtu, domain, name_servers, ip6_network, ip6_gateway, ip4_network, ip4_gateway, dhcp_flag, dhcp_start, dhcp_end):
""" """
Modify details of virtual network VNI. All fields optional; only specified fields will be updated. Modify details of virtual network VNI. All fields optional; only specified fields will be updated.
NOTE: The MTU must be equal to, or less than, the underlying device MTU (either the node 'bridge_mtu' for bridged networks, or the node 'cluster_mtu' minus 50 for managed networks). Is only required if the device MTU should be lower than the underlying physical device MTU for compatibility. To reset an explicit MTU to the default underlying device MTU, specify '--mtu' with a quoted empty string argument.
Example: Example:
pvc network modify 1001 --gateway 10.1.1.1 --dhcp pvc network modify 1001 --gateway 10.1.1.1 --dhcp
""" """
retcode, retmsg = pvc_network.net_modify(config, vni, description, domain, name_servers, ip4_network, ip4_gateway, ip6_network, ip6_gateway, dhcp_flag, dhcp_start, dhcp_end) retcode, retmsg = pvc_network.net_modify(config, vni, description, mtu, domain, name_servers, ip4_network, ip4_gateway, ip6_network, ip6_gateway, dhcp_flag, dhcp_start, dhcp_end)
cleanup(retcode, retmsg) cleanup(retcode, retmsg)