2 # vim: tabstop=4 shiftwidth=4 softtabstop=4
3 # -*- coding: utf-8 -*-
5 # ti2.py : List TAP device info for running VMs
8 # basecode "tapinfo.py" : List TAP device info for running VMs
15 from optparse import OptionParser, OptionGroup
16 from linkpair.collect.collector import Collector
17 from linkpair.linkpair import LinkPair
18 from linkpair.formatter.grapheasy import GraphEasyFormatter
19 from linkpair.formatter.springy import SpringyFormatter
20 from linkpair.formatter.springy_raphael import SpringyRaphaelFormatter
21 from linkpair.formatter.graphviz_tb import GraphvizTBFormatter
22 from linkpair.dbutils import DBUtils
25 def print_linkpair_records(lps):
26 format.set_linkpairs(lps)
27 for lp in format.format_linkpairs():
30 if __name__ == "__main__":
31 # init program options
32 p = OptionParser(version="ver:%s" % __version__)
33 g1 = OptionGroup(p, "Remote connection",
34 "connect to a remote system via SSH")
35 g1.add_option('-r', '--remote', dest='remote_desc',
36 help="specify user's name and hostname, port number (ex. -r user@hostname:22)", metavar="REMOTE_DESC")
37 g1.add_option('-p', '--password', dest='remote_password',
38 help="specify user's SSH password", metavar="PASSWORD")
39 g1.add_option('-k', '--sshkey', dest='remote_sshkey',
40 help="specify user's SSH private-key file", metavar="FILE")
41 p.add_option_group(g1)
42 p.add_option('-f', '--format', dest='format',
43 choices=['g', 'graph-easy', 's', 'springy',
44 'r', 'springy-raphael', 't', 'graphviz-tb'],
46 help="specify output format [FORMAT: g/graph-easy, s/springy, r/springy-raphael, t/graphviz-tb]",
48 p.add_option('-d', '--database', dest='database', default="",
49 help="store record to database", metavar="FILE")
50 p.add_option('-t', '--datatype', dest='datatype', default="json",
51 help="specify database type(default: json)", metavar="TYPE")
52 g2 = OptionGroup(p, "Collector Agent flags",
53 "disable Collector Agents")
55 '--disable_ovs_agent', dest='disable_ovs_agent', action="store_true", default=False,
56 help="disable Open vSwitch collector agent")
58 '--disable_linux_agent', dest='disable_linux_agent', action="store_true", default=False,
59 help="disable linux OS collector agent")
61 '--disable_linuxbridge_agent', dest='disable_linuxbridge_agent', action="store_true", default=False,
62 help="disable linux bridge collector agent")
64 '--disable_linuxvlan_agent', dest='disable_linuxvlan_agent', action="store_true", default=False,
65 help="disable linux vlan collector agent")
67 '--disable_libvirt_agent', dest='disable_libvirt_agent', action="store_true", default=False,
68 help="disable libvirt collector agent")
70 '--disable_namespace_agent', dest='disable_namespace_agent', action="store_true", default=False,
71 help="disable network namespace collector agent")
73 '--disable_sspvxlan_agent', dest='disable_sspvxlan_agent', action="store_true", default=False,
74 help="disable SSP VXLAN collector agent")
76 '--disable_veth_agent', dest='disable_veth_agent', action="store_true", default=False,
77 help="disable veth collector agent")
78 p.add_option_group(g2)
80 '-v', '--verbose', dest='verbose', action="store_true", default=False,
81 help="verbose output.")
82 (opts, args) = p.parse_args()
84 if opts.database is not None and opts.database != "":
86 # sql_conn = dbu.open_db(opts.database)
89 if opts.format == "g" or opts.format == "graph-easy":
90 format = GraphEasyFormatter()
91 elif opts.format == "s" or opts.format == "springy":
92 format = SpringyFormatter()
93 elif opts.format == "r" or opts.format == "springy-raphael":
94 format = SpringyRaphaelFormatter()
95 elif opts.format == "t" or opts.format == "graphviz-tb":
96 format = GraphvizTBFormatter()
98 format = GraphEasyFormatter()
100 col = Collector(opts, dbu, format)
101 if opts.remote_sshkey is not None:
102 col.set_remote_sshkey(opts.remote_sshkey)
103 if opts.remote_password is not None:
104 col.set_remote_password(opts.remote_password)
107 linkpairs = col.get_linkpairs()
109 dbu.store_to_db(opts.database, linkpairs)
111 print_linkpair_records(linkpairs)