NBDB API: Add param if_exists for methods using db_remove()

This patch is adding the parameter "if_exists" to the methods in the
Northbound DB API that uses the db_remove() method underneath.

The following methods were affected:

* dns_remove_record()
* ls_remove_dns_record()

The intention of this patch is to make the API more flexible for
projects relying on those methods so they can choose whether they want
to raise an exception if the item being removed exist or not.

Closes-Bug: #1793132
Change-Id: I1e6749a9f3827f91a9db29e6f5ba0c8b7a6cc622
This commit is contained in:
Lucas Alvares Gomes 2018-09-18 10:07:05 +01:00
parent 1c58eacc81
commit 31a4764353
2 changed files with 17 additions and 6 deletions

View File

@ -86,9 +86,16 @@ class API(api.API):
"""
@abc.abstractmethod
def ls_remove_dns_record(self, switch_uuid, dns_uuid):
def ls_remove_dns_record(self, switch_uuid, dns_uuid, if_exists=False):
"""Remove the 'dns_record' from the switch's 'dns_records' list
:param switch_uuid: The uuid of the switch
:type switch_uuid: string or uuid.UUID
:param dns_uuid: The uuid of the DNS record
:type dns_uuid: string or uuid.UUID
:param if_exists: If True, don't fail if the DNS record
doesn't exist
:type if_exists: boolean
:returns: :class:`Command` with RowView result
"""
@ -852,12 +859,15 @@ class API(api.API):
"""
@abc.abstractmethod
def dns_remove_record(self, uuid, hostname):
def dns_remove_record(self, uuid, hostname, if_exists=False):
"""Remove the 'hostname' from the 'records' field of the DNS row
:param uuid: The uuid of the DNS row to set the records with
:type uuid: string or uuid.UUID
:param hostname: hostname as the key to the record dict
:param if_exists: If True, don't fail if the DNS record
doesn't exist
:type if_exists: boolean
:returns: :class:`Command` with no result
"""

View File

@ -49,9 +49,9 @@ class OvnNbApiIdlImpl(ovs_idl.Backend, api.API):
return self.db_add('Logical_Switch', switch_uuid, 'dns_records',
dns_uuid)
def ls_remove_dns_record(self, switch_uuid, dns_uuid):
def ls_remove_dns_record(self, switch_uuid, dns_uuid, if_exists=False):
return self.db_remove('Logical_Switch', switch_uuid, 'dns_records',
dns_uuid)
dns_uuid, if_exists=if_exists)
def acl_add(self, switch, direction, priority, match, action, log=False,
may_exist=False, **external_ids):
@ -269,8 +269,9 @@ class OvnNbApiIdlImpl(ovs_idl.Backend, api.API):
ips = " ".join(utils.normalize_ip_port(ip) for ip in ips)
return self.db_add('DNS', uuid, 'records', {hostname: ips})
def dns_remove_record(self, uuid, hostname):
return self.db_remove('DNS', uuid, 'records', hostname)
def dns_remove_record(self, uuid, hostname, if_exists=False):
return self.db_remove('DNS', uuid, 'records', hostname,
if_exists=if_exists)
def dns_set_external_ids(self, uuid, **external_ids):
return cmd.DnsSetExternalIdsCommand(self, uuid, **external_ids)