3 # Jailhouse, a Linux-based partitioning hypervisor
5 # Copyright (c) Siemens AG, 2014
8 # Jan Kiszka <jan.kiszka@siemens.com>
10 # This work is licensed under the terms of the GNU GPL, version 2. See
11 # the COPYING file in the top-level directory.
19 return int(open(path).readline().strip().replace(",", ""), 16)
22 def finish_cpu_list(last_cpu, cpu):
23 if last_cpu is not None and cpu-last_cpu > 1:
24 return "%s%d," % ("-" if cpu-last_cpu > 2 else ",", cpu-1)
39 output += finish_cpu_list(last_cpu, cpu)
43 output += finish_cpu_list(last_cpu, cpu)
44 return output.strip(",")
48 print("usage: %s" % os.path.basename(sys.argv[0]).replace("-", " "))
49 exit(0 if sys.argv[1] in ("--help", "-h") else 1)
52 for cell_path in glob.glob('/sys/devices/jailhouse/cells/*'):
54 'name': os.path.basename(cell_path),
55 'id': open(cell_path + "/id").readline().strip(),
56 'state': open(cell_path + "/state").readline().strip(),
57 'cpus_assigned': read_cpus(cell_path + "/cpus_assigned"),
58 'cpus_failed': read_cpus(cell_path + "/cpus_failed")
61 line_format = "%-8s%-24s%-16s%-24s%-24s"
63 print(line_format % ("ID", "Name", "State",
64 "Assigned CPUs", "Failed CPUs"))
65 for cell in sorted(cells, key=lambda cell: cell['id']):
66 print(line_format % (cell['id'], cell['name'], cell['state'],
67 print_cpus(cell['cpus_assigned']),
68 print_cpus(cell['cpus_failed'])))