OSDN Git Service

delete old collector agents
[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.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
22
23
24 class Collector(object):
25     '''LinkpPair collector
26
27     This class gets the LinkPair information from LinuxBridge and Open vSwitch and libvirt
28     '''
29
30     PEER_FOUND = 1
31
32     def __init__(self, remote_desc, dbu, formatter=GraphEasyFormatter()):
33         self._linkpairs = []
34         self._port_to_br = {}
35         self._iface_to_nss = {}
36         self._u = CommonUtils()
37         self._cu = None
38         self._db_enable = False
39         self._sql_conn = None
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
48
49         ''' set parameters '''
50         [self._ssh_username, self._ssh_hostname, self._ssh_hostport] = self._u.parse_remote_desc(remote_desc)
51         self._dbu = dbu
52         self._formatter = formatter
53         self._runner = CommandRunner(self._remote_desc)
54         
55     def run(self):
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)
58         namespace_agent.run()
59         ovs_agent = OVSAgent(self._runner, self._cu, self._linkpairs, self._port_to_br, self._iface_to_nss, self._formatter)
60         ovs_agent.run()
61         bridge_agent = LinuxBridgeAgent(self._runner, self._cu, self._linkpairs, self._port_to_br, self._iface_to_nss, self._formatter)
62         bridge_agent.run()
63         libvirt_agent = LibvirtAgent(self._runner, self._cu, self._linkpairs, self._port_to_br, self._iface_to_nss, self._remote_desc, self._formatter)
64         libvirt_agent.run()
65         
66     def get_linkpairs(self):
67         return self._linkpairs
68             
69     def set_remote_sshkey(self, remote_sshkey):
70         self._runner.set_remote_sshkey(remote_sshkey)
71
72     def set_remote_password(self, remote_password):
73         self._runner.set_remote_password(remote_password)