def createPartitions(self): """ creates new partition table """ if not self.exists(): raise ComException("Device %s not found" % self.getDeviceName()) import ComParted phelper=ComParted.getInstance() phelper.createPartitions(self.getDeviceName(), self.getAllPartitions(), self.sameSize()) self.stabilize()
def initFromDiskParted(self): import parted import ComParted phelper=ComParted.PartedHelper() dev=parted.PedDevice.get(self.getDeviceName()) try: disk=parted.PedDisk.new(dev) partlist=phelper.get_primary_partitions(disk) for part in partlist: self.appendChild(Partition(part, self.getDocument())) except parted.error: HostDisk.log.debug("no partitions found")
def createPartitionsParted(self): import parted import ComParted if not self.exists(): raise ComException("Device %s not found" % self.getDeviceName()) phelper=ComParted.PartedHelper() #IDEA compare the partition configurations for update #1. delete all aprtitions dev=parted.PedDevice.get(self.getDeviceName()) try: disk=parted.PedDisk.new(dev) disk.delete_all() except parted.error: #FIXME use generic disk types disk=dev.disk_new_fresh(parted.disk_type_get("msdos")) # create new partitions for com_part in self.getAllPartitions(): type=com_part.getPartedType() if self.sameSize(): size=com_part.getPartedSize(dev) else: size=com_part.getPartedSizeOptimum(dev) flags=com_part.getPartedFlags() self.log.debug("creating partition: size: %i" % size ) phelper.add_partition(disk, type, size, flags) disk.commit() self.commit() #dev.sync() #dev.close() # run partx if the device is a multipath device self.log.debug("ComHostDisk: checking for multipath devices") if self.isDMMultipath(): self.log.debug("Device %s is a dm_multipath device, adding partitions" %self.getDeviceName()) __cmd=CMD_KPARTX + " -d " + self.getDeviceName() try: __ret = ComSystem.execLocalOutput(__cmd, True, "") self.log.debug(__ret) __cmd=CMD_KPARTX + " -a " + self.getDeviceName() __ret = ComSystem.execLocalOutput(__cmd, True, "") self.log.debug(__ret) #FIXME: crappy fix to give os some time to create devicefiles. time.sleep(10) except ComSystem.ExecLocalException, ele: ComLog.debugTraceLog(self.log) self.log.debug("Could not execute %s. Error %s" %(ele.cmd, ele))
def initFromDisk(self): """ reads partition information from the disk and fills up DOM with new information """ HostDisk.log.debug("initFromDisk()") #FIXME: create LabelResolver if self.refByLabel(): pass if not self.exists(): raise ComException("Device %s not found or no valid device!" % self.getDeviceName()) import ComParted phelper=ComParted.getInstance() for partition in phelper.initFromDisk(self.getDeviceName()): self.addPartition(Partition(partition, self.getDocument()))
def __create_element_from_parted(self, part, doc): import ComParted element = doc.createElement(self.TAGNAME) phelper = ComParted.getInstance() # name element.setAttribute("name", str(phelper.getPartNumber(part))) # type element.setAttribute("type", self.__name_of_part_type(phelper.getPartType(part))) # size element.setAttribute("size", str(phelper.getPartSize(part))) # start # element.setAttribute("start", str(part.geom.start)) # end # element.setAttribute("end", str(part.geom.end)) # all flags for flag in phelper.get_flags_as_string(part): if flag and flag != "": felem = PartitionFlag(doc.createElement("flag"), doc) felem.setAttribute("name", flag) element.appendChild(felem.getElement()) return element