diff --git a/ovsdbapp/schema/ovn_northbound/api.py b/ovsdbapp/schema/ovn_northbound/api.py index 6e81dfea..0b1f6bee 100644 --- a/ovsdbapp/schema/ovn_northbound/api.py +++ b/ovsdbapp/schema/ovn_northbound/api.py @@ -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): diff --git a/ovsdbapp/schema/ovn_northbound/commands.py b/ovsdbapp/schema/ovn_northbound/commands.py index 05a2a1c6..1e9fb74c 100644 --- a/ovsdbapp/schema/ovn_northbound/commands.py +++ b/ovsdbapp/schema/ovn_northbound/commands.py @@ -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): diff --git a/ovsdbapp/schema/ovn_northbound/impl_idl.py b/ovsdbapp/schema/ovn_northbound/impl_idl.py index 248a8ab5..43e96502 100644 --- a/ovsdbapp/schema/ovn_northbound/impl_idl.py +++ b/ovsdbapp/schema/ovn_northbound/impl_idl.py @@ -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, diff --git a/ovsdbapp/tests/functional/schema/ovn_northbound/test_impl_idl.py b/ovsdbapp/tests/functional/schema/ovn_northbound/test_impl_idl.py index d1aa56e3..b6cc5c79 100644 --- a/ovsdbapp/tests/functional/schema/ovn_northbound/test_impl_idl.py +++ b/ovsdbapp/tests/functional/schema/ovn_northbound/test_impl_idl.py @@ -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):