# vim: tabstop=4 shiftwidth=4 softtabstop=4
# -*- coding: utf-8 -*-
#
-# ti2.py : List TAP device info for running VMs
+# ti2.py : List informations of the TAP devices for running VMs
#
-# 2013/02/01 ver1.0
-# basecode "tapinfo.py" : List TAP device info for running VMs
#
+
__version__ = '1.1'
+import sys
from optparse import OptionParser, OptionGroup
from linkpair.collect.collector import Collector
from linkpair.formatter.grapheasy import GraphEasyFormatter
from linkpair.formatter.springy_raphael import SpringyRaphaelFormatter
from linkpair.formatter.graphviz_tb import GraphvizTBFormatter
from linkpair.utils.common import CommonUtils
+from linkpair.exporter.JSON import JsonExporter
+from linkpair.importer.JSON import JsonImporter
def print_linkpair_records(lps):
p.add_option('-f', '--format', dest='format',
choices=['g', 'graph-easy', 's', 'springy',
'r', 'springy-raphael', 't', 'graphviz-tb'],
- default="graph-easy",
+ default="graphviz-tb",
help="specify output format [FORMAT: g/graph-easy, s/springy, r/springy-raphael, t/graphviz-tb]",
metavar="FORMAT")
p.add_option('-d', '--debug', dest='debug', action="store_true", default=False,
help="enable debug output")
p.add_option('-e', '--export_file', dest='export_file',
help="export linkpairs to json file", metavar="FILE")
+ p.add_option('-x', '--export_stdout', dest='export_stdout', action="store_true", default=False,
+ help="export linkpairs to stdout")
p.add_option('-i', '--import_file', dest='import_file',
help="import json file as linkpairs", metavar="FILE")
g2 = OptionGroup(p, "Collector Agent flags",
'--disable_linux_agent', dest='disable_linux_agent', action="store_true", default=False,
help="disable linux OS collector agent")
g2.add_option(
+ '--disable_linuxnet_agent', dest='disable_linuxnet_agent', action="store_true", default=False,
+ help="disable linux Network collector agent")
+ g2.add_option(
'--disable_linuxbridge_agent', dest='disable_linuxbridge_agent', action="store_true", default=False,
help="disable linux bridge collector agent")
g2.add_option(
util = CommonUtils()
util.set_opts(opts)
util.debug_out("init program options")
- #dbu = DBUtils()
- #if opts.database is not None and opts.database != "":
- # dbu.db_enable = True
- # sql_conn = dbu.open_db(opts.database)
- # dbu.create_tables()
if opts.format == "g" or opts.format == "graph-easy":
formatter = GraphEasyFormatter(util)
elif opts.format == "t" or opts.format == "graphviz-tb":
formatter = GraphvizTBFormatter(util)
else:
- formatter = GraphEasyFormatter()
+ formatter = GraphvizTBFormatter()
util.debug_out("formatter: " + str(formatter))
- col = Collector(opts, util, formatter)
- if opts.remote_sshkey is not None:
- col.set_remote_sshkey(opts.remote_sshkey)
- if opts.remote_password is not None:
- col.set_remote_password(opts.remote_password)
+ if opts.import_file is not None:
+ importer = JsonImporter(util, opts.import_file, formatter)
+ importer.run()
+ linkpairs = importer.get_linkpairs()
+ else:
+ col = Collector(opts, util, formatter)
+ if opts.remote_sshkey is not None:
+ col.set_remote_sshkey(opts.remote_sshkey)
+ col.connect_ssh()
+ if opts.remote_password is not None:
+ col.set_remote_password(opts.remote_password)
+ col.connect_ssh()
+ col.run()
+ linkpairs = col.get_linkpairs()
- col.run()
- linkpairs = col.get_linkpairs()
- #if dbu.db_enable:
- # dbu.store_to_db(opts.database, linkpairs)
+ if opts.export_stdout:
+ exporter = JsonExporter(util, linkpairs)
+ print(exporter.run())
+ sys.exit(0)
print_linkpair_records(linkpairs)