From: Evan Broder Date: Tue, 11 Nov 2008 09:32:17 +0000 (-0500) Subject: Actually generalize the invirt.remctl module X-Git-Tag: 0.0.9^0 X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-base.git/commitdiff_plain/93012c9a4cc83922a3546c7b51fc524a4efda2b4 Actually generalize the invirt.remctl module svn path=/trunk/packages/invirt-base/; revision=1614 --- diff --git a/python/invirt/remctl.py b/python/invirt/remctl.py index 8f93984..465d31c 100644 --- a/python/invirt/remctl.py +++ b/python/invirt/remctl.py @@ -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)