Esempio n. 1
0
    def ps(self, psregex):
        psmatcher = re.compile(psregex)

        runner = AppRunner('ps -eo args')

        for line in runner.stdout():
            if psmatcher.match(line):
                print line.strip()
Esempio n. 2
0
    def getallpids(self):
        pids = []

        runner = AppRunner('ps --no-headers -eo pid,command')

        for line in runner.stdout():
            toks = line.strip().split()

            pids.append((int(toks[0]), toks[1]))

        return pids
Esempio n. 3
0
    def getnetworkdevicenames(self):
        runner = AppRunner('ip link show')

        devices = []

        devmatcher = re.compile(r'^\d+: (\w+):')

        for line in runner.stdout():
            match = devmatcher.match(line)

            if match:
                devices.append(match.group(1))

        return devices
Esempio n. 4
0
    def isdeviceup(self, device):
        #10: br1:  <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default
        devicematcher = re.compile(r'\d+: %s(?:@\w+)?: <(.*)>' % device)

        command = 'ip link show %s' % device

        e = AppRunner(command)

        for line in e.stdout():
            match = devicematcher.match(line)
            if match:
                attributes = match.group(1).split(',')
                return 'UP' in attributes

        return False
Esempio n. 5
0
    def _get_local_ip_addresses(self):
        ipaddrs = []

        matcher = re.compile(r'inet (\d+.\d+.\d+.\d+)/\d+')

        runner = AppRunner('ip addr show')

        lines = [line.strip() for line in runner.stdout()]

        for line in lines:
            match = matcher.match(line)

            if match:
                ipaddrs.append(match.group(1))

        return ipaddrs
Esempio n. 6
0
    def __init__(self):
        lines = AppRunner('lxc-execute --version').stdout().readlines()

        self._lxc_major_version = int(lines[0].decode().split('.')[0])