Add commands to set and get LRP options
This patch is adding two new commands: * lrp_set_options(): To set the "options" column for a LRP * lrp_get_options(): To get the values of the "options" column of a LRP Since the code is pretty much the same as the equivalent command for LSP this patch attempts to reuse the same command for both. Change-Id: I0a8e54b0e61553e5962ccc8030a2e8e9a9d49390 Signed-off-by: Lucas Alvares Gomes <lucasagomes@gmail.com>
This commit is contained in:
parent
81c124fe29
commit
78de8a6187
@ -542,6 +542,26 @@ class API(api.API):
|
||||
:returns:
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def lrp_set_options(self, port, **options):
|
||||
"""Set options related to the type of 'port'
|
||||
|
||||
:param port: The name or uuid of the port
|
||||
:type port: string or uuid.UUID
|
||||
:param options: keys and values for the port 'options' dict
|
||||
:type options: key: string, value: string
|
||||
:returns: :class:`Command` with no result
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def lrp_get_options(self, port):
|
||||
"""Get the type-specific options for 'port'
|
||||
|
||||
:param port: The name or uuid of the port
|
||||
:type port: string or uuid.UUID
|
||||
:returns: :class:`Command` with dict result
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def lr_route_add(self, router, prefix, nexthop, port=None,
|
||||
policy='dst-ip', may_exist=False):
|
||||
|
@ -542,23 +542,27 @@ class LspGetTypeCommand(cmd.ReadOnlyCommand):
|
||||
|
||||
|
||||
class LspSetOptionsCommand(cmd.BaseCommand):
|
||||
table = 'Logical_Switch_Port'
|
||||
|
||||
def __init__(self, api, port, **options):
|
||||
super(LspSetOptionsCommand, self).__init__(api)
|
||||
self.port = port
|
||||
self.options = options
|
||||
|
||||
def run_idl(self, txn):
|
||||
lsp = self.api.lookup('Logical_Switch_Port', self.port)
|
||||
lsp = self.api.lookup(self.table, self.port)
|
||||
lsp.options = self.options
|
||||
|
||||
|
||||
class LspGetOptionsCommand(cmd.ReadOnlyCommand):
|
||||
table = 'Logical_Switch_Port'
|
||||
|
||||
def __init__(self, api, port):
|
||||
super(LspGetOptionsCommand, self).__init__(api)
|
||||
self.port = port
|
||||
|
||||
def run_idl(self, txn):
|
||||
lsp = self.api.lookup('Logical_Switch_Port', self.port)
|
||||
lsp = self.api.lookup(self.table, self.port)
|
||||
self.result = lsp.options
|
||||
|
||||
|
||||
@ -795,6 +799,14 @@ class LrpGetEnabledCommand(cmd.ReadOnlyCommand):
|
||||
self.result = next(iter(lrp.enabled), True)
|
||||
|
||||
|
||||
class LrpSetOptionsCommand(LspSetOptionsCommand):
|
||||
table = 'Logical_Router_Port'
|
||||
|
||||
|
||||
class LrpGetOptionsCommand(LspGetOptionsCommand):
|
||||
table = 'Logical_Router_Port'
|
||||
|
||||
|
||||
class LrRouteAddCommand(cmd.BaseCommand):
|
||||
def __init__(self, api, router, prefix, nexthop, port=None,
|
||||
policy='dst-ip', may_exist=False):
|
||||
|
@ -178,6 +178,12 @@ class OvnNbApiIdlImpl(ovs_idl.Backend, api.API):
|
||||
def lrp_get_enabled(self, port):
|
||||
return cmd.LrpGetEnabledCommand(self, port)
|
||||
|
||||
def lrp_set_options(self, port, **options):
|
||||
return cmd.LrpSetOptionsCommand(self, port, **options)
|
||||
|
||||
def lrp_get_options(self, port):
|
||||
return cmd.LrpGetOptionsCommand(self, port)
|
||||
|
||||
def lr_route_add(self, router, prefix, nexthop, port=None,
|
||||
policy='dst-ip', may_exist=False):
|
||||
return cmd.LrRouteAddCommand(self, router, prefix, nexthop, port,
|
||||
|
@ -1032,6 +1032,14 @@ class TestLogicalRouterPortOps(OvnNorthboundTest):
|
||||
self.assertTrue(self.api.lrp_get_enabled(lrp.name).execute(
|
||||
check_error=True))
|
||||
|
||||
def test_lrp_get_set_options(self):
|
||||
options = {'one': 'two', 'three': 'four'}
|
||||
lrp = self._lrp_add(None)
|
||||
self.api.lrp_set_options(lrp.uuid, **options).execute(
|
||||
check_error=True)
|
||||
self.assertEqual(options, self.api.lrp_get_options(lrp.uuid).execute(
|
||||
check_error=True))
|
||||
|
||||
|
||||
class TestLoadBalancerOps(OvnNorthboundTest):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user