1 # vim: tabstop=4 shiftwidth=4 softtabstop=4
2 # -*- coding: utf-8 -*-
8 from linkpair.device import Device
9 from linkpair.port import Port
10 from linkpair.collect.agent.base_agent import BaseAgent
13 class LinuxBridgeAgent(BaseAgent):
15 Linux bridge Collector Agent
19 self.pick_bridge_configuration()
21 def pick_bridge_configuration(self):
23 result = self._runner.exec_cmd("brctl show")
24 for br_line in result:
25 br_line = br_line.rstrip()
26 if self._u.d_push(re.match(r'^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$', br_line)) is not None:
27 match = self._u.d_pop()
28 br_name = match.group(1)
30 if port not in self._port_to_br and br_name != "":
31 self._port_to_br[port] = br_name
32 ## for OpenStack quntum...
33 if self._u.d_push(re.match(r'^qvb(.+)', port)):
34 quantum_idprefix = self._u.d_pop().group(1)
35 if "qvo" + quantum_idprefix in self._port_to_br:
36 self._cu.add_linkpair(
37 Device(br_name, Device.BR_TYPE),
38 Device(self._port_to_br[
39 "qvo" + quantum_idprefix], Device.BR_TYPE),
41 Port("qvo" + quantum_idprefix),
42 self._formatter.VETH_FORMAT)
44 self._cu.add_linkpair(
46 Device("INTERNAL", Device.OS_ROUTE_TYPE),
50 # print self._port_to_br.keys()
51 # if self._u.d_push(re.match(r'^qvo(.+)', port)):
53 # add_linkpair(self.DEFAULT_FORMAT, br_name, self.DEFAULT_TYPE, port, \
54 # "INTERNAL", self.OS_ROUTE_TYPE )
56 elif self._u.d_push(re.match(r'^\s+(\S+)$', br_line)) is not None:
57 port = self._u.d_pop().group(1)
58 if port not in self._port_to_br and br_name != "":
59 self._port_to_br[port] = br_name
60 ## for OpenStack quntum...
61 if self._u.d_push(re.match(r'^qvb(.+)', port)):
62 quantum_idprefix = self._u.d_pop().group(1)
63 if "qvo" + quantum_idprefix in self._port_to_br:
64 self._cu.add_linkpair(
65 Device(br_name, Device.BR_TYPE),
66 Device(self._port_to_br[
67 "qvo" + quantum_idprefix], Device.BR_TYPE),
69 Port("qvo" + quantum_idprefix),
70 self._formatter.VETH_FORMAT)
72 if self._u.d_push(re.match(r'^qvo(.+)', port)):
74 self._cu.add_linkpair(
76 Device("INTERNAL", Device.OS_ROUTE_TYPE),