3 from datetime import date
11 def printEdge(tableName, baseType, label):
14 options['label'] = '"%s"' % label
15 if baseType.refType == 'weak':
16 options['constraint'] = 'false'
17 print "\t%s -> %s [%s];" % (
20 ', '.join(['%s=%s' % (k,v) for k,v in options.items()]))
22 def schemaToDot(schemaFile):
23 schema = DbSchema.fromJson(ovs.json.from_file(schemaFile))
25 print "digraph %s {" % schema.name
26 for tableName, table in schema.tables.iteritems():
27 print '\tsize="6.5,4";'
29 print "\tnode [shape=box];"
30 print "\t%s;" % tableName
31 for columnName, column in table.columns.iteritems():
33 printEdge(tableName, column.type.key, "%s key" % columnName)
34 printEdge(tableName, column.type.value, "%s value" % columnName)
36 printEdge(tableName, column.type.key, columnName)
41 %(argv0)s: compiles ovsdb schemas to graphviz format
42 Prints a .dot file that "dot" can render to an entity-relationship diagram
43 usage: %(argv0)s [OPTIONS] SCHEMA
44 where SCHEMA is an OVSDB schema in JSON format
46 The following options are also available:
47 -h, --help display this help message
48 -V, --version display version information\
49 """ % {'argv0': argv0}
52 if __name__ == "__main__":
55 options, args = getopt.gnu_getopt(sys.argv[1:], 'hV',
57 except getopt.GetoptError, geo:
58 sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
61 for key, value in options:
62 if key in ['-h', '--help']:
64 elif key in ['-V', '--version']:
65 print "ovsdb-dot (Open vSwitch) @VERSION@"
70 sys.stderr.write("%s: exactly 1 non-option argument required "
71 "(use --help for help)\n" % argv0)
77 sys.stderr.write("%s: %s\n" % (argv0, e.msg))