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.commonutils import CommonUtils
15 from linkpair.dbutils import DBUtils
16 from linkpair.collect.utils import CollectUtils
17 from linkpair.collect.agent.commandrunner import CommandRunner
18 from linkpair.collect.agent.namespace_agent import NamespaceAgent
19 from linkpair.collect.agent.ovs_agent import OVSAgent
20 from linkpair.collect.agent.linuxbridge_agent import LinuxBridgeAgent
21 from linkpair.collect.agent.libvirt_agent import LibvirtAgent
24 class Collector(object):
25 '''LinkpPair collector
27 This class gets the LinkPair information from LinuxBridge and Open vSwitch and libvirt
32 def __init__(self, remote_desc, dbu, formatter=GraphEasyFormatter()):
35 self._iface_to_nss = {}
36 self._u = CommonUtils()
38 self._db_enable = False
40 self._remote_desc = remote_desc
41 self._ssh_username = ""
42 self._ssh_hostname = ""
43 self._ssh_hostport = 22
44 self._remote_password = ""
45 self._remote_sshkey = ""
46 self._ssh_keyauth = False
47 self._ssh_passauth = False
49 ''' set parameters '''
50 [self._ssh_username, self._ssh_hostname, self._ssh_hostport] = self._u.parse_remote_desc(remote_desc)
52 self._formatter = formatter
53 self._runner = CommandRunner(self._remote_desc)
56 self._cu = CollectUtils(self._linkpairs, self._port_to_br, self._iface_to_nss, self._dbu, self._formatter)
57 namespace_agent = NamespaceAgent(self._runner, self._cu, self._iface_to_nss)
59 ovs_agent = OVSAgent(self._runner, self._cu, self._linkpairs, self._port_to_br, self._iface_to_nss, self._formatter)
61 bridge_agent = LinuxBridgeAgent(self._runner, self._cu, self._linkpairs, self._port_to_br, self._iface_to_nss, self._formatter)
63 libvirt_agent = LibvirtAgent(self._runner, self._cu, self._linkpairs, self._port_to_br, self._iface_to_nss, self._remote_desc, self._formatter)
66 def get_linkpairs(self):
67 return self._linkpairs
69 def set_remote_sshkey(self, remote_sshkey):
70 self._runner.set_remote_sshkey(remote_sshkey)
72 def set_remote_password(self, remote_password):
73 self._runner.set_remote_password(remote_password)