def umount(self): """ Unmount partition """ if self.invalid: raise PartitionError('Partition is invalid') mnt = mount.Mount(self.name, self.mountpoint, executor=self._executor) mnt.umount() self.refresh()
def umount(self): """ Unmount partition """ if self.invalid: raise PartitionError('Partition is invalid') # if self.hrd is None: # raise PartitionError('No HRD attached to disk') # path = self.hrd.get('mountpath') mnt = mount.Mount(self.name, self.mountpoint, executor=self._executor) mnt.umount() self.refresh()
def mount(self): """ Mount partition to `mountpath` defined in HRD """ if self.invalid: raise PartitionError('Partition is invalid') if self.hrd is None: raise PartitionError('No HRD attached to disk') path = self.hrd.get('mountpath') mnt = mount.Mount(self.name, path, executor=self._executor) mnt.mount() self.refresh()
def getDisks(self): """ Get list of all available disks on machine """ blks = lsblk.lsblk(executor=self._executor) devices = self._loaddisks(blks) # loading hrds for disk in devices: for partition in disk.partitions: if partition.fstype == 'swap' or\ not disks.isValidFS(partition.fstype): continue config = {} if partition.mountpoint != "" and partition.mountpoint is not None: # partition is already mounted, no need to remount it config = self._loadconfig(partition.mountpoint) elif partition.fstype: with mount.Mount(partition.name, options='ro', executor=self._executor) as mnt: config = self._loadconfig(mnt.path) partition.config = config self.logger.debug("found partition: %s:%s" % (disk, partition)) def findDisk(devices, name): for item in devices: if item.name == name: return item raise j.exceptions.RuntimeError("could not find disk:%s" % name) for device in devices: if device.mirror_devices != [] and device.mountpoint == "": # find the mountpoint of one the mirrors for mir in device.mirror_devices: disk = findDisk(devices, mir) if disk.mountpoint != "": device.mountpoint = disk.mountpoint self.disks = devices return devices
def _dumpCONFIG(self): with mount.Mount(self.name, executor=self._executor) as mnt: filepath = j.tools.path.get(mnt.path).joinpath('.disk.hrd') filepath.write_text(str(self.hrd)) filepath.chmod(400)