#!/usr/bin/python3 from storage import Environment, Storage, BlkDevice, DeviceNotFound environment = Environment(True) storage = Storage(environment) storage.probe() probed = storage.get_probed() try: tmp = BlkDevice.find_by_name(probed, "/dev/sdz") print(tmp) except DeviceNotFound as e: print("device not found") print("done")
devicegraph = Devicegraph() sda = Disk.create(devicegraph, "/dev/sda") gpt = sda.create_partition_table(GPT) sda1 = gpt.create_partition("/dev/sda1") sda2 = gpt.create_partition("/dev/sda2") ext4 = sda1.create_filesystem(EXT4) swap = sda2.create_filesystem(SWAP) print devicegraph print "partitions on gpt:" for partition in gpt.get_partitions(): print " %s %s" % (partition, partition.get_number()) print print "descendants of sda:" for device in sda.get_descendants(False): print " %s" % device print tmp1 = BlkDevice.find(devicegraph, "/dev/sda1") print tmp1
devicegraph = Devicegraph() sda = Disk.create(devicegraph, "/dev/sda") gpt = sda.create_partition_table(PtType_GPT) sda1 = gpt.create_partition("/dev/sda1", Region(0, 1000, 512), PRIMARY) sda2 = gpt.create_partition("/dev/sda2", Region(1000, 1000, 512), PRIMARY) ext4 = sda1.create_filesystem(EXT4) swap = sda2.create_filesystem(SWAP) print devicegraph print "partitions on gpt:" for partition in gpt.get_partitions(): print " %s %s" % (partition, partition.get_number()) print print "descendants of sda:" for device in sda.get_descendants(False): print " %s" % device print tmp1 = BlkDevice.find(devicegraph, "/dev/sda1") print tmp1
#!/usr/bin/python from storage import Devicegraph, BlkDevice, DeviceNotFound devicegraph = Devicegraph() try: tmp = BlkDevice.find(devicegraph, "/dev/sda") print tmp except DeviceNotFound, e: print "device not found" print "done"