+
+def idltest_find_simple(idl, i):
+ for row in idl.tables["simple"].rows.itervalues():
+ if row.i == i:
+ return row
+ return None
+
+
+def idl_set(idl, commands, step):
+ txn = ovs.db.idl.Transaction(idl)
+ increment = False
+ for command in commands.split(','):
+ words = command.split()
+ name = words[0]
+ args = words[1:]
+
+ if name == "set":
+ if len(args) != 3:
+ sys.stderr.write('"set" command requires 3 arguments\n')
+ sys.exit(1)
+
+ s = idltest_find_simple(idl, int(args[0]))
+ if not s:
+ sys.stderr.write('"set" command asks for nonexistent i=%d\n'
+ % int(args[0]))
+ sys.exit(1)
+
+ if args[1] == "b":
+ s.b = args[2] == "1"
+ elif args[1] == "s":
+ s.s = args[2]
+ elif args[1] == "u":
+ s.u = uuid.UUID(args[2])
+ elif args[1] == "r":
+ s.r = float(args[2])
+ else:
+ sys.stderr.write('"set" comamnd asks for unknown column %s\n'
+ % args[2])
+ sys.stderr.exit(1)
+ elif name == "insert":
+ if len(args) != 1:
+ sys.stderr.write('"set" command requires 1 argument\n')
+ sys.exit(1)
+
+ s = txn.insert(idl.tables["simple"])
+ s.i = int(args[0])
+ elif name == "delete":
+ if len(args) != 1:
+ sys.stderr.write('"delete" command requires 1 argument\n')
+ sys.exit(1)
+
+ s = idltest_find_simple(idl, int(args[0]))
+ if not s:
+ sys.stderr.write('"delete" command asks for nonexistent i=%d\n'
+ % int(args[0]))
+ sys.exit(1)
+ s.delete()
+ elif name == "verify":
+ if len(args) != 2:
+ sys.stderr.write('"verify" command requires 2 arguments\n')
+ sys.exit(1)
+
+ s = idltest_find_simple(idl, int(args[0]))
+ if not s:
+ sys.stderr.write('"verify" command asks for nonexistent i=%d\n'
+ % int(args[0]))
+ sys.exit(1)
+
+ if args[1] in ("i", "b", "s", "u", "r"):
+ s.verify(args[1])
+ else:
+ sys.stderr.write('"verify" command asks for unknown column '
+ '"%s"\n' % args[1])
+ sys.exit(1)
+ elif name == "increment":
+ if len(args) != 1:
+ sys.stderr.write('"increment" command requires 1 argument\n')
+ sys.exit(1)
+
+ s = idltest_find_simple(idl, int(args[0]))
+ if not s:
+ sys.stderr.write('"set" command asks for nonexistent i=%d\n'
+ % int(args[0]))
+ sys.exit(1)
+
+ s.increment("i")
+ increment = True
+ elif name == "abort":
+ txn.abort()
+ break
+ elif name == "destroy":
+ print "%03d: destroy" % step
+ sys.stdout.flush()
+ txn.abort()
+ return
+ elif name == "linktest":
+ l1_0 = txn.insert(idl.tables["link1"])
+ l1_0.i = 1
+ l1_0.k = [l1_0]
+ l1_0.ka = [l1_0]
+ l1_1 = txn.insert(idl.tables["link1"])
+ l1_1.i = 2
+ l1_1.k = [l1_0]
+ l1_1.ka = [l1_0, l1_1]
+ elif name == 'getattrtest':
+ l1 = txn.insert(idl.tables["link1"])
+ i = getattr(l1, 'i', 1)
+ assert i == 1
+ l1.i = 2
+ i = getattr(l1, 'i', 1)
+ assert i == 2
+ l1.k = [l1]
+ else:
+ sys.stderr.write("unknown command %s\n" % name)
+ sys.exit(1)
+
+ status = txn.commit_block()
+ sys.stdout.write("%03d: commit, status=%s"
+ % (step, ovs.db.idl.Transaction.status_to_string(status)))
+ if increment and status == ovs.db.idl.Transaction.SUCCESS:
+ sys.stdout.write(", increment=%d" % txn.get_increment_new_value())
+ sys.stdout.write("\n")
+ sys.stdout.flush()
+
+
+def do_idl(schema_file, remote, *commands):
+ schema_helper = ovs.db.idl.SchemaHelper(schema_file)
+ schema_helper.register_all()
+ idl = ovs.db.idl.Idl(remote, schema_helper)