OSDN Git Service

move namespace.py to namespace_agent.py
authort.moriyama <t.moriyama@users.sourceforge.jp>
Fri, 19 Apr 2013 09:23:51 +0000 (18:23 +0900)
committert.moriyama <t.moriyama@users.sourceforge.jp>
Fri, 19 Apr 2013 09:23:51 +0000 (18:23 +0900)
linkpair/collect/agent/namespace_agent.py [new file with mode: 0755]

diff --git a/linkpair/collect/agent/namespace_agent.py b/linkpair/collect/agent/namespace_agent.py
new file mode 100755 (executable)
index 0000000..a06a195
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+
+__version__ = '1.1'
+
+import sys
+import os
+import re
+from xml.dom import minidom
+from subprocess import Popen, PIPE
+from socket import gethostname
+from linkpair.device import Device
+from linkpair.port import Port
+from linkpair.linkpair import LinkPair
+from linkpair.collect.utils import CollectUtils
+from linkpair.collect.agent.commandrunner import CommandRunner
+from linkpair.formatter.grapheasy import GraphEasyFormatter
+from linkpair.commonutils import CommonUtils
+
+
+class NamespaceAgent(object):
+    '''network Namespace
+
+    This class gets the network namespace information from ip command
+    '''
+
+    PEER_FOUND = 1
+
+    def __init__(self, runner, cu, iface_to_nss):
+        self._runner = runner
+        self._cu = cu
+        self._iface_to_nss = iface_to_nss
+        self._u = CommonUtils()
+    def run(self):
+           self.map_port_to_namespace()
+           
+    def map_port_to_namespace(self):
+        result = self._runner.exec_cmd("ip netns")
+    # if result....
+        for ns in result:
+            ns = ns.rstrip()
+            result2 = self._runner.exec_cmd("ip netns exec " + ns + " ip link show")
+            for linkpair_out in result2:
+                linkpair_out = linkpair_out.rstrip()
+                match = re.match(r'\d+: (.*?): ', linkpair_out)
+                if match is not None and match.group(1) != 'lo':
+                    self._iface_to_nss[match.group(1).rstrip()] = ns