Esempio n. 1
0
def destroy(mpoint, force=False):
    if not os.path.ismount(mpoint):
        raise StorageError('Directory %s is not valid mount point' % mpoint)
    cmd = [UMOUNT_EXEC, mpoint]
    if force:
        cmd.insert(1, '-f')
    system(tuple(cmd), error_text="Can't destroy ramdisk.")
Esempio n. 2
0
def findname():
    """ Return unused md device name """
    for i in range(1000):
        dev = '/dev/md%s' % i
        if not os.path.exists(dev):
            return dev

    raise StorageError("No unused raid device name left")
Esempio n. 3
0
def mdfind(*devices):
    """ Return md name that contains passed devices """
    devices_base = map(os.path.basename, devices)

    with open('/proc/mdstat') as f:
        stat = f.readlines()

    for line in stat:
        if all(map(lambda x: x in line, devices_base)):
            array = '/dev/%s' % line.split()[0]
            md_info = detail(array)
            md_devices = md_info['devices'].keys()
            md_devices = map(os.path.realpath, md_devices)
            if sorted(md_devices) == sorted(devices):
                return array
    else:
        raise StorageError("Devices aren't part of any array: %s" %
                           ', '.join(devices))
Esempio n. 4
0
 def side_eff(device):
     if device == '/dev/md0':
         return md0_details
     else:
         raise StorageError('Unknown device')