]> git.uio.no Git - python-TSD.git/commitdiff
New tool tsd-atom2hosts.
authorPetter Reinholdtsen <petter.reinholdtsen@usit.uio.no>
Thu, 22 May 2014 13:13:31 +0000 (15:13 +0200)
committerPetter Reinholdtsen <petter.reinholdtsen@usit.uio.no>
Thu, 22 May 2014 13:13:31 +0000 (15:13 +0200)
bin/tsd-atom2hosts [new file with mode: 0644]
setup.py

diff --git a/bin/tsd-atom2hosts b/bin/tsd-atom2hosts
new file mode 100644 (file)
index 0000000..dfa282d
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/python
+#
+# Given a cfengine atom visible in LDAP, list the FQDN of the hosts
+# where this atom is enabled.
+
+import os, sys, inspect
+
+# use this if you want to include modules from a subforder
+cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"../lib")))
+if cmd_subfolder not in sys.path:
+    sys.path.insert(0, cmd_subfolder)
+
+import TSD
+import ldap
+import socket
+
+def main():
+    try:
+        atom = sys.argv[1]
+    except:
+        print "error: need atom to look up hosts"
+       return 1
+
+    if atom is None or "" == atom:
+        print "error: need atom to look up hosts"
+        return 1
+
+    lref = TSD.common.ldap_connect()
+    hosts = TSD.common.atom2hosts(lref, atom)
+    if 0 < len(hosts):
+        print "\n".join(hosts);
+    lref.unbind()
+
+if __name__ == "__main__":
+    main()
index 90655031df57e1dad2d884d020a36df51fe32222..ddd92e279dec195d9ca2a816bbdc9d74a3257263 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -14,5 +14,6 @@ setup(name='python-TSD',
                'bin/tsd-ldap2cfengine',
                'bin/tsd-virtcreate',
                'bin/tsd-run-with-lockfile',
+               'bin/tsd-atom2hosts',
               ],
      )