2 Functions to perform remctls.
10 def kinit(principal=None, keytab=None):
11 """Kinit with a given username and keytab"""
13 principal = 'daemon/' + getfqdn()
15 keytab = '/etc/invirt/keytab'
17 subprocess.run(['kinit', '-k', '-t', keytab, principal],
18 check_output=True, encoding='utf-8', check=True)
20 def check_kinit(principal=None, keytab=None):
21 """If we lack tickets, kinit."""
24 subprocess.run(['klist', '-s'])
25 except subprocess.CalledProcessError:
26 #TODO: Does this return a specific error code that we can check for?
27 kinit(principal, keytab)
29 def remctl(host, *args, **kws):
30 """Perform a remctl and return the output.
32 kinits if necessary, and outputs errors to stderr.
35 check_kinit(kwargs.get('principal'), kwargs.get('keytab'))
37 return subprocess.run(['remctl', host] + list(args),
38 check_output=True, encoding='utf-8', check=True)