OSDN Git Service

add LinuxAgent
[ti2/ti2.git] / linkpair / collect / collector.py
1 #!/usr/bin/env python
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.ovs_agent import OVSAgent
22 from linkpair.collect.agent.linuxbridge_agent import LinuxBridgeAgent
23 from linkpair.collect.agent.libvirt_agent import LibvirtAgent
24
25
26 class Collector(object):
27     '''LinkpPair collector
28
29     This class gets the LinkPair information from LinuxBridge and Open vSwitch and libvirt
30     '''
31
32     PEER_FOUND = 1
33
34     def __init__(self, remote_desc, dbu, formatter=GraphEasyFormatter()):
35         self._os_info = {}
36         self._linkpairs = []
37         self._port_to_br = {}
38         self._iface_to_nss = {}
39         self._u = CommonUtils()
40         self._cu = None
41         self._db_enable = False
42         self._sql_conn = None
43         self._remote_desc = remote_desc
44         self._ssh_username = ""
45         self._ssh_hostname = ""
46         self._ssh_hostport = 22
47         self._remote_password = ""
48         self._remote_sshkey = ""
49         self._ssh_keyauth = False
50         self._ssh_passauth = False
51
52         ''' set parameters '''
53         [self._ssh_username, self._ssh_hostname, self._ssh_hostport] = self._u.parse_remote_desc(remote_desc)
54         self._dbu = dbu
55         self._formatter = formatter
56         self._runner = CommandRunner(self._remote_desc)
57         
58     def run(self):
59         self._cu = CollectUtils(self._linkpairs, self._port_to_br, self._iface_to_nss, self._dbu, self._formatter)
60         cd = CollectorDataset(self._os_info, self._linkpairs, self._port_to_br, self._iface_to_nss)
61         os_agent = LinuxAgent(self._runner, self._cu, self._remote_desc, cd, self._formatter)
62         os_agent.run()
63         namespace_agent = NamespaceAgent(self._runner, self._cu, self._remote_desc, cd, self._formatter)
64         namespace_agent.run()
65         ovs_agent = OVSAgent(self._runner, self._cu, self._remote_desc, cd, self._formatter)
66         ovs_agent.run()
67         bridge_agent = LinuxBridgeAgent(self._runner, self._cu, self._remote_desc, cd, self._formatter)
68         bridge_agent.run()
69         libvirt_agent = LibvirtAgent(self._runner, self._cu, self._remote_desc, cd, self._formatter)
70         libvirt_agent.run()
71         
72     def get_linkpairs(self):
73         return self._linkpairs
74             
75     def set_remote_sshkey(self, remote_sshkey):
76         self._runner.set_remote_sshkey(remote_sshkey)
77
78     def set_remote_password(self, remote_password):
79         self._runner.set_remote_password(remote_password)