OSDN Git Service

add NamespaceAgent
authort.moriyama <t.moriyama@users.sourceforge.jp>
Sun, 14 Apr 2013 02:10:56 +0000 (11:10 +0900)
committert.moriyama <t.moriyama@users.sourceforge.jp>
Sun, 14 Apr 2013 02:10:56 +0000 (11:10 +0900)
linkpair/collect/agent/namespace.py [new file with mode: 0644]
linkpair/collect/agent/ovs.py
linkpair/collect/collector.py

diff --git a/linkpair/collect/agent/namespace.py b/linkpair/collect/agent/namespace.py
new file mode 100644 (file)
index 0000000..ce0f965
--- /dev/null
@@ -0,0 +1,44 @@
+#!/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.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, iface_to_nss):
+        self._runner = runner
+        self._iface_to_nss = iface_to_nss
+        self._u = CommonUtils()
+        
+    def run(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
index 604ce7c..e4685e0 100755 (executable)
@@ -13,6 +13,7 @@ from socket import gethostname
 from device import Device
 from port import Port
 from linkpair import LinkPair
+from linkpair.collect.agent.commandrunner import CommandRunner
 from formatter.grapheasy import GraphEasyFormatter
 from commonutils import CommonUtils
 
index 1b6cec7..821f059 100755 (executable)
@@ -19,6 +19,8 @@ from linkpair.formatter.grapheasy import GraphEasyFormatter
 from linkpair.commonutils import CommonUtils
 from linkpair.dbutils import DBUtils
 from linkpair.collect.agent.commandrunner import CommandRunner
+from linkpair.collect.agent.namespace import NamespaceAgent
+
 
 class Collector(object):
     '''LinkpPair collector
@@ -51,7 +53,9 @@ class Collector(object):
         self._runner = CommandRunner(self._remote_desc)
         
     def run(self):
-        self.map_port_to_namespace()
+        #self.map_port_to_namespace()
+        namespace_agent = NamespaceAgent(self._runner, self._iface_to_nss)
+        namespace_agent.run()
         self.pick_ovs_configuration()
         self.pick_bridge_configuration()
         self.pick_libvirt_configuration()