Add set_column(s) for ovs_idl backend
The create/set Commands allow one to pass the result of txn.add() to a subsequent Command in a transaction to use the result of that Command's execution. In this way one can create a DHCP Option and then pass it to an lsp_add() command. This change replaces the direct uses of setattr() with a version that does the substituation if one of the arguments is a Command instead of a normal value, enabling this behavior for all Commands. Change-Id: I97e7cbff7e71f7e1f00342c724af963a411b6c5d
This commit is contained in:
parent
e40e271a0d
commit
558783eba2
@ -40,6 +40,15 @@ class BaseCommand(api.Command):
|
||||
if check_error:
|
||||
raise
|
||||
|
||||
@classmethod
|
||||
def set_column(cls, row, col, val):
|
||||
setattr(row, col, idlutils.db_replace_record(val))
|
||||
|
||||
@classmethod
|
||||
def set_columns(cls, row, **columns):
|
||||
for col, val in columns.items():
|
||||
cls.set_column(row, col, val)
|
||||
|
||||
def post_commit(self, txn):
|
||||
pass
|
||||
|
||||
@ -70,8 +79,7 @@ class DbCreateCommand(BaseCommand):
|
||||
|
||||
def run_idl(self, txn):
|
||||
row = txn.insert(self.api._tables[self.table])
|
||||
for col, val in self.columns.items():
|
||||
setattr(row, col, idlutils.db_replace_record(val))
|
||||
self.set_columns(row, **self.columns)
|
||||
# This is a temporary row to be used within the transaction
|
||||
self.result = row
|
||||
|
||||
@ -112,7 +120,7 @@ class DbSetCommand(BaseCommand):
|
||||
existing = getattr(record, col, {})
|
||||
existing.update(val)
|
||||
val = existing
|
||||
setattr(record, col, idlutils.db_replace_record(val))
|
||||
self.set_column(record, col, val)
|
||||
|
||||
|
||||
class DbAddCommand(BaseCommand):
|
||||
@ -146,7 +154,7 @@ class DbAddCommand(BaseCommand):
|
||||
field = getattr(record, self.column, [])
|
||||
field.append(value)
|
||||
record.verify(self.column)
|
||||
setattr(record, self.column, idlutils.db_replace_record(field))
|
||||
self.set_column(record, self.column, field)
|
||||
|
||||
|
||||
class DbClearCommand(BaseCommand):
|
||||
|
@ -49,8 +49,7 @@ class LsAddCommand(cmd.AddCommand):
|
||||
else:
|
||||
# because ovs.db.idl brokenly requires a changed column
|
||||
sw.name = ""
|
||||
for col, value in self.columns.items():
|
||||
setattr(sw, col, value)
|
||||
self.set_columns(sw, **self.columns)
|
||||
self.result = sw.uuid
|
||||
|
||||
|
||||
@ -172,7 +171,7 @@ class LspAddCommand(cmd.AddCommand):
|
||||
if tag and not 0 <= tag <= 4095:
|
||||
raise TypeError("tag must be 0 to 4095, inclusive")
|
||||
if (parent_name is None) != (tag is None):
|
||||
raise TypeError("parent and tag must be passed together")
|
||||
raise TypeError("parent_name and tag must be passed together")
|
||||
super(LspAddCommand, self).__init__(api)
|
||||
self.switch = switch
|
||||
self.port = port
|
||||
@ -215,8 +214,7 @@ class LspAddCommand(cmd.AddCommand):
|
||||
lsp.parent_name = self.parent
|
||||
lsp.tag_request = self.tag
|
||||
ls.addvalue('ports', lsp)
|
||||
for col, value in self.columns.items():
|
||||
setattr(lsp, col, value)
|
||||
self.set_columns(lsp, **self.columns)
|
||||
self.result = lsp.uuid
|
||||
|
||||
|
||||
@ -519,8 +517,7 @@ class LrAddCommand(cmd.BaseCommand):
|
||||
pass
|
||||
lr = txn.insert(self.api.tables['Logical_Router'])
|
||||
lr.name = self.router if self.router else ""
|
||||
for col, value in self.columns.items():
|
||||
setattr(lr, col, value)
|
||||
self.set_columns(lr, **self.columns)
|
||||
self.result = lr.uuid
|
||||
|
||||
def post_commit(self, txn):
|
||||
@ -596,8 +593,7 @@ class LrpAddCommand(cmd.BaseCommand):
|
||||
if self.peer:
|
||||
lrp.peer = self.peer
|
||||
lr.addvalue('ports', lrp)
|
||||
for col, value in self.columns.items():
|
||||
setattr(lrp, col, value)
|
||||
self.set_columns(lrp, **self.columns)
|
||||
self.result = lrp.uuid
|
||||
|
||||
def post_commit(self, txn):
|
||||
@ -861,9 +857,7 @@ class LbAddCommand(cmd.BaseCommand):
|
||||
lb.name = self.lb
|
||||
lb.protocol = self.protocol
|
||||
lb.vips = {self.vip: self.ips}
|
||||
for col, val in self.columns.items():
|
||||
setattr(lb, col, val)
|
||||
|
||||
self.set_columns(lb, **self.columns)
|
||||
self.result = lb.uuid
|
||||
|
||||
def post_commit(self, txn):
|
||||
|
Loading…
Reference in New Issue
Block a user