OSDN Git Service

add LinuxVlanAgent
[ti2/ti2.git] / linkpair / collect / collector.py
1 # vim: tabstop=4 shiftwidth=4 softtabstop=4
2 # -*- coding: utf-8 -*-
3 #
4
5 __version__ = '1.1'
6
7 import sys
8 import os
9 import re
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
26
27
28 class Collector(object):
29     '''LinkpPair collector
30
31     This class gets the LinkPair information from LinuxBridge and Open vSwitch and libvirt
32     '''
33
34     PEER_FOUND = 1
35
36     def __init__(self, remote_desc, dbu, formatter=GraphEasyFormatter()):
37         self._devices = {}
38         self._ports = {}
39         self._os_info = {}
40         self._linkpairs = []
41         self._port_to_br = {}
42         self._iface_to_nss = {}
43         self._veth_peer = {}
44         self._u = CommonUtils()
45         self._db_enable = False
46         self._sql_conn = None
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
55
56         ''' set parameters '''
57         [self._ssh_username, self._ssh_hostname,
58             self._ssh_hostport] = self._u.parse_remote_desc(remote_desc)
59         self._dbu = dbu
60         self._formatter = formatter
61         self._runner = CommandRunner(self._remote_desc)
62
63     def run(self):
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)
67         cu = CollectUtils(
68             cd, self._dbu, self._formatter)
69         os_agent = LinuxAgent(
70             self._runner, cu, self._remote_desc, cd, self._formatter)
71         os_agent.run()
72         namespace_agent = NamespaceAgent(
73             self._runner, cu, self._remote_desc, cd, self._formatter)
74         namespace_agent.run()
75         veth_agent = VethAgent(
76             self._runner, cu, self._remote_desc, cd, self._formatter)
77         veth_agent.run()
78         vlan_agent = LinuxVlanAgent(
79             self._runner, cu, self._remote_desc, cd, self._formatter)
80         vlan_agent.run()
81         ovs_agent = OVSAgent(
82             self._runner, cu, self._remote_desc, cd, self._formatter)
83         ovs_agent.run()
84         bridge_agent = LinuxBridgeAgent(
85             self._runner, cu, self._remote_desc, cd, self._formatter)
86         bridge_agent.run()
87         libvirt_agent = LibvirtAgent(
88             self._runner, cu, self._remote_desc, cd, self._formatter)
89         libvirt_agent.run()
90
91     def get_linkpairs(self):
92         return self._linkpairs
93
94     def set_remote_sshkey(self, remote_sshkey):
95         self._runner.set_remote_sshkey(remote_sshkey)
96
97     def set_remote_password(self, remote_password):
98         self._runner.set_remote_password(remote_password)