From b35e74e3551857f845cfdb9dd3352883bb47bd2f Mon Sep 17 00:00:00 2001
From: PCoder <purple.coder@yahoo.co.uk>
Date: Thu, 31 Aug 2017 12:55:19 +0530
Subject: [PATCH] Updated cdist integration code with index parameter

---
 utils/tasks.py | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/utils/tasks.py b/utils/tasks.py
index 1c6dd449..6a246d54 100644
--- a/utils/tasks.py
+++ b/utils/tasks.py
@@ -1,6 +1,7 @@
-import cdist
 import tempfile
-from cdist.integration import configure_hosts_simple
+
+import cdist
+import cdist.integration as cdist_integration
 from celery.utils.log import get_task_logger
 from django.conf import settings
 from django.core.mail import EmailMessage
@@ -50,9 +51,13 @@ def save_ssh_key(self, hosts, keys):
         tmp_manifest.writelines(lines_list)
         tmp_manifest.flush()
         try:
-            configure_hosts_simple(hosts,
-                                   tmp_manifest.name,
-                                   verbose=cdist.argparse.VERBOSE_TRACE)
+            cdist_instance_index = cdist_integration.instance_index
+            cdist_index = next(cdist_instance_index)
+            cdist_integration.configure_hosts_simple(hosts,
+                                                     tmp_manifest.name,
+                                                     index=cdist_index,
+                                                     verbose=cdist.argparse.VERBOSE_TRACE)
+            cdist_instance_index.free(cdist_index)
         except Exception as cdist_exception:
             logger.error(cdist_exception)
             return_value = False