diff --git a/client-cli/pvc/cli_lib/network.py b/client-cli/pvc/cli_lib/network.py index 72bd6555..2ad049e1 100644 --- a/client-cli/pvc/cli_lib/network.py +++ b/client-cli/pvc/cli_lib/network.py @@ -100,7 +100,7 @@ def net_list(config, limit): 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 @@ -112,6 +112,7 @@ def net_add(config, vni, description, nettype, domain, name_servers, ip4_network 'vni': vni, 'description': description, 'nettype': nettype, + 'mtu': mtu, 'domain': domain, 'name_servers': name_servers, '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', '') -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 @@ -143,6 +144,8 @@ def net_modify(config, net, description, domain, name_servers, ip4_network, ip4_ params = dict() if description is not None: params['description'] = description + if mtu is not None: + params['mtu'] = mtu if domain is not None: params['domain'] = domain if name_servers is not None: @@ -519,6 +522,7 @@ def format_info(config, network_information, long_output): # Basic information ainformation.append('{}VNI:{} {}'.format(ansiprint.purple(), ansiprint.end(), network_information['vni'])) 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'])) if network_information['type'] == 'managed': 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_description_length = 12 net_nettype_length = 8 + net_mtu_length = 4 net_domain_length = 6 net_v6_flag_length = 6 net_dhcp6_flag_length = 7 @@ -589,6 +594,10 @@ def format_list(config, network_list): _net_description_length = len(network_information['description']) + 1 if _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 _net_domain_length = len(network_information['domain']) + 1 if _net_domain_length > net_domain_length: @@ -599,7 +608,7 @@ def format_list(config, network_list): bold=ansiprint.bold(), end_bold=ansiprint.end(), 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)]), 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_description: <{net_description_length}} \ {net_nettype: <{net_nettype_length}} \ +{net_mtu: <{net_mtu_length}} \ {net_domain: <{net_domain_length}} \ {net_v6_flag: <{net_v6_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_description_length=net_description_length, net_nettype_length=net_nettype_length, + net_mtu_length=net_mtu_length, net_domain_length=net_domain_length, net_v6_flag_length=net_v6_flag_length, net_dhcp6_flag_length=net_dhcp6_flag_length, @@ -626,6 +637,7 @@ def format_list(config, network_list): net_vni='VNI', net_description='Description', net_nettype='Type', + net_mtu='MTU', net_domain='Domain', net_v6_flag='IPv6', net_dhcp6_flag='DHCPv6', @@ -649,6 +661,7 @@ def format_list(config, network_list): {net_vni: <{net_vni_length}} \ {net_description: <{net_description_length}} \ {net_nettype: <{net_nettype_length}} \ +{net_mtu: <{net_mtu_length}} \ {net_domain: <{net_domain_length}} \ {v6_flag_colour}{net_v6_flag: <{net_v6_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_description_length=net_description_length, net_nettype_length=net_nettype_length, + net_mtu_length=net_mtu_length, net_domain_length=net_domain_length, net_v6_flag_length=net_v6_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_description=network_information['description'], net_nettype=network_information['type'], + net_mtu=network_information['mtu'], net_domain=network_information['domain'], net_v6_flag=v6_flag, v6_flag_colour=v6_flag_colour, diff --git a/client-cli/pvc/pvc.py b/client-cli/pvc/pvc.py index 0047650f..655366b2 100755 --- a/client-cli/pvc/pvc.py +++ b/client-cli/pvc/pvc.py @@ -1874,6 +1874,11 @@ def cli_network(): 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.' ) +@click.option( + '-m', '--mtu', 'mtu', + default='', + help='MTU of the network interfaces.' +) @click.option( '-n', '--domain', 'domain', default=None, @@ -1924,10 +1929,12 @@ def cli_network(): 'vni' ) @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. + 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: 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. """ - 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) @@ -1954,6 +1961,11 @@ def net_add(vni, description, nettype, domain, ip_network, ip_gateway, ip6_netwo default=None, 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( '-n', '--domain', 'domain', default=None, @@ -2004,16 +2016,18 @@ def net_add(vni, description, nettype, domain, ip_network, ip_gateway, ip6_netwo 'vni' ) @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. + 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: 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)