From f38c2a5154ee8f265ea61fdc17e45e0e04f3a468 Mon Sep 17 00:00:00 2001
From: "ak@geant.org" <ak@geant.org>
Date: Wed, 20 Dec 2023 17:48:44 +0000
Subject: [PATCH] SNMP reorganize

snmp.j2 moved to system/security
snmp: added SNMP view config
---
 .../templates/routers/nokia/snmp.j2           | 27 ----------------
 .../routers/nokia/system/security/security.j2 |  1 +
 .../routers/nokia/system/security/snmp.j2     | 32 +++++++++++++++++++
 3 files changed, 33 insertions(+), 27 deletions(-)
 delete mode 100644 geant/gap_ansible/roles/base_config/templates/routers/nokia/snmp.j2
 create mode 100644 geant/gap_ansible/roles/base_config/templates/routers/nokia/system/security/snmp.j2

diff --git a/geant/gap_ansible/roles/base_config/templates/routers/nokia/snmp.j2 b/geant/gap_ansible/roles/base_config/templates/routers/nokia/snmp.j2
deleted file mode 100644
index 08803d34..00000000
--- a/geant/gap_ansible/roles/base_config/templates/routers/nokia/snmp.j2
+++ /dev/null
@@ -1,27 +0,0 @@
-<system xmlns="urn:nokia.com:sros:ns:yang:sr:conf" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes">
-<security>
-<snmp>
-{% for community in nokia_snmp_communities %}
-<community xmlns="urn:nokia.com:sros:ns:yang:sr:conf" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes" alu:operation="replace">
-{% if community.hash2 is defined %}
-  <community-string>{{ community.hash2 }}</community-string>
-{% else %}
-  <community-string>{{ community.name }}</community-string>
-{% endif %}
-  <access-permissions>r</access-permissions>
-  <version>{{ community.version | default('v2c') }}</version>
-  <source-access-list>{{ community.acl_name }}</source-access-list>
-</community>
-<source-access-list xmlns="urn:nokia.com:sros:ns:yang:sr:conf" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes" alu:operation="replace">
-  <list-name>{{ community.acl_name }}</list-name>
-{% for entry in community.acl_entries %}
-  <source-host>
-    <host-name>{{ entry.hostname }}</host-name>
-    <address>{{ entry.address }}</address>
-  </source-host>
-{% endfor %}
-{% endfor %}
-</source-access-list>
-</snmp>
-</security>
-</system>
diff --git a/geant/gap_ansible/roles/base_config/templates/routers/nokia/system/security/security.j2 b/geant/gap_ansible/roles/base_config/templates/routers/nokia/system/security/security.j2
index c240b1c4..1b007a91 100644
--- a/geant/gap_ansible/roles/base_config/templates/routers/nokia/system/security/security.j2
+++ b/geant/gap_ansible/roles/base_config/templates/routers/nokia/system/security/security.j2
@@ -8,6 +8,7 @@
         {% include "system/security/user_params.j2" %}
         {% include "system/security/dist_cpu_protection.j2" %}
         {% include "system/security/source_addresses.j2" %}
+        {% include "system/security/snmp.j2" %}
         {# {% include "system/security/ssh.j2" %} #}
       </security>
     </system>
diff --git a/geant/gap_ansible/roles/base_config/templates/routers/nokia/system/security/snmp.j2 b/geant/gap_ansible/roles/base_config/templates/routers/nokia/system/security/snmp.j2
new file mode 100644
index 00000000..092ac6d4
--- /dev/null
+++ b/geant/gap_ansible/roles/base_config/templates/routers/nokia/system/security/snmp.j2
@@ -0,0 +1,32 @@
+        <snmp>
+        {% for community in nokia_snmp_communities %}
+          <community xmlns="urn:nokia.com:sros:ns:yang:sr:conf" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes" alu:operation="replace">
+          {% if community.hash2 is defined %}
+            <community-string>{{ community.hash2 }}</community-string>
+          {% else %}
+            <community-string>{{ community.name }}</community-string>
+          {% endif %}
+            <access-permissions>r</access-permissions>
+            <version>{{ community.version | default('v2c') }}</version>
+            <source-access-list>{{ community.acl_name }}</source-access-list>
+          </community>
+          <source-access-list xmlns="urn:nokia.com:sros:ns:yang:sr:conf" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes" alu:operation="replace">
+            <list-name>{{ community.acl_name }}</list-name>
+          {% for entry in community.acl_entries %}
+            <source-host>
+              <host-name>{{ entry.hostname }}</host-name>
+              <address>{{ entry.address }}</address>
+            </source-host>
+          {% endfor %}
+          {% endfor %}
+          </source-access-list>
+        {% if nokia_snmp_views is defined %}
+          {% for view in nokia_snmp_views %}
+          <view alu:operation="replace">
+            <view-name>{{ view.name }}</view-name>
+            <subtree>{{ view.subtree }}</subtree>
+            <type>{{ view.type }}</type>
+          </view>
+          {% endfor %}
+        {% endif %}
+        </snmp>
-- 
GitLab