Example #1
0
def call_umount(umountdir, lazy=False):
    if lazy:
        cmd = [UMOUNT, '-l']
    else:
        cmd = [UMOUNT]
    cmd.append(umountdir)
    return tools.popen2log(cmd, LOG)
Example #2
0
    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
Example #3
0
def call_umount(umountdir, lazy=False):
    umnt = which('umount')
    if lazy:
        cmd = [umnt, '-l']
    else:
        cmd = [umnt]
    cmd.append(umountdir)
    return popen2log(cmd, LOG)
Example #4
0
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))
Example #5
0
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))
Example #6
0
 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)
Example #7
0
File: qemu.py Project: Sedl/servus
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)
Example #8
0
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)
Example #9
0
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)
Example #10
0
def call_mount(params):
    return tools.popen2log([MOUNT] + params, LOG)
Example #11
0
def call_mount(params):
    mnt = which('mount')
    return popen2log([mnt] + params, LOG)