diff --git a/config.yaml b/config.yaml index 357fa93..b8740b7 100644 --- a/config.yaml +++ b/config.yaml @@ -59,9 +59,9 @@ subnets: ipv4_address: 10.1.5.129 r1: ipv4_address: 10.1.5.130 - s1: + s0: ipv4_address: 10.1.5.131 - s2: + s1: ipv4_address: 10.1.5.132 srgw0: srgw0: @@ -69,3 +69,6 @@ subnets: service: s: ipv4_address: 10.4.0.1 + slice0: + subnet: + ipv4_address: 10.2.0.0/24 diff --git a/scripts/jinja/customize.py b/scripts/jinja/customize.py index 101a49d..a971074 100644 --- a/scripts/jinja/customize.py +++ b/scripts/jinja/customize.py @@ -170,6 +170,22 @@ def ipv6(host: str, subnet: str, context: _Context) -> str: raise('Unknown ip address') return addr +@function +def ipv4_subnet(subnet: str, context: _Context) -> str: + try: + addr = context.dict['subnets'][subnet]['subnet']['ipv4_address'] + except: + raise('Unknown ip subnet') + return addr + +@function +def ipv6_subnet(subnet: str, context: _Context) -> str: + try: + addr = context.dict['subnets'][subnet]['subnet']['ipv6_address'] + except: + raise('Unknown ip subnet') + return addr + @function(output='json') def container(name: str, image: str, ipv6: typing.Optional[bool] = False, iface_tun: typing.Optional[bool] = False, command: typing.Optional[str|bool] = None, @@ -203,3 +219,15 @@ def container(name: str, image: str, ipv6: typing.Optional[bool] = False, iface_ if iface_tun: containers[name]['devices'] = ["/dev/net/tun:/dev/net/tun"] return json.dumps(containers) + +@function(output='json') +def container_setup(name: str) -> str: + containers = {} + containers[f'{name}-setup'] = { + "container_name": f'{name}-setup', + "network_mode": f'service{name}', + "image": 'louisroyer/docker-setup', + "cap_add": ['NET_ADMIN',], + "restart": "no", + } + return json.dumps(containers) diff --git a/templates/compose.yaml.j2 b/templates/compose.yaml.j2 index dfd0c9a..f3e6ed7 100644 --- a/templates/compose.yaml.j2 +++ b/templates/compose.yaml.j2 @@ -340,29 +340,37 @@ services: # srgw0: - # TODO: s1 docker-setup - {{ container_s(name='s1', image='nginx', command=False) }} + {{ container_setup_s(name='s0') }} + environment: + ONESHOT: "true" + ROUTES_INIT: |- + - add {{ ipv4_subnet('slice0') }} via {{ ipv4('r0', 'edge') }} + {{ container_s(name='s0', image='nginx', command=False) }} volumes: {{ volume_ro('nginx/instance.conf.template', '/etc/nginx/templates/instance.conf') }} environment: NGINX_PORT: "80" NGINX_SERVICE_ID: "{{ ipv4('s', 'service') }}" - NGINX_INSTANCE_ID: "{{ ipv4('s1', 'edge') }}" + NGINX_INSTANCE_ID: "{{ ipv4('s0', 'edge') }}" networks: edge: - ipv4_address: "{{ ipv4('s1', 'edge') }}" + ipv4_address: "{{ ipv4('s0', 'edge') }}" - # TODO: s2 docker-setup - {{ container_s(name='s2', image='nginx', command=False) }} + {{ container_setup_s(name='s1') }} + environment: + ONESHOT: "true" + ROUTES_INIT: |- + - add {{ ipv4_subnet('slice0') }} via {{ ipv4('r1', 'edge') }} + {{ container_s(name='s1', image='nginx', command=False) }} volumes: {{ volume_ro('nginx/instance.conf.template', '/etc/nginx/templates/instance.conf') }} environment: NGINX_PORT: "80" NGINX_SERVICE_ID: "{{ ipv4('s', 'service') }}" - NGINX_INSTANCE_ID: "{{ ipv4('s2', 'edge') }}" + NGINX_INSTANCE_ID: "{{ ipv4('s1', 'edge') }}" networks: edge: - ipv4_address: "{{ ipv4('s2', 'edge') }}" + ipv4_address: "{{ ipv4('s1', 'edge') }}" networks: ran: