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