def bird_info(self): birdv = self.machine.run("echo | birdc | head -1").strip().replace(" ready.", "") birdv = birdv.split(" ") info = { "daemon": birdv[0], "version": birdv[1], "ospf": {} } log.info("[%s] getting OSPF neighbours" % self.hostname()) output = self.machine.run("echo show ospf neighbors | birdc | sed '/^bird[^ ] .*/d'") neighbours = [] for toks in [tokenize(l) for l in splitlines(output)[2:]]: neighbour = { "routerid": toks[0] } if toks[4][0] in ascii_letters: neighbour["ifname"] = toks[4] neighbour["v4addr"] = toks[5] else: neighbour["v4addr"] = toks[4] neighbour["ifname"] = toks[5] neighbours.append(neighbour) info["ospf"]["neighbours"] = neighbours return info
def v4addr(self, iface): output = self.machine.run("ip addr show dev %s | grep '^ *inet '" % iface).strip() def parseaddr(a): a = a.strip() if "/" not in a: return a + "/32" return a tokset = [tokenize(l) for l in splitlines(output)] return [parseaddr(toks[1]) for toks in tokset if len(toks) > 0]
def quagga_info(self): output = self.machine.run("zebra --version") info = { "daemon": "Quagga", "version": tokenize(splitlines(output)[0])[-1], "ospf": {} } neighbours = [] log.info("[%s] getting OSPF neighbours" % self.hostname()) output = self.machine.run("echo show ip ospf neighbor | vtysh | grep '^[1-9]'") for toks in [tokenize(l) for l in splitlines(output)]: if len(toks) == 0: continue neighbour = { "routerid": toks[0], "v4addr": toks[4], "ifname": toks[5].split(":")[0] } neighbours.append(neighbour) info["ospf"]["neighbours"] = neighbours return info
def _routes(): for toks in [tokenize(l) for l in splitlines(output)]: if len(toks) < 3: continue network, nexthop = toks[0], toks[2] if network == "default": network = "0.0.0.0/0" if "/" not in network: network = network + "/32" addr, _ = network.split("/") if is_bogon(addr): continue yield { "network": network, "nexthop": nexthop }
def procs(self): output = self.machine.run("ps w | sed 's/S </S/' | awk '{ print $5 }'") return splitlines(output)[1:]
def _neighbours(): for toks in [tokenize(l) for l in splitlines(output)]: if len(toks) == 0: continue v4addr, mac = toks[0], toks[3] yield { "v4addr": v4addr, "mac": mac.upper() }
def _ifs(): for toks in [tokenize(l) for l in splitlines(output)[2:]]: if len(toks) == 0: continue ifname = toks[0].split(":")[0] yield ifname
def procs(self): output = self.machine.run("ps xw | awk '{ print $5; }'") return splitlines(output)[1:]