Skip to content

Commit

Permalink
Provide base classes for {Get,Set}Options commands
Browse files Browse the repository at this point in the history
Move common code for all {Get,Set}Options commands to base classes.

Trivial-Fix

Change-Id: I0273d321f41ad525afa4b00a99dc2d64577c9ee5
  • Loading branch information
0x5b committed Jul 12, 2022
1 parent 81bd6fe commit e9c6c6c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 39 deletions.
25 changes: 25 additions & 0 deletions ovsdbapp/backend/ovs_idl/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,31 @@ def run_idl(self, txn):
self.result = self.api.lookup(self.table, self.record)


class BaseSetOptionsCommand(BaseCommand):
table = []

def __init__(self, api, entity, **options):
super().__init__(api)
self.entity = entity
self.options = options

def run_idl(self, txn):
entity = self.api.lookup(self.table, self.entity)
entity.options = self.options


class BaseGetOptionsCommand(ReadOnlyCommand):
table = []

def __init__(self, api, entity, **options):
super().__init__(api)
self.entity = entity

def run_idl(self, txn):
entity = self.api.lookup(self.table, self.entity)
self.result = entity.options


class DbRemoveCommand(BaseCommand):
def __init__(self, api, table, record, column, *values, **keyvalues):
super().__init__(api)
Expand Down
54 changes: 15 additions & 39 deletions ovsdbapp/schema/ovn_northbound/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,30 +695,13 @@ def run_idl(self, txn):
self.result = lsp.type


class LspSetOptionsCommand(cmd.BaseCommand):
class LspSetOptionsCommand(cmd.BaseSetOptionsCommand):
table = 'Logical_Switch_Port'

def __init__(self, api, port, **options):
super().__init__(api)
self.port = port
self.options = options

def run_idl(self, txn):
lsp = self.api.lookup(self.table, self.port)
lsp.options = self.options


class LspGetOptionsCommand(cmd.ReadOnlyCommand):
class LspGetOptionsCommand(cmd.BaseGetOptionsCommand):
table = 'Logical_Switch_Port'

def __init__(self, api, port):
super().__init__(api)
self.port = port

def run_idl(self, txn):
lsp = self.api.lookup(self.table, self.port)
self.result = lsp.options


class LspSetDhcpV4OptionsCommand(cmd.BaseCommand):
def __init__(self, api, port, dhcpopt_uuid):
Expand Down Expand Up @@ -778,25 +761,12 @@ class DhcpOptionsGetCommand(cmd.BaseGetRowCommand):
table = 'DHCP_Options'


class DhcpOptionsSetOptionsCommand(cmd.BaseCommand):
def __init__(self, api, dhcpopt_uuid, **options):
super().__init__(api)
self.dhcpopt_uuid = dhcpopt_uuid
self.options = options

def run_idl(self, txn):
dhcpopt = self.api.lookup('DHCP_Options', self.dhcpopt_uuid)
dhcpopt.options = self.options

class DhcpOptionsSetOptionsCommand(cmd.BaseSetOptionsCommand):
table = 'DHCP_Options'

class DhcpOptionsGetOptionsCommand(cmd.ReadOnlyCommand):
def __init__(self, api, dhcpopt_uuid):
super().__init__(api)
self.dhcpopt_uuid = dhcpopt_uuid

def run_idl(self, txn):
dhcpopt = self.api.lookup('DHCP_Options', self.dhcpopt_uuid)
self.result = dhcpopt.options
class DhcpOptionsGetOptionsCommand(cmd.BaseGetOptionsCommand):
table = 'DHCP_Options'


class LrAddCommand(cmd.BaseCommand):
Expand Down Expand Up @@ -957,11 +927,11 @@ def run_idl(self, txn):
self.result = next(iter(lrp.enabled), True)


class LrpSetOptionsCommand(LspSetOptionsCommand):
class LrpSetOptionsCommand(cmd.BaseSetOptionsCommand):
table = 'Logical_Router_Port'


class LrpGetOptionsCommand(LspGetOptionsCommand):
class LrpGetOptionsCommand(cmd.BaseGetOptionsCommand):
table = 'Logical_Router_Port'


Expand All @@ -984,7 +954,13 @@ def run_idl(self, txn):
lrp.addvalue('gateway_chassis', cmd.result)


class LrpGetGatewayChassisCommand(LrpGetOptionsCommand):
class LrpGetGatewayChassisCommand(cmd.ReadOnlyCommand):
table = 'Logical_Router_Port'

def __init__(self, api, port):
super().__init__(api)
self.port = port

def run_idl(self, txn):
lrp = self.api.lookup(self.table, self.port)
self.result = [rowview.RowView(d) for d in lrp.gateway_chassis]
Expand Down

0 comments on commit e9c6c6c

Please sign in to comment.