From 3b4eec37b0abdc4fbabd6ae45f1d56a1af51510c Mon Sep 17 00:00:00 2001 From: "t.moriyama" Date: Fri, 14 Jun 2013 22:11:04 +0900 Subject: [PATCH] add SSPVxlanAgent --- linkpair/collect/agent/sspvxlan_agent.py | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 linkpair/collect/agent/sspvxlan_agent.py diff --git a/linkpair/collect/agent/sspvxlan_agent.py b/linkpair/collect/agent/sspvxlan_agent.py new file mode 100755 index 0000000..4b50a60 --- /dev/null +++ b/linkpair/collect/agent/sspvxlan_agent.py @@ -0,0 +1,40 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# -*- coding: utf-8 -*- +# + +__version__ = '1.1' + +import re +import os +from linkpair.device import Device +from linkpair.port import Port +from linkpair.collect.agent.base_agent import BaseAgent + + +class SSPVxlanAgent(BaseAgent): + ''' + SSP VXLAN Collector Agent + ''' + + def run(self): + self.pick_vxlan_configuration() + + def pick_vxlan_configuration(self): + vxlan_base_dir = "/proc/net/vxlan/" + vxlan_if_dirs = self._runner.exec_cmd("ls " + vxlan_base_dir) + for vxlan_if_dir in vxlan_if_dirs: + vxlan_if_dir = vxlan_if_dir.strip() + if self._u.d_push(re.match(r'^(vxlan\d+)', vxlan_if_dir)) is not None: + match = self._u.d_pop() + vxlan_if_name = match.group(1) + vxlan_remote = self._runner.exec_cmd("cat " + vxlan_base_dir + vxlan_if_name + "/" + "remote") + vxlan_ifconfigs = self._runner.exec_cmd("ifconfig " + vxlan_if_name) + for vxlan_ifconfig in vxlan_ifconfigs: + vxlan_ifconfig = vxlan_ifconfig.strip() + if self._u.d_push(re.match(r'VXLAN VNI\s+:\s+(\d+)', vxlan_ifconfig)) is not None: + vxlan_vnid = self._u.d_pop().group(1) + port_meta = { + "vxlan_vnid": vxlan_vnid, "remote_ip": "\\\"" +vxlan_remote[0] + "\\\""} + self._cu.add_port(Port( + vxlan_if_name, Port.DEFAULT_TYPE, port_meta)) + break -- 2.11.0