Merge "Add APIs for deleting logical router port"

changes/04/205304/2
Jenkins 2015-07-30 13:36:33 +00:00 committed by Gerrit Code Review
commit a9dd1e74a5
3 changed files with 61 additions and 4 deletions

View File

@ -221,8 +221,9 @@ class DelLRouterCommand(BaseCommand):
class AddLRouterPortCommand(BaseCommand):
def __init__(self, api, lrouter, lswitch, may_exist, **columns):
def __init__(self, api, name, lrouter, lswitch, may_exist, **columns):
super(AddLRouterPortCommand, self).__init__(api)
self.name = name
self.lrouter = lrouter
self.lswitch = lswitch
self.columns = columns
@ -241,9 +242,42 @@ class AddLRouterPortCommand(BaseCommand):
return
lrouter_port = txn.insert(self.api._tables['Logical_Router_Port'])
lrouter_port.name = self.name
for col, val in self.columns.items():
setattr(lrouter_port, col, val)
lrouter_ports.append(lrouter_port)
setattr(lrouter, 'ports', lrouter_ports)
lswitch.router_port = lrouter_port
class DelLRouterPortCommand(BaseCommand):
def __init__(self, api, name, lrouter, lswitch, if_exists):
super(DelLRouterPortCommand, self).__init__(api)
self.name = name
self.lrouter = lrouter
self.lswitch = lswitch
self.if_exists = if_exists
def run_idl(self, txn):
try:
lrouter = idlutils.row_by_value(self.api.idl, 'Logical_Router',
'name', self.lrouter)
lswitch = idlutils.row_by_value(self.api.idl, 'Logical_Switch',
'name', self.lswitch)
lrouter_ports = getattr(lrouter, 'ports', [])
lrouter_port = idlutils.row_by_value(self.api.idl,
'Logical_Router_Port',
'name', self.name)
except idlutils.RowNotFound:
if self.if_exists:
return
msg = _("Logical Router Port %s does not exist") % self.name
LOG.error(msg)
raise RuntimeError(msg)
lrouter_ports.remove(lrouter_port)
setattr(lrouter, 'ports', lrouter_ports)
setattr(lswitch, 'router_port', [])

View File

@ -102,6 +102,11 @@ class OvsdbOvnIdl(ovn_api.API):
def delete_lrouter(self, name, if_exists=True):
return cmd.DelLRouterCommand(self, name, if_exists)
def add_lrouter_port(self, lrouter, lswitch, may_exist=True, **columns):
return cmd.AddLRouterPortCommand(self, lrouter, lswitch,
def add_lrouter_port(self, name, lrouter, lswitch, may_exist=True,
**columns):
return cmd.AddLRouterPortCommand(self, name, lrouter, lswitch,
may_exist, **columns)
def delete_lrouter_port(self, name, lrouter, lswitch, if_exists=True):
return cmd.DelLRouterPortCommand(self, name, lrouter, lswitch,
if_exists)

View File

@ -172,9 +172,12 @@ class API(object):
"""
@abc.abstractmethod
def add_lrouter_port(self, lrouter, lswitch, may_exist=True, **columns):
def add_lrouter_port(self, name, lrouter, lswitch, may_exist=True,
**columns):
"""Create a command to add an OVN lrouter port
:param name: The unique name of the lrouter port
:type name: string
:param lrouter: The unique name of the lrouter
:type lrouter: string
:param lswitch: The unique name of the lswitch
@ -186,3 +189,18 @@ class API(object):
:type columns: dictionary
:returns: :class:`Command` with no result
"""
@abc.abstractmethod
def delete_lrouter_port(self, name, lrouter, lswitch, if_exists=True):
"""Create a command to delete an OVN lrouter port
:param name: The name of the lrouter port
:type name: string
:param lrouter: The unique name of the lrouter
:type lrouter: string
:param lswitch: The unique name of the lswitch
:type lswitch: string
:param if_exists: Do not fail if the lrouter port does not exists
:type if_exists: bool
:returns: :class:`Command` with no result
"""