From e2537c30236b4a0e64cffa9ec4391ece6e5b1fcd Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Wed, 25 Jan 2023 20:46:26 +0100 Subject: container: T4947: backport missing port-range validator --- src/validators/port-range | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 src/validators/port-range diff --git a/src/validators/port-range b/src/validators/port-range new file mode 100755 index 000000000..5468000a7 --- /dev/null +++ b/src/validators/port-range @@ -0,0 +1,40 @@ +#!/usr/bin/python3 + +import sys +import re + +from vyos.util import read_file + +services_file = '/etc/services' + +def get_services(): + names = [] + service_data = read_file(services_file, "") + for line in service_data.split("\n"): + if not line or line[0] == '#': + continue + names.append(line.split(None, 1)[0]) + return names + +def error(port_range): + print(f'Error: {port_range} is not a valid port or port range') + sys.exit(1) + +if __name__ == '__main__': + if len(sys.argv)>1: + port_range = sys.argv[1] + if re.match('^[0-9]{1,5}-[0-9]{1,5}$', port_range): + port_1, port_2 = port_range.split('-') + if int(port_1) not in range(1, 65536) or int(port_2) not in range(1, 65536): + error(port_range) + if int(port_1) > int(port_2): + error(port_range) + elif port_range.isnumeric() and int(port_range) not in range(1, 65536): + error(port_range) + elif not port_range.isnumeric() and port_range not in get_services(): + print(f'Error: {port_range} is not a valid service name') + sys.exit(1) + else: + sys.exit(2) + + sys.exit(0) -- cgit v1.2.3 From 20dfd05bf67dcb6437df8440e401286255426356 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Wed, 25 Jan 2023 20:46:46 +0100 Subject: container: xml: T4947: add missing default value in CLI help VyOS 1.3 does not support automatic generation of the (default: <>) string from XML defaultValue nodes. Specify help string manually. --- interface-definitions/container.xml.in | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/interface-definitions/container.xml.in b/interface-definitions/container.xml.in index b61664125..1c971b58a 100644 --- a/interface-definitions/container.xml.in +++ b/interface-definitions/container.xml.in @@ -111,7 +111,7 @@ - Memory (RAM) available to this container + Memory (RAM) available to this container (default: 512) u32:0 Unlimited @@ -129,7 +129,7 @@ - Shared memory available to this container + Shared memory available to this container (default: 64) u32:0 Unlimited @@ -207,7 +207,7 @@ - Transport protocol used for port mapping + Transport protocol used for port mapping (default: tcp) tcp udp @@ -229,7 +229,7 @@ - Restart options for container + Restart options for container (default: on-failure) no on-failure always @@ -276,7 +276,7 @@ - Volume access mode ro/rw + Volume access mode ro/rw (default: rw) ro rw @@ -334,7 +334,7 @@ - Registry Name + Registry Name (default: docker.io, quay.io) docker.io quay.io -- cgit v1.2.3 From 8a84cdb451b6568afb2b95ea8f66beb2983ba114 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Wed, 25 Jan 2023 20:47:49 +0100 Subject: op-mode: container: T4947: there is no standardised vyos.opmode in equuleus --- op-mode-definitions/container.xml.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/op-mode-definitions/container.xml.in b/op-mode-definitions/container.xml.in index 786bd66d3..78b3b7335 100644 --- a/op-mode-definitions/container.xml.in +++ b/op-mode-definitions/container.xml.in @@ -100,13 +100,13 @@ Show containers - sudo ${vyos_op_scripts_dir}/container.py show_container + sudo podman ps --all Show container image - sudo ${vyos_op_scripts_dir}/container.py show_image + sudo podman image ls @@ -121,7 +121,7 @@ Show available container networks - sudo ${vyos_op_scripts_dir}/container.py show_network + sudo podman network ls @@ -149,7 +149,7 @@ container name - sudo ${vyos_op_scripts_dir}/container.py restart --name="$3" + sudo podman restart "$3" -- cgit v1.2.3