summaryrefslogtreecommitdiff
path: root/src/conf_mode/containers.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-04-27 19:20:49 +0200
committerGitHub <noreply@github.com>2021-04-27 19:20:49 +0200
commitaf108d812d1506a38feee7061fe935639dcc63a6 (patch)
tree2b0c4f700d71323e957667897a5d5ab420ea5549 /src/conf_mode/containers.py
parent41152d41a18fc75f91e105a7a85ccc64e67a99c0 (diff)
parentb141b56e6779644826129cf0899a87f28058c7ea (diff)
downloadvyos-1x-af108d812d1506a38feee7061fe935639dcc63a6.tar.gz
vyos-1x-af108d812d1506a38feee7061fe935639dcc63a6.zip
Merge pull request #818 from sever-sever/T2216-ports
container: T2216: Add binding for ports and volumes
Diffstat (limited to 'src/conf_mode/containers.py')
-rwxr-xr-xsrc/conf_mode/containers.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/conf_mode/containers.py b/src/conf_mode/containers.py
index 9b7a52d26..5efdb6a2f 100755
--- a/src/conf_mode/containers.py
+++ b/src/conf_mode/containers.py
@@ -221,14 +221,36 @@ def apply(container):
env_opt = '-e '
env_opt += " -e ".join(f"{k}={v['value']}" for k, v in container_config['environment'].items())
+ # Publish ports
+ port = ''
+ 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'
+ sport = container_config['port'][portmap]['source']
+ dport = container_config['port'][portmap]['destination']
+ port += f' -p {sport}:{dport}{protocol}'
+
+ # Bind volume
+ volume = ''
+ if 'volume' in container_config:
+ for vol in container_config['volume']:
+ svol = container_config['volume'][vol]['source']
+ dvol = container_config['volume'][vol]['destination']
+ volume += f' -v {svol}:{dvol}'
+
if 'allow_host_networks' in container_config:
- _cmd(f'podman run -dit --name {name} --net host {env_opt} {image}')
+ _cmd(f'podman run -dit --name {name} --net host {port} {volume} {env_opt} {image}')
else:
for network in container_config['network']:
ipparam = ''
if 'address' in container_config['network'][network]:
ipparam = '--ip ' + container_config['network'][network]['address']
- _cmd(f'podman run --name {name} -dit --net {network} {ipparam} {env_opt} {image}')
+ _cmd(f'podman run --name {name} -dit --net {network} {ipparam} {port} {volume} {env_opt} {image}')
# Else container is already created. Just start it.
# It's needed after reboot.