Fix job templates and grain

Change-Id: I50f3cfc78a57d9f7277954247e57c32434a502d1
diff --git a/_grains/jenkins.py b/_grains/jenkins.py
deleted file mode 100644
index b8f85d7..0000000
--- a/_grains/jenkins.py
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env python
-
-import json
-
-def main():
-    output = { "jenkins_plugins" : {} }
-
-    list_plugin_groovy = """\
-        pluginList = []
-        Jenkins.instance.pluginManager.plugins.each{ pluginList << ("'${it.shortName}@${it.version}'")}
-        print pluginList
-    """
-    call_result = __salt__['jenkins_common.call_groovy_script'](list_plugin_groovy, [])
-
-    plugins = json.loads(call_result)
-
-    for plugin in plugins:
-        plugin_fields = plugin.split('@')
-        output["jenkins_plugins"][plugin_fields[0]] = {"version": plugin_fields[1]}
-
-    if output:
-        return output
-    else:
-        return None
diff --git a/_grains/jenkins_plugins.py b/_grains/jenkins_plugins.py
new file mode 100644
index 0000000..c13cb8b
--- /dev/null
+++ b/_grains/jenkins_plugins.py
@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+
+import jenkins
+import salt.config
+
+def main():
+    output = { "jenkins_plugins" : {} }
+    opts = salt.config.minion_config('/etc/salt/minion')
+    user = opts['jenkins']['user']
+    password = opts['jenkins']['password']
+    url = opts['jenkins']['url']
+
+    server = jenkins.Jenkins(url, username=user, password=password)
+    plugins = server.get_plugins(depth=1)
+    for plugin_name, plugin_dict in plugins.iteritems():
+        output["jenkins_plugins"][plugin_name[0]] = {"version" : (plugin_dict["backupVersion"] or 0)}
+    return output