Actually generalize the invirt.remctl module 0.0.9
authorEvan Broder <broder@mit.edu>
Tue, 11 Nov 2008 09:32:17 +0000 (04:32 -0500)
committerEvan Broder <broder@mit.edu>
Tue, 11 Nov 2008 09:32:17 +0000 (04:32 -0500)
svn path=/trunk/packages/invirt-base/; revision=1614

python/invirt/remctl.py

index 8f93984..465d31c 100644 (file)
@@ -4,29 +4,33 @@ Functions to perform remctls.
 
 from invirt.common import CodeError
 import subprocess
+from socket import getfqdn
 
-def kinit():
+def kinit(principal=None, keytab=None):
     """Kinit with a given username and keytab"""
-    p = subprocess.Popen(['kinit', "-k", "-t", '/etc/invirt/keytab',
-                          'daemon/'+config.web.hostname],
+    if principal is None:
+        principal = 'daemon/' + getfqdn()
+    if keytab is None:
+        keytab = '/etc/invirt/keytab'
+    p = subprocess.Popen(['kinit', "-k", "-t", keytab, principal],
                          stderr=subprocess.PIPE)
     e = p.wait()
     if e:
         raise CodeError("Error %s in kinit: %s" % (e, p.stderr.read()))
 
-def checkKinit():
+def checkKinit(principal=None, keytab=None):
     """If we lack tickets, kinit."""
     p = subprocess.Popen(['klist', '-s'])
     if p.wait():
-        kinit()
+        kinit(principal, keytab)
 
-def remctl(*args, **kws):
+def remctl(host, *args, **kws):
     """Perform a remctl and return the output.
 
     kinits if necessary, and outputs errors to stderr.
     """
-    checkKinit()
-    p = subprocess.Popen(['remctl', config.remote.hostname]
+    checkKinit(kws.get('principal'), kws.get('keytab'))
+    p = subprocess.Popen(['remctl', host]
                          + list(args),
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE)