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()
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
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
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
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
def __init__(self): lines = AppRunner('lxc-execute --version').stdout().readlines() self._lxc_major_version = int(lines[0].decode().split('.')[0])