#!/usr/bin/env python3 """Attrappe von `rbd` - nur lesende Auskuenfte fuer die Bildschirmfotos. VM 9101 ist ein Linked Clone (haengt am Quell-Snapshot), VM 9102 ist bereits geloest. Genau diese beiden Zustaende soll das Handbuch zeigen. """ import sys VERBUNDEN = "vm-9101-disk-0" # haengt noch am Snapshot QUELLE = "vmdaten/vm-101-disk-0@auto-stuendlich-20260809-100000" # Optionen, hinter denen noch ein Wert steht - sonst haelt man "-m " # fuer den Befehl. MIT_WERT = {"-m", "--id", "--keyring", "-c", "--conf", "-p", "--pool", "--namespace", "-n", "--name"} def zerlege(argv): """(Befehl, Abbild) aus der Kommandozeile.""" rest = [] index = 0 while index < len(argv): wort = argv[index] if wort in MIT_WERT: index += 2 continue if wort.startswith("-"): index += 1 continue rest.append(wort) index += 1 return (rest[0] if rest else ""), (rest[1] if len(rest) > 1 else "") def main(argv): if not argv: return 1 befehl, ziel = zerlege(argv) name = ziel.split("/")[-1].split("@")[0] if befehl == "info": print("rbd image '%s':" % name) print("\tsize 400 GiB in 102400 objects") print("\torder 22 (4 MiB objects)") print("\tsnapshot_count: 0") print("\tid: 1f5c3d9a7b2e") print("\tblock_name_prefix: rbd_data.1f5c3d9a7b2e") print("\tformat: 2") print("\tfeatures: layering, exclusive-lock") print("\top_features:") print("\tflags:") if name == VERBUNDEN: print("\tparent: %s" % QUELLE) print("\toverlap: 400 GiB") return 0 if befehl == "du": print("NAME PROVISIONED USED") print("%-19s 400 GiB 2.4 GiB" % name) return 0 if befehl in ("flatten", "snap"): return 0 return 0 if __name__ == "__main__": sys.exit(main(sys.argv[1:]))