---
 MANIFEST.in   |    1 +
 aux/anamon.py |  183 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 cobbler.spec  |    4 +
 setup.py      |    8 +++
 4 files changed, 196 insertions(+), 0 deletions(-)
 create mode 100644 aux/anamon.py

diff --git a/MANIFEST.in b/MANIFEST.in
index a367267..43fc677 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -31,5 +31,6 @@ include snippets/*
 recursive-include po *.pot
 recursive-include po *.po
 recursive-include webui_content *
+recursive-include aux *
 recursive-include webui_templates *
 recursive-include triggers *
diff --git a/aux/anamon.py b/aux/anamon.py
new file mode 100644
index 0000000..1849bbd
--- /dev/null
+++ b/aux/anamon.py
@@ -0,0 +1,183 @@
+#!/usr/bin/python
+
+import os
+import sys
+import string
+import time
+import re
+import md5
+import base64
+import xmlrpclib
+
+class WatchedFile:
+    def __init__(self, fn, alias):
+        self.fn = fn
+        self.alias = alias
+        self.reset()
+
+    def reset(self):
+        self.where = 0
+        self.last_size = 0
+        self.lfrag=''
+        self.re_list={}
+        self.seen_line={}
+
+    def exists(self):
+        return os.access(self.fn, os.F_OK)
+
+    def lookfor(self,pattern):
+        self.re_list[pattern] = re.compile(pattern,re.MULTILINE)
+        self.seen_line[pattern] = 0
+
+    def seen(self,pattern):
+        if self.seen_line.has_key(pattern):
+            return self.seen_line[pattern]
+        else:
+            return 0
+
+    def changed(self):
+        if not self.exists():
+            return 0
+        size = os.stat(self.fn)[6]
+        if size > self.last_size:
+            self.last_size = size
+            return 1
+        else:
+            return 0
+
+    def uploadWrapper(self, blocksize = 262144):
+        """upload a file in chunks using the uploadFile call"""
+        retries = 3
+        fo = file(self.fn, "r")
+        totalsize = os.path.getsize(self.fn)
+        ofs = 0
+        md5sum = md5.new()
+        while True:
+            lap = time.time()
+            contents = fo.read(blocksize)
+            md5sum.update(contents)
+            size = len(contents)
+            data = base64.encodestring(contents)
+            if size == 0:
+                offset = -1
+                digest = md5sum.hexdigest()
+                sz = ofs
+            else:
+                offset = ofs
+                digest = md5.new(contents).hexdigest()
+                sz = size
+            del contents
+            tries = 0
+            while tries <= retries:
+                debug("upload_log_data('%s', '%s', %s, %s, %s, ...)\n" % 
(name, self.alias, sz, digest, offset))
+                if session.upload_log_data(name, self.alias, sz, digest, 
offset, data):
+                    break
+                else:
+                    tries = tries + 1
+            if size == 0:
+                break
+            ofs += size
+        fo.close()
+
+    def update(self):
+        if not self.exists():
+            return
+        if not self.changed():
+            return
+        try:
+            self.uploadWrapper()
+        except:
+            raise
+
+class MountWatcher:
+
+    def __init__(self,mp):
+        self.mountpoint = mp
+        self.zero()
+
+    def zero(self):
+        self.line=''
+        self.time = time.time()
+
+    def update(self):
+        fd = open('/proc/mounts')
+        found = 0
+        while 1:
+            line = fd.readline()
+            if not line:
+                break
+            parts = string.split(line)
+            mp = parts[1]
+            if mp == self.mountpoint:
+                found = 1
+                if line != self.line:
+                    self.line = line
+                    self.time = time.time()
+        if not found:
+            self.zero()
+        fd.close()
+
+    def stable(self):
+        self.update()
+        if self.line and (time.time() - self.time > 60):
+            return 1
+        else:
+            return 0
+
+def anamon_loop():
+    alog = WatchedFile("/tmp/anaconda.log", "anaconda.log")
+    alog.lookfor("step installpackages$")
+
+    slog = WatchedFile("/tmp/syslog", "sys.log")
+    llog = WatchedFile("/tmp/lvmout", "lvmout.log")
+    kcfg = WatchedFile("/tmp/ks.cfg", "ks.cfg")
+    scrlog = WatchedFile("/tmp/ks-script.log", "ks-script.log")
+    dump = WatchedFile("/tmp/anacdump.txt", "anacdump.txt")
+    mod = WatchedFile("/tmp/modprobe.conf", "modprobe.conf")
+    ilog = WatchedFile("/mnt/sysimage/root/install.log", "install.log")
+    ilog2 = WatchedFile("/mnt/sysimage/tmp/install.log", "tmp+install.log")
+    ulog = WatchedFile("/mnt/sysimage/root/upgrade.log", "upgrade.log")
+    ulog2 = WatchedFile("/mnt/sysimage/tmp/upgrade.log", "tmp+upgrade.log")
+    sysimage = MountWatcher("/mnt/sysimage")
+    watchlist = [alog, slog, dump, scrlog, mod, llog, kcfg]
+    waitlist = [ilog, ilog2, ulog, ulog2]
+
+    while 1:
+        time.sleep(5)
+
+        for watch in waitlist:
+            if alog.seen("step installpackages$") or (sysimage.stable() and 
watch.exists()):
+                print "Adding %s to watch list" % watch.alias
+                watchlist.append(watch)
+                waitlist.remove(watch)
+
+        for wf in watchlist:
+            wf.update()
+
+# process args
+name = ""
+daemon = 1
+debug = lambda x,**y: None
+
+n = 0
+while n < len(sys.argv):
+    arg = sys.argv[n]
+    if arg == '--name':
+        n = n+1
+        name = sys.argv[n]
+    elif arg == '--debug':
+        debug = lambda x,**y: sys.stderr.write(x % y)
+    elif arg == '--fg':
+        daemon = 0
+    n = n+1
+
+session = xmlrpclib.Server("http://dell-t5400.test.redhat.com:80/cobbler_api";)
+
+if daemon:
+    if not os.fork():
+        anamon_loop()
+        sys._exit(1)
+    sys.exit(0)
+else:
+    anamon_loop()
+
diff --git a/cobbler.spec b/cobbler.spec
index 9761634..777cfb0 100644
--- a/cobbler.spec
+++ b/cobbler.spec
@@ -150,8 +150,10 @@ test "x$RPM_BUILD_ROOT" != "x" && rm -rf $RPM_BUILD_ROOT
 %dir /var/www/cobbler/links
 %defattr(755,apache,apache)
 %dir /var/www/cobbler/webui
+%dir /var/www/cobbler/aux
 %defattr(444,apache,apache)
 /var/www/cobbler/webui/*
+/var/www/cobbler/aux/*
 
 %defattr(755,root,root)
 %{_bindir}/cobbler
@@ -195,6 +197,7 @@ test "x$RPM_BUILD_ROOT" != "x" && rm -rf $RPM_BUILD_ROOT
 %config(noreplace) /etc/httpd/conf.d/cobbler_svc.conf
 %endif
 %dir /var/log/cobbler/syslog
+%dir /var/log/cobbler/anamon
 
 %defattr(755,root,root)
 %dir /var/lib/cobbler
@@ -261,6 +264,7 @@ test "x$RPM_BUILD_ROOT" != "x" && rm -rf $RPM_BUILD_ROOT
 %config(noreplace) /var/lib/cobbler/snippets/func_register_if_enabled
 %config(noreplace) /var/lib/cobbler/snippets/download_config_files
 %config(noreplace) /var/lib/cobbler/snippets/koan_environment
+%config(noreplace) /var/lib/cobbler/snippets/pre_anamon
 /var/lib/cobbler/elilo-3.8-ia64.efi
 /var/lib/cobbler/menu.c32
 /var/lib/cobbler/yaboot-1.3.14
diff --git a/setup.py b/setup.py
index 408c53e..ab62ba4 100644
--- a/setup.py
+++ b/setup.py
@@ -106,6 +106,7 @@ if __name__ == "__main__":
         vw_systems    = wwwpath + "/systems"
         vw_profiles   = wwwpath + "/profiles"
         vw_links      = wwwpath + "/links"
+        vw_aux        = wwwpath + "/aux"
         # cgipath       = "/var/www/cgi-bin/cobbler"
         modpython     = wwwpath + "/web"
         modpythonsvc  = wwwpath + "/svc"
@@ -115,6 +116,7 @@ if __name__ == "__main__":
         logpath2 = logpath + "/kicklog"
         logpath3 = logpath + "/syslog"
         logpath4 = "/var/log/httpd/cobbler"
+        logpath5 = logpath + "/anamon"
 
         # tftp paths        
         tftp_cfg      = "/tftpboot/pxelinux.cfg"
@@ -261,6 +263,7 @@ if __name__ == "__main__":
                                 (snippetpath, 
['snippets/func_register_if_enabled']),
                                 (snippetpath, 
['snippets/download_config_files']),
                                 (snippetpath, ['snippets/koan_environment']),
+                                (snippetpath, ['snippets/pre_anamon']),
 
                                 # documentation
                                 (manpath,  ['docs/cobbler.1.gz']),
@@ -270,6 +273,7 @@ if __name__ == "__main__":
                                 (logpath2, []),
                                 (logpath3, []),
                                (logpath4, []),
+                                (logpath5, []),
 
                                 # web page directories that we own
                                 (vw_localmirror,    []),
@@ -283,6 +287,7 @@ if __name__ == "__main__":
                                 (vw_systems,        []),
                                 (vw_profiles,       []),
                                 (vw_links,          []),
+                                (vw_aux,            []),
 
                                 # zone-specific templates directory
                                 (zonepath,    []),
@@ -336,6 +341,9 @@ if __name__ == "__main__":
                                 (wwwcon,            
['webui_content/logo-cobbler.png']),
                                 (wwwcon,            
['webui_content/cobblerweb.css']),
 
+                                # Anamon script
+                                (vw_aux,            ['aux/anamon.py']),
+
                                 # Directories to hold cobbler triggers
                                 ("%s/add/distro/pre" % trigpath,      []),
                                 ("%s/add/distro/post" % trigpath,     []),
-- 
1.6.0.4

_______________________________________________
cobbler mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/cobbler

Reply via email to