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 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. 3
0
def rmloop(device):
	try:
		system((LOSETUP_EXEC, '-d', device))
	except StorageError, e:
		if 'No such device or address' in e.err:
			''' Silently pass non-existed loop removal '''
			pass
		else:
			raise
Esempio n. 4
0
def rmloop(device):
    try:
        system((LOSETUP_EXEC, '-d', device))
    except StorageError, e:
        if 'No such device or address' in e.err:
            ''' Silently pass non-existed loop removal '''
            pass
        else:
            raise
Esempio n. 5
0
def listloop():
	ret = {}
	loop_lines = system((LOSETUP_EXEC, '-a'))[0].strip().splitlines()
	for loop_line in loop_lines:
		words = loop_line.split()
		ret[words[0][:-1]] = words[-1][1:-1]
	return ret
Esempio n. 6
0
def listloop():
    ret = {}
    loop_lines = system((LOSETUP_EXEC, '-a'))[0].strip().splitlines()
    for loop_line in loop_lines:
        words = loop_line.split()
        ret[words[0][:-1]] = words[-1][1:-1]
    return ret
Esempio n. 7
0
def free():
    cmd = (FREE_EXEC, '-m')
    out_lines = system(cmd)[0].splitlines()
    free_ram = int(out_lines[1].split()[3])
    free_swap = int(out_lines[3].split()[3])
    return (free_ram, free_swap)
    
    
Esempio n. 8
0
def mkloop(filename, device=None, size=None, quick=False):
	''' Create loop device '''
	if size and not os.path.exists(filename):
		cmd = ['dd', 'if=/dev/zero', 'of=%s' % filename, 'bs=1M']
		if quick:
			cmd.extend(['seek=%d' % (size - 1,), 'count=1'])
		else:
			cmd.extend(['count=%d' % size])
		system(cmd)
	if not device:
		system((LOSETUP_EXEC, '-f', filename))
		loops = listloop()
		for loopdev, fname in loops.iteritems():
			if fname == filename:
				return loopdev
		else:
			raise Exception('Cannot find loop device with %s file' % file)
	else:
		system((LOSETUP_EXEC, device, filename))
	return device
Esempio n. 9
0
def mkloop(filename, device=None, size=None, quick=False):
    ''' Create loop device '''
    if size and not os.path.exists(filename):
        cmd = ['dd', 'if=/dev/zero', 'of=%s' % filename, 'bs=1M']
        if quick:
            cmd.extend(['seek=%d' % (size - 1, ), 'count=1'])
        else:
            cmd.extend(['count=%d' % size])
        system(cmd)
    if not device:
        system((LOSETUP_EXEC, '-f', filename))
        loops = listloop()
        for loopdev, fname in loops.iteritems():
            if fname == filename:
                return loopdev
        else:
            raise Exception('Cannot find loop device with %s file' % file)
    else:
        system((LOSETUP_EXEC, device, filename))
    return device
Esempio n. 10
0
def create(size, mpoint):
    if not os.path.exists(mpoint):
        os.makedirs(mpoint)
    cmd = (MOUNT_EXEC, '-t', 'tmpfs', '-o','size=%sM'%size, 'tmpfs', mpoint)
    system(cmd, error_text="Can't create ramdisk.")
Esempio n. 11
0
def free():
    cmd = (FREE_EXEC, '-m')
    out_lines = system(cmd)[0].splitlines()
    free_ram = int(out_lines[1].split()[3])
    free_swap = int(out_lines[3].split()[3])
    return (free_ram, free_swap)
Esempio n. 12
0
def create(size, mpoint):
    if not os.path.exists(mpoint):
        os.makedirs(mpoint)
    cmd = (MOUNT_EXEC, '-t', 'tmpfs', '-o', 'size=%sM' % size, 'tmpfs', mpoint)
    system(cmd, error_text="Can't create ramdisk.")