on console, get Kerberos realm from config
[invirt/packages/invirt-console.git] / files / usr / sbin / sipb-xen-update-conserver
index 297fefe..1fc623b 100755 (executable)
@@ -1,4 +1,34 @@
-#!/bin/bash
+#!/usr/bin/python
 
-ls /etc/conserver/conf.d/ | sed -e 's|^|#include /etc/conserver/conf.d/|' >/etc/conserver/includes.cf
-/etc/init.d/conserver-server reload
\ No newline at end of file
+import sipb_xen_database
+import subprocess
+import os
+import socket
+
+sipb_xen_database.connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen')
+
+def live_vms():
+    p = subprocess.Popen(['/usr/sbin/xm', 'list'], stdout=subprocess.PIPE)
+    p.wait()
+    output = p.stdout.read()
+    vms = [x.split()[0][2:] for x in output.splitlines() if x.startswith('d_')]
+    return vms
+
+def reload_conserver():
+    p = subprocess.Popen(['/etc/init.d/conserver-server', 'reload'], stdout=subprocess.PIPE)
+    p.wait()
+
+if __name__ == '__main__':
+    hostname = socket.getfqdn().lower()
+    realm = file('/etc/invirt/realm').read().strip()
+    principal = 'host/'+hostname+'@'+realm
+    config = '\n'.join('console %s { master %s; }' % (vm, hostname)
+                       for vm in live_vms())
+    f = open('/etc/conserver/sipb-xen-consoles.cf', 'w')
+    f.write(config)
+    f.close()
+    reload_conserver()
+    subprocess.call(['/usr/bin/kinit', '-k', '-t', '/etc/krb5.keytab',
+                     principal])
+    subprocess.call(['/usr/bin/remctl', 'sipb-xen-console.mit.edu',
+                     'console', 'update', config])