From fd1177ed09e33e060d0cfac8d987b5d838a0cade Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Mon, 24 Dec 2018 10:27:30 +0100
Subject: [PATCH] added snmp query to worker jobs

---
 inventory_provider/routes/jobs.py  | 20 +++++++++----
 inventory_provider/tasks/worker.py | 47 +++++++++++++++---------------
 2 files changed, 38 insertions(+), 29 deletions(-)

diff --git a/inventory_provider/routes/jobs.py b/inventory_provider/routes/jobs.py
index db71dfe2..a3f3925f 100644
--- a/inventory_provider/routes/jobs.py
+++ b/inventory_provider/routes/jobs.py
@@ -15,13 +15,23 @@ def update():
     config = current_app.config["INVENTORY_PROVIDER_CONFIG"]
 
     for r in config["routers"]:
-        task_logger.info("fetching router details for: %r" % r)
-        task_logger.debug('launching task: '
-                          'inventory_provider'
-                          '.tasks.worker.netconf_refresh_config'
-                          '(%s)' % r['hostname'])
+
+        task_logger.info("fetching details for: %r" % r)
+
+        task_logger.debug(
+            'launching task: '
+            'inventory_provider.tasks.worker.netconf_refresh_config'
+            '(%s)' % r['hostname'])
         app.send_task(
             'inventory_provider.tasks.worker.netconf_refresh_config',
             args=[r["hostname"]])
 
+        task_logger.debug(
+            'launching task: '
+            'inventory_provider.tasks.worker.snmp_refresh_interfaces'
+            '(%s)' % r['hostname'])
+        app.send_task(
+            'inventory_provider.tasks.worker.snmp_refresh_interfaces',
+            args=[r["hostname"], r["community"]])
+
     return Response("OK")
diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py
index b450f560..4f83d159 100644
--- a/inventory_provider/tasks/worker.py
+++ b/inventory_provider/tasks/worker.py
@@ -51,7 +51,7 @@ class InventoryTask(Task):
         InventoryTask.save_key(
             hostname,
             key,
-            etree.tostring(data, encoding='utf-8'))
+            etree.tostring(data, encoding='unicode'))
 
 
 class WorkerArgs(bootsteps.Step):
@@ -74,28 +74,28 @@ app.user_options['worker'].add(worker_args)
 app.steps['worker'].add(WorkerArgs)
 
 
-@app.task(bind=InventoryTask)
-def juniper_refresh_bgp(self, hostname):
-    InventoryTask.save_key_json(
-        hostname,
-        "bgp",
-        juniper.fetch_bgp_config(hostname, InventoryTask.config["ssh"]))
-
-
-@app.task(bind=InventoryTask)
-def juniper_refresh_vrr(self, hostname):
-    InventoryTask.save_key_json(
-        hostname,
-        "vrr",
-        juniper.fetch_vrr_config(hostname, InventoryTask.config["ssh"]))
-
-
-@app.task(bind=InventoryTask)
-def juniper_refresh_interfaces(self, hostname):
-    InventoryTask.save_key_json(
-        hostname,
-        "interfaces",
-        juniper.fetch_interfaces(hostname, InventoryTask.config["ssh"]))
+# @app.task(bind=InventoryTask)
+# def juniper_refresh_bgp(self, hostname):
+#     InventoryTask.save_key_json(
+#         hostname,
+#         "bgp",
+#         juniper.fetch_bgp_config(hostname, InventoryTask.config["ssh"]))
+#
+#
+# @app.task(bind=InventoryTask)
+# def juniper_refresh_vrr(self, hostname):
+#     InventoryTask.save_key_json(
+#         hostname,
+#         "vrr",
+#         juniper.fetch_vrr_config(hostname, InventoryTask.config["ssh"]))
+#
+#
+# @app.task(bind=InventoryTask)
+# def juniper_refresh_interfaces(self, hostname):
+#     InventoryTask.save_key_json(
+#         hostname,
+#         "interfaces",
+#         juniper.fetch_interfaces(hostname, InventoryTask.config["ssh"]))
 
 
 @app.task(bind=InventoryTask)
@@ -115,4 +115,3 @@ def netconf_refresh_config(self, hostname):
         hostname,
         "netconf",
         netconf.load_config(hostname, InventoryTask.config["ssh"]))
-
-- 
GitLab