Exemplo n.º 1
0
    def update(self):
        """
        Update list of FreeBSD mountpoints based on /sbin/mount output
        """
        self.__delslice__(0, len(self))

        try:
            output = check_output(['/sbin/mount'])
        except CalledProcessError:
            raise FileSystemError('Error running /sbin/mount')

        for l in [l for l in output.split('\n') if l.strip() != '']:
            if l[:4] == 'map ':
                continue

            m = RE_MOUNT.match(l)
            if not m:
                continue

            device = m.group(1)
            mountpoint = m.group(2)
            flags = map(lambda x: x.strip(), m.group(3).split(','))
            filesystem = flags[0]
            flags = flags[1:]

            entry = BSDMountPoint(device, mountpoint, filesystem)
            for f in flags:
                entry.flags.set(f, True)

            self.append(entry)
Exemplo n.º 2
0
    def usage(self):
        """
        Check usage percentage for this mountpoint.
        Returns dictionary with usage details.
        """
        if self.filesystem in PSEUDO_FILESYSTEMS:
            return {}

        try:
            output = check_output(['df', '-k', self.mountpoint])
        except CalledProcessError:
            raise FileSystemError('Error getting usage for %s' %
                                  self.mountpoint)

        header, usage = output.split('\n', 1)
        try:
            usage = ' '.join(usage.split('\n'))
        except ValueError:
            pass

        fs, size, used, free, percent, mp = map(lambda x: x.strip(),
                                                usage.split())
        percent = percent.rstrip('%')
        return {
            'mountpoint': self.mountpoint,
            'size': long(size),
            'used': long(used),
            'free': long(free),
            'percent': int(percent)
        }
Exemplo n.º 3
0
    def update_usage(self, line=None):
        """
        Check usage percentage for this mountpoint.
        Returns dictionary with usage details.
        """
        if self.filesystem in PSEUDO_FILESYSTEMS:
            return {}

        if line is None:
            parser = ShellCommandParser()
            try:
                stdout, stderr = parser.execute('df', '-Pk', self.mountpoint)
            except ShellCommandParserError:
                raise FileSystemError('Error getting usage for {0}'.format(self.mountpoint))

            header, usage = stdout.split('\n', 1)
            try:
                usage = ' '.join(usage.split('\n'))
            except ValueError:
                pass

        else:
            usage = ' '.join(line.split('\n'))

        fs, size, used, free, percent, mp = [x.strip() for x in usage.split()]
        percent = percent.rstrip('%')

        self.usage = {
            'mountpoint': self.mountpoint,
            'size': int(size),
            'used': int(used),
            'free': int(free),
            'percent': int(percent),
        }
Exemplo n.º 4
0
def load_mountpoints():
    """
    Update list of linux mountpoints based on /bin/mount output
    """
    mountpoints = []

    try:
        output = check_output(['/bin/mount'])
    except CalledProcessError:
        raise FileSystemError('Error running /bin/mount')

    for l in [l for l in output.split('\n') if l.strip() != '']:
        if l[:4] == 'map ':
            continue

        m = RE_MOUNT.match(l)
        if not m:
            continue

        device = m.group(1)
        mountpoint = m.group(2)
        filesystem = m.group(3)
        flags = map(lambda x: x.strip(), m.group(4).split(','))

        entry = LinuxMountPoint(device, mountpoint, filesystem)
        for f in flags:
            entry.flags.set(f, True)

        mountpoints.append(entry)

    return mountpoints
Exemplo n.º 5
0
def load_mountpoints(self):
    """
    Update list of FreeBSD mountpoints based on /sbin/mount output
    """
    mountpoints = []

    parser = ShellCommandParser()
    try:
        stdout, stderr = parser.execute('mount')
    except ShellCommandParserError as e:
        raise FileSystemError('Error running mount: {0}'.format(e))

    for l in [l for l in stdout.split('\n') if l.strip() != '']:
        if l[:4] == 'map ':
            continue

        m = RE_MOUNT.match(l)
        if not m:
            continue

        device = str(m.group(1))
        mountpoint = str(m.group(2))
        flags = [str(x.strip()) for x in m.group(3).split(',')]
        filesystem = flags[0]
        flags = flags[1:]

        entry = BSDMountPoint(self, device, mountpoint, filesystem)
        if entry.is_virtual:
            continue

        for f in flags:
            entry.flags.set(f, True)

        mountpoints.append(entry)

    try:
        stdout, stderr = parser.execute('df', '-k')
    except ShellCommandParserError as e:
        raise FileSystemError('Error running mount: {0}'.format(e))

    for mountpoint in mountpoints:
        for line in stdout.splitlines():
            if line.split()[0] == mountpoint.device:
                mountpoint.update_usage(line)

    return mountpoints