Changeset 1614 for trunk/packages


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

Actually generalize the invirt.remctl module

Location:
trunk/packages
Files:
2 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,
  • trunk/packages/invirt-web/code/controls.py

    r1613 r1614  
    1010from invirt.config import structs as config
    1111from invirt.database import Machine, Disk, Type, NIC, CDROM, session, meta
    12 from invirt.remctl import remctl
     12from invirt.remctl import remctl as gen_remctl
    1313
    1414# ... and stolen from xend/uuid.py
     
    2323                     "%02x" * 6]) % tuple(u)
    2424# end stolen code
     25
     26def remctl(*args, **kwargs):
     27    return gen_remctl(config.remote.hostname, *args,
     28                      principal='daemon/'+config.web.hostname,
     29                      **kwargs)
    2530
    2631def lvcreate(machine, disk):
Note: See TracChangeset for help on using the changeset viewer.