Ignore:
Timestamp:
Nov 11, 2008, 4:32:17 AM (16 years ago)
Author:
broder
Message:

Actually generalize the invirt.remctl module

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/invirt-base/python/invirt/remctl.py

    r1613 r1614  
    55from invirt.common import CodeError
    66import subprocess
     7from socket import getfqdn
    78
    8 def kinit():
     9def kinit(principal=None, keytab=None):
    910    """Kinit with a given username and keytab"""
    10     p = subprocess.Popen(['kinit', "-k", "-t", '/etc/invirt/keytab',
    11                           'daemon/'+config.web.hostname],
     11    if principal is None:
     12        principal = 'daemon/' + getfqdn()
     13    if keytab is None:
     14        keytab = '/etc/invirt/keytab'
     15    p = subprocess.Popen(['kinit', "-k", "-t", keytab, principal],
    1216                         stderr=subprocess.PIPE)
    1317    e = p.wait()
     
    1519        raise CodeError("Error %s in kinit: %s" % (e, p.stderr.read()))
    1620
    17 def checkKinit():
     21def checkKinit(principal=None, keytab=None):
    1822    """If we lack tickets, kinit."""
    1923    p = subprocess.Popen(['klist', '-s'])
    2024    if p.wait():
    21         kinit()
     25        kinit(principal, keytab)
    2226
    23 def remctl(*args, **kws):
     27def remctl(host, *args, **kws):
    2428    """Perform a remctl and return the output.
    2529
    2630    kinits if necessary, and outputs errors to stderr.
    2731    """
    28     checkKinit()
    29     p = subprocess.Popen(['remctl', config.remote.hostname]
     32    checkKinit(kws.get('principal'), kws.get('keytab'))
     33    p = subprocess.Popen(['remctl', host]
    3034                         + list(args),
    3135                         stdout=subprocess.PIPE,
Note: See TracChangeset for help on using the changeset viewer.