Не могу понять, как управлять потоком l oop. Я уверен, что это можно сделать, добавив некоторые условия, но я нахожусь на очень ранних этапах изучения кода. Любая помощь будет полезна в выяснении этого, не делая шаблон stati c. Он должен быть динамическим c, чтобы он работал в моем случае использования, так как каждое изменение в сети будет отличаться от предыдущего, но основные c остаются прежними.
YAML and Template below spit out every possible match but i only need to permit Stream A source to Stream A groups. I left ports same for all here but would like to control where they get attached in output.
I.e,
permit udp object-group STREAM_A object-group GROUPS_Stream_A object-group Stream_A/B ports
permit udp object-group STREAM_A object-group GROUPS_Stream_B object-group Stream_A/B ports
permit udp object-group STREAM_B object-group GROUPS_Stream_A object-group Stream_A/B ports
permit udp object-group STREAM_B object-group GROUPS_Stream_B object-group Stream_A/B ports
What i am hoping the output would be is:
permit udp object-group STREAM_A object-group GROUPS_Stream_A object-group Stream_A/B ports
permit udp object-group STREAM_B object-group GROUPS_Stream_B object-group Stream_A/B ports
YAML INPUT
rpAddresses:
- name: Stream A
ip: 10.10.1.1
mask: 255.255.255.255
- name: Stream B
ip: 10.10.2.1
mask: 255.255.255.255
sourceNetworks:
- name: STREAM_A
description: Stream A description
network: 10.10.10.0 255.255.255.128
- name: STREAM_B
description: Stream B Sources
network: 10.10.10.128 255.255.255.128
mcChannels:
- name: GROUPS_Stream_A
description: groups for stream A
channels:
- 1.0.0.1
- 1.0.0.2
- name: GROUPS_Stream_B
description: groups for stream B
channels:
- 2.0.0.1
- 2.0.0.2
mcPorts:
- name: Stream_A/B ports
description: ports
ports:
- 10001
- 10002
~! JINJA Template i am using!
!
{%for data in sourceNetworks if data.name is defined-%}
object-group network {{data.name}}
description {{data.description}}
{{data.network}}
{% endfor -%}
{%for data in mcChannels if data.name is defined-%}
object-group network {{data.name}}
description {{data.description}}
{% for ip in data.channels -%}
host {{ip}}
{% endfor -%}
{% endfor -%}
{%for data in mcPorts if data.name is defined-%}
object-group network {{data.name}}
description {{data.description}}
{% for port in data.ports -%}
udp eq {{port}}
{% endfor -%}
{% endfor -%}
{% for source in sourceNetworks if source.name is defined -%}
{% for channel in mcChannels if channel.name is defined -%}
{% for port in mcPorts if port.name is defined -%}
permit udp object-group {{source.name}} object-group {{channel.name}} object-group {{port.name}}
{% endfor -%}
{% endfor -%}
{% endfor -%}