def call_umount(umountdir, lazy=False): if lazy: cmd = [UMOUNT, '-l'] else: cmd = [UMOUNT] cmd.append(umountdir) return tools.popen2log(cmd, LOG)
def do_partition(self, partlist): '''Takes a list of partitions and - properly aligns the partitions - fills in the one partition without partition size given - runs parted on the disk to create the partitions on the device :param list partlist: list of :py:class:`servus.block.Partition`\ instances :raises DiskError: if something failed ''' if not self._attached: raise exc.DiskError('ERROR: Disk is not attached.') parts_align(partlist, self.size) cmd = parted.parts2partedcmd(partlist) LOG.info('Running GNU parted on %s with the following command: %s' % \ (self._blockdevice, repr(cmd))) #_, stderr, retcode = parted.call_parted(self._blockdevice, [cmd]) pcmd = [parted.PARTED, '-ms', self._blockdevice, cmd] retcode = tools.popen2log(pcmd, LOG) # print stdout, stderr if not retcode == 0: raise exc.DiskError('GNU parted returned a non zero exit '\ 'status (%d).' % retcode) blktools.detect_parts_devnames(partlist, self._blockdevice) self._partitions = partlist
def call_umount(umountdir, lazy=False): umnt = which('umount') if lazy: cmd = [umnt, '-l'] else: cmd = [umnt] cmd.append(umountdir) return popen2log(cmd, LOG)
def mount(block, target): '''Mounts a partition to the given directory :param str block: block device :param str target: target directory :raises DiskError:''' exitc = tools.popen2log([MOUNT, block, target], LOG) if not exitc == 0: raise exc.DiskError('Mount to \'%s\' failed for \'%s\'' % (target, block))
def mount(block, target): '''Mounts a partition to the given directory :param str block: block device :param str target: target directory :raises DiskError:''' mnt = which('mount') exitc = popen2log([mnt, block, target], LOG) if not exitc == 0: raise DiskError('Mount to "%s" failed for "%s"' % (target, block))
def umount(self, mountpoint, lazy=False): '''Unmounts a previously mounted partition''' targd = self._mounts[mountpoint] umnt = which('umount') cmd = [umnt] if lazy: cmd += ['-l'] cmd += [targd] exitc = popen2log(cmd, LOG) if not exitc == 0: raise DiskError('Unmounting of %s failed. See the logs for '\ 'details' % (targd,)) os.rmdir(targd)
def create_imagefile(filename, size, iformat): '''Creates an image file and logs the output to the modules logger :param str filename: filename of the image :param int size: size in bytes :param str iformat: from qemu-img supported image format :raises servus.exceptions.DiskError: if the image creation failed ''' cmd = [QEMU_IMG, 'create', '-f', iformat, filename, str(size)] retc = popen2log(cmd, LOG) if not retc == 0: raise DiskError('Image file creation failed. qemu-img returned '\ 'exit code %i' % retc)
def mkfs_swap(path, label=None, uuid=None): '''Runs mkswap on the given partition :param str path: path to the partition :param str label: an optional label for the swap partition :param str uuid: use this UUID instead of generating a new one :returns int: exit vode of mkswap''' if not MKSWAP: raise exc.DiskError('Can\'t find mkswap executable') cmd = [MKSWAP] if label: cmd += ['-L', label] if uuid: cmd += ['-U', uuid] cmd += [path] LOG.info('Running mkswap: %s' % ' '.join(repr(c) for c in cmd)) ecode = popen2log(cmd, LOG) if not ecode == 0: raise exc.MkfsError( 'mkswap returned a non zero exit code: %d' % ecode, ecode)
def mkfs_ext(path, filesystem, label=None, uuid=None): '''Formats a partition with the given file system :param str path: path to the image/partition :param str filesystem: one of ext2, ext3 or ext4 :param str label: optional filesysten label :param str uuid: use specified UUID instead of generating a new one :returns int: exit code of mkfs ''' if MKFS is None: raise exc.DiskError('Can\'t find mkfs executable') cmd = [MKFS, '-t', filesystem, '-F'] if label: cmd += ['-L', label] if uuid: cmd += ['-U', uuid] cmd += (path, ) LOG.info('Running mkfs: %s' % ' '.join(repr(c) for c in cmd)) ecode = popen2log(cmd, LOG) if not ecode == 0: raise exc.MkfsError( 'mkfs returned a non zero exit code: %d' % ecode, ecode)
def call_mount(params): return tools.popen2log([MOUNT] + params, LOG)
def call_mount(params): mnt = which('mount') return popen2log([mnt] + params, LOG)