From 72c55fe6c7934ac3343fd692a5c521716f079e89 Mon Sep 17 00:00:00 2001
From: Robert Latta <robert.latta@geant.org>
Date: Mon, 25 Jan 2021 17:34:32 +0000
Subject: [PATCH] added route for retrieving netconf data

---
 inventory_provider/routes/testing.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/inventory_provider/routes/testing.py b/inventory_provider/routes/testing.py
index 81a43cf0..c9bdc7a1 100644
--- a/inventory_provider/routes/testing.py
+++ b/inventory_provider/routes/testing.py
@@ -189,6 +189,18 @@ def snmp_ids(hostname):
     return jsonify(ifc_data)
 
 
+@routes.route("netconf/<hostname>", methods=['GET', 'POST'])
+def get_netconf(hostname):
+    config = current_app.config["INVENTORY_PROVIDER_CONFIG"]
+    try:
+        netconf_doc = juniper.load_config(
+            hostname, config["ssh"], validate=False)
+        msg = etree.tostring(netconf_doc, encoding='unicode')
+    except (ConnectionError, juniper.NetconfHandlingError) as e:
+        msg = f'error loading netconf data from {hostname}\n{e}'
+    return msg
+
+
 @routes.route("latchdb", methods=['GET', 'POST'])
 def latch_db():
     config = current_app.config["INVENTORY_PROVIDER_CONFIG"]
-- 
GitLab