/usr/lib/xen-common/bin/xen-init-name is in xen-utils-common 4.9.2-0ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61  | #!/usr/bin/python
import json
import re
import sys
import subprocess
class SXPParser(object):
    tokenizer_rules = r""" (?P<open> \( ) | (?P<close> \) ) | (?P<whitespace> \s+ ) | [^()^\s]+ """
    tokenizer_re = re.compile(tokenizer_rules, re.X)
    @classmethod
    def loads(cls, input):
        data = []
        stack = []
        for match in cls.tokenizer_re.finditer(input):
            if match.group('open'):
                stack.append([])
            elif match.group('close'):
                top = stack.pop()
                if stack:
                    stack[-1].append(top)
                else:
                    data.append(top)
            elif match.group('whitespace'):
                pass
            else:
                if stack:
                    stack[-1].append(match.group())
        return data
class Data(object):
    def __call__(self, out):
        out.write('{}\n'.format(self.name))
class DataJSON(Data):
    def __init__(self, p):
        s = json.loads(p)
        self.name = s['c_info']['name']
class DataSXP(Data):
    def __init__(self, p):
        s = SXPParser.loads(p)
        for i in s:
            if i and i[0] == 'domain':
                data = dict(j for j in i if len(j) == 2)
                self.name = data['name']
                break
if __name__ == '__main__':
    p = subprocess.check_output(('xen', 'create', '--quiet', '--dryrun', '--defconfig', sys.argv[1]))
    if p[0] == '(':
        d = DataSXP(p)
    else:
        d = DataJSON(p)
    d(sys.stdout)
 |