From 74b35343889abe481e6a2c6a07926f25d17a9d36 Mon Sep 17 00:00:00 2001 From: Thomas Schwery Date: Sun, 29 Nov 2015 22:14:27 +0100 Subject: [PATCH] Using status information to populate "Available minions" instead of using grains list. This fixes the occurences where servers disappear because they are down on the grains call and up on the status call as calls are not transactional. --- saltinventory.py | 4 ++-- templates/hostlist_template.html | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/saltinventory.py b/saltinventory.py index e38b22d..1eb2e70 100755 --- a/saltinventory.py +++ b/saltinventory.py @@ -49,15 +49,15 @@ class Inventorizer: def collectHostData(self): self.keys_list = self.saltwhe.cmd('key.list_all', [], {}, {}) - self.host_list = self.saltcmd.cmd('*', 'grains.items') self.stat_list = self.saltrun.cmd('manage.status') + self.grains_list = self.saltcmd.cmd('*', 'grains.items') self.jobs_list = self.saltrun.cmd('jobs.list_jobs') def createHostList(self): fo = open(self.config['base_path'] + "index.html", "wb") env = Environment(loader = FileSystemLoader(config['template_path'])) template = env.get_template('hostlist_template.html') - fo.write(template.render({'hostlist': self.host_list, 'statlist': self.stat_list, 'keylist': self.keys_list, 'joblist': self.jobs_list, 'now' : time.strftime('%Y-%m-%d %H:%M:%S')})) + fo.write(template.render({'grainlist': self.grains_list, 'statlist': self.stat_list, 'keylist': self.keys_list, 'joblist': self.jobs_list, 'now' : time.strftime('%Y-%m-%d %H:%M:%S')})) fo.close def lenFilter(self, list): diff --git a/templates/hostlist_template.html b/templates/hostlist_template.html index a1549c5..730b5cb 100644 --- a/templates/hostlist_template.html +++ b/templates/hostlist_template.html @@ -43,7 +43,9 @@ - {% for name, data in hostlist.iteritems() %} + {% for name in statlist['up'] %} + {% if name in grainlist %} + {% set data = grainlist[name] %} + + {{ name }} + + + + + + + + {% endif %} {% endfor %} @@ -148,7 +166,7 @@ - {% for name, data in hostlist.iteritems() %} + {% for name, data in grainlist.iteritems() %}