3 from datetime import date
13 def printEdge(tableName, baseType, label):
14 if baseType.ref_table:
16 options['label'] = '"%s"' % label
17 if baseType.ref_type == 'weak':
18 options['constraint'] = 'false'
19 print "\t%s -> %s [%s];" % (
22 ', '.join(['%s=%s' % (k,v) for k,v in options.items()]))
24 def schemaToDot(schemaFile):
25 schema = ovs.db.schema.DbSchema.from_json(ovs.json.from_file(schemaFile))
27 print "digraph %s {" % schema.name
28 for tableName, table in schema.tables.iteritems():
29 print '\tsize="6.5,4";'
31 print "\tnode [shape=box];"
32 print "\t%s;" % tableName
33 for columnName, column in table.columns.iteritems():
35 printEdge(tableName, column.type.key, "%s key" % columnName)
36 printEdge(tableName, column.type.value, "%s value" % columnName)
38 printEdge(tableName, column.type.key, columnName)
43 %(argv0)s: compiles ovsdb schemas to graphviz format
44 Prints a .dot file that "dot" can render to an entity-relationship diagram
45 usage: %(argv0)s [OPTIONS] SCHEMA
46 where SCHEMA is an OVSDB schema in JSON format
48 The following options are also available:
49 -h, --help display this help message
50 -V, --version display version information\
51 """ % {'argv0': argv0}
54 if __name__ == "__main__":
57 options, args = getopt.gnu_getopt(sys.argv[1:], 'hV',
59 except getopt.GetoptError, geo:
60 sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
63 for key, value in options:
64 if key in ['-h', '--help']:
66 elif key in ['-V', '--version']:
67 print "ovsdb-dot (Open vSwitch) @VERSION@"
72 sys.stderr.write("%s: exactly 1 non-option argument required "
73 "(use --help for help)\n" % argv0)
78 except ovs.db.error.Error, e:
79 sys.stderr.write("%s: %s\n" % (argv0, e.msg))