summaryrefslogtreecommitdiff
path: root/src/conf_mode/container.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2022-12-25 11:09:21 +0100
committerChristian Poessinger <christian@poessinger.com>2022-12-25 11:12:09 +0100
commita0d3c5702dfcf0ac0008039357a2e0e02c625235 (patch)
tree9516374016dfbf5d1cca74b6e8eeeb71dafb9317 /src/conf_mode/container.py
parent1ef7ba760bc7c21a754ef7cf3e5049ec88739b12 (diff)
downloadvyos-1x-a0d3c5702dfcf0ac0008039357a2e0e02c625235.tar.gz
vyos-1x-a0d3c5702dfcf0ac0008039357a2e0e02c625235.zip
container: T2216: use defaultValue XML definition to define port protocol
Instead of hardcoding the default protocol as TCP in the Python script we shall use the XML based defaultValue approach instead. This also automatically exports the default to the CLI completion helper.
Diffstat (limited to 'src/conf_mode/container.py')
-rwxr-xr-xsrc/conf_mode/container.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/conf_mode/container.py b/src/conf_mode/container.py
index 48ba409a8..7567444db 100755
--- a/src/conf_mode/container.py
+++ b/src/conf_mode/container.py
@@ -73,9 +73,19 @@ def get_config(config=None):
# Merge per-container default values
if 'name' in container:
default_values = defaults(base + ['name'])
+ if 'port' in default_values:
+ del default_values['port']
for name in container['name']:
container['name'][name] = dict_merge(default_values, container['name'][name])
+ # XXX: T2665: we can not safely rely on the defaults() when there are
+ # tagNodes in place, it is better to blend in the defaults manually.
+ if 'port' in container['name'][name]:
+ for port in container['name'][name]['port']:
+ default_values = defaults(base + ['name', 'port'])
+ container['name'][name]['port'][port] = dict_merge(
+ default_values, container['name'][name]['port'][port])
+
# Delete container network, delete containers
tmp = node_changed(conf, base + ['network'])
if tmp: container.update({'network_remove' : tmp})
@@ -242,14 +252,10 @@ def generate_run_arguments(name, container_config):
if 'port' in container_config:
protocol = ''
for portmap in container_config['port']:
- if 'protocol' in container_config['port'][portmap]:
- protocol = container_config['port'][portmap]['protocol']
- protocol = f'/{protocol}'
- else:
- protocol = '/tcp'
+ protocol = container_config['port'][portmap]['protocol']
sport = container_config['port'][portmap]['source']
dport = container_config['port'][portmap]['destination']
- port += f' -p {sport}:{dport}{protocol}'
+ port += f' -p {sport}:{dport}/{protocol}'
# Bind volume
volume = ''