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:
25 return "%s%d," % ("-" if cpu-last_cpu > 2 else ",", cpu-1)
42 output += finish_cpu_list(last_cpu, cpu)
46 output += finish_cpu_list(last_cpu, cpu)
47 return output.strip(",")
51 print("usage: %s" % os.path.basename(sys.argv[0]).replace("-", " "))
52 exit(0 if sys.argv[1] in ("--help", "-h") else 1)
55 for cell_path in glob.glob('/sys/devices/jailhouse/cells/*'):
57 'name': os.path.basename(cell_path),
58 'id': open(cell_path + "/id").readline().strip(),
59 'state': open(cell_path + "/state").readline().strip(),
60 'cpus_assigned': read_cpus(cell_path + "/cpus_assigned"),
61 'cpus_failed': read_cpus(cell_path + "/cpus_failed")
64 line_format = "%-8s%-24s%-16s%-24s%-24s"
66 print(line_format % ("ID", "Name", "State",
67 "Assigned CPUs", "Failed CPUs"))
68 for cell in sorted(cells, key=lambda cell: cell['id']):
69 print(line_format % (cell['id'], cell['name'], cell['state'],
70 print_cpus(cell['cpus_assigned']),
71 print_cpus(cell['cpus_failed'])))