OSDN Git Service

refactoring...
[ti2/ti2.git] / linkpair / collect / agent / namespace_agent.py
1 # vim: tabstop=4 shiftwidth=4 softtabstop=4
2 # -*- coding: utf-8 -*-
3 #
4
5 import re
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
10
11
12 class NamespaceAgent(BaseAgent):
13
14     '''network Namespace
15
16     This class gets the network namespace information from ip command
17     '''
18
19     def run(self):
20         self.map_port_to_namespace()
21
22     def map_port_to_namespace(self):
23         result = self._runner.exec_cmd("ip netns")
24     # if result....
25         for ns in result:
26             ns = ns.rstrip()
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