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 "\tedge [dir=none, arrowhead=none, arrowtail=none];"
33 print "\t%s;" % tableName
34 for columnName, column in table.columns.iteritems():
36 printEdge(tableName, column.type.key, "%s key" % columnName)
37 printEdge(tableName, column.type.value, "%s value" % columnName)
39 printEdge(tableName, column.type.key, columnName)
44 %(argv0)s: compiles ovsdb schemas to graphviz format
45 Prints a .dot file that "dot" can render to an entity-relationship diagram
46 usage: %(argv0)s [OPTIONS] SCHEMA
47 where SCHEMA is an OVSDB schema in JSON format
49 The following options are also available:
50 -h, --help display this help message
51 -V, --version display version information\
52 """ % {'argv0': argv0}
55 if __name__ == "__main__":
58 options, args = getopt.gnu_getopt(sys.argv[1:], 'hV',
60 except getopt.GetoptError, geo:
61 sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
64 for key, value in options:
65 if key in ['-h', '--help']:
67 elif key in ['-V', '--version']:
68 print "ovsdb-dot (Open vSwitch) @VERSION@"
73 sys.stderr.write("%s: exactly 1 non-option argument required "
74 "(use --help for help)\n" % argv0)
79 except ovs.db.error.Error, e:
80 sys.stderr.write("%s: %s\n" % (argv0, e.msg))