OSDN Git Service

17ce6700965d372f3258b42453ac2e6f50a0b7ba
[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.commonutils 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.libvirt_agent import LibvirtAgent
25
26
27 class Collector(object):
28     '''LinkpPair collector
29
30     This class gets the LinkPair information from LinuxBridge and Open vSwitch and libvirt
31     '''
32
33     PEER_FOUND = 1
34
35     def __init__(self, remote_desc, dbu, formatter=GraphEasyFormatter()):
36         self._os_info = {}
37         self._linkpairs = []
38         self._port_to_br = {}
39         self._iface_to_nss = {}
40         self._veth_peer = {}
41         self._u = CommonUtils()
42         self._db_enable = False
43         self._sql_conn = None
44         self._remote_desc = remote_desc
45         self._ssh_username = ""
46         self._ssh_hostname = ""
47         self._ssh_hostport = 22
48         self._remote_password = ""
49         self._remote_sshkey = ""
50         self._ssh_keyauth = False
51         self._ssh_passauth = False
52
53         ''' set parameters '''
54         [self._ssh_username, self._ssh_hostname,
55             self._ssh_hostport] = self._u.parse_remote_desc(remote_desc)
56         self._dbu = dbu
57         self._formatter = formatter
58         self._runner = CommandRunner(self._remote_desc)
59
60     def run(self):
61         cd = CollectorDataset(
62             self._os_info, self._linkpairs, self._port_to_br, self._iface_to_nss, self._veth_peer)
63         cu = CollectUtils(
64             cd, self._dbu, self._formatter)
65         os_agent = LinuxAgent(
66             self._runner, cu, self._remote_desc, cd, self._formatter)
67         os_agent.run()
68         namespace_agent = NamespaceAgent(
69             self._runner, cu, self._remote_desc, cd, self._formatter)
70         namespace_agent.run()
71         veth_agent = VethAgent(
72             self._runner, cu, self._remote_desc, cd, self._formatter)
73         veth_agent.run()
74         ovs_agent = OVSAgent(
75             self._runner, cu, self._remote_desc, cd, self._formatter)
76         ovs_agent.run()
77         bridge_agent = LinuxBridgeAgent(
78             self._runner, cu, self._remote_desc, cd, self._formatter)
79         bridge_agent.run()
80         libvirt_agent = LibvirtAgent(
81             self._runner, cu, self._remote_desc, cd, self._formatter)
82         libvirt_agent.run()
83
84     def get_linkpairs(self):
85         return self._linkpairs
86
87     def set_remote_sshkey(self, remote_sshkey):
88         self._runner.set_remote_sshkey(remote_sshkey)
89
90     def set_remote_password(self, remote_password):
91         self._runner.set_remote_password(remote_password)