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 options['style'] = 'dotted'
20 print "\t%s -> %s [%s];" % (
23 ', '.join(['%s=%s' % (k,v) for k,v in options.items()]))
25 def schemaToDot(schemaFile):
26 schema = ovs.db.schema.DbSchema.from_json(ovs.json.from_file(schemaFile))
28 print "digraph %s {" % schema.name
29 print '\tsize="6.5,4";'
31 print "\tnode [shape=box];"
32 print "\tedge [dir=none, arrowhead=none, arrowtail=none];"
33 for tableName, table in schema.tables.iteritems():
36 options['style'] = 'bold'
37 print "\t%s [%s];" % (
39 ', '.join(['%s=%s' % (k,v) for k,v in options.items()]))
40 for columnName, column in table.columns.iteritems():
42 printEdge(tableName, column.type.key, "%s key" % columnName)
43 printEdge(tableName, column.type.value, "%s value" % columnName)
45 printEdge(tableName, column.type.key, columnName)
50 %(argv0)s: compiles ovsdb schemas to graphviz format
51 Prints a .dot file that "dot" can render to an entity-relationship diagram
52 usage: %(argv0)s [OPTIONS] SCHEMA
53 where SCHEMA is an OVSDB schema in JSON format
55 The following options are also available:
56 -h, --help display this help message
57 -V, --version display version information\
58 """ % {'argv0': argv0}
61 if __name__ == "__main__":
64 options, args = getopt.gnu_getopt(sys.argv[1:], 'hV',
66 except getopt.GetoptError, geo:
67 sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
70 for key, value in options:
71 if key in ['-h', '--help']:
73 elif key in ['-V', '--version']:
74 print "ovsdb-dot (Open vSwitch) @VERSION@"
79 sys.stderr.write("%s: exactly 1 non-option argument required "
80 "(use --help for help)\n" % argv0)
85 except ovs.db.error.Error, e:
86 sys.stderr.write("%s: %s\n" % (argv0, e.msg))