1 # vim: tabstop=4 shiftwidth=4 softtabstop=4
2 # -*- coding: utf-8 -*-
10 from linkpair.device import Device
11 from linkpair.port import Port
12 from linkpair.linkpair import LinkPair
13 from linkpair.formatter.grapheasy import GraphEasyFormatter
14 from linkpair.utils.common import CommonUtils
15 from linkpair.dbutils import DBUtils
16 from linkpair.collect.utils import CollectUtils
17 from linkpair.collect.collector_dataset import CollectorDataset
18 from linkpair.collect.agent.commandrunner import CommandRunner
19 from linkpair.collect.agent.linux_agent import LinuxAgent
20 from linkpair.collect.agent.namespace_agent import NamespaceAgent
21 from linkpair.collect.agent.veth_agent import VethAgent
22 from linkpair.collect.agent.ovs_agent import OVSAgent
23 from linkpair.collect.agent.linuxbridge_agent import LinuxBridgeAgent
24 from linkpair.collect.agent.linuxvlan_agent import LinuxVlanAgent
25 from linkpair.collect.agent.libvirt_agent import LibvirtAgent
28 class Collector(object):
29 '''LinkpPair collector
31 This class gets the LinkPair information from LinuxBridge and Open vSwitch and libvirt
36 def __init__(self, remote_desc, dbu, formatter=GraphEasyFormatter()):
42 self._iface_to_nss = {}
44 self._u = CommonUtils()
45 self._db_enable = False
47 self._remote_desc = remote_desc
48 self._ssh_username = ""
49 self._ssh_hostname = ""
50 self._ssh_hostport = 22
51 self._remote_password = ""
52 self._remote_sshkey = ""
53 self._ssh_keyauth = False
54 self._ssh_passauth = False
56 ''' set parameters '''
57 [self._ssh_username, self._ssh_hostname,
58 self._ssh_hostport] = self._u.parse_remote_desc(remote_desc)
60 self._formatter = formatter
61 self._runner = CommandRunner(self._remote_desc)
64 cd = CollectorDataset(
65 self._devices, self._ports, self._os_info, self._linkpairs,
66 self._port_to_br, self._iface_to_nss, self._veth_peer)
68 cd, self._dbu, self._formatter)
69 os_agent = LinuxAgent(
70 self._runner, cu, self._remote_desc, cd, self._formatter)
72 namespace_agent = NamespaceAgent(
73 self._runner, cu, self._remote_desc, cd, self._formatter)
75 veth_agent = VethAgent(
76 self._runner, cu, self._remote_desc, cd, self._formatter)
78 vlan_agent = LinuxVlanAgent(
79 self._runner, cu, self._remote_desc, cd, self._formatter)
82 self._runner, cu, self._remote_desc, cd, self._formatter)
84 bridge_agent = LinuxBridgeAgent(
85 self._runner, cu, self._remote_desc, cd, self._formatter)
87 libvirt_agent = LibvirtAgent(
88 self._runner, cu, self._remote_desc, cd, self._formatter)
91 def get_linkpairs(self):
92 return self._linkpairs
94 def set_remote_sshkey(self, remote_sshkey):
95 self._runner.set_remote_sshkey(remote_sshkey)
97 def set_remote_password(self, remote_password):
98 self._runner.set_remote_password(remote_password)