1 # vim: tabstop=4 shiftwidth=4 softtabstop=4
2 # -*- coding: utf-8 -*-
6 from linkpair.device import Device
7 from linkpair.port import Port
8 from linkpair.linkpair import LinkPair
9 from linkpair.collect.agent.base_agent import BaseAgent
12 class NamespaceAgent(BaseAgent):
16 This class gets the network namespace information from ip command
20 self.map_port_to_namespace()
22 def map_port_to_namespace(self):
23 result = self._runner.exec_cmd("ip netns")
27 result2 = self._runner.exec_cmd(
28 "ip netns exec " + ns + " ip link show")
29 for linkpair_out in result2:
30 linkpair_out = linkpair_out.rstrip()
31 match = re.match(r'\d+: (.*?): ', linkpair_out)
32 if match is not None and match.group(1) != 'lo':
33 self._iface_to_nss[match.group(1).rstrip()] = ns