From 31a476435373a8c6581ad66d96fbe314711e7f36 Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Tue, 18 Sep 2018 10:07:05 +0100 Subject: [PATCH] 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 --- ovsdbapp/schema/ovn_northbound/api.py | 14 ++++++++++++-- ovsdbapp/schema/ovn_northbound/impl_idl.py | 9 +++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ovsdbapp/schema/ovn_northbound/api.py b/ovsdbapp/schema/ovn_northbound/api.py index 80836493..6e81dfea 100644 --- a/ovsdbapp/schema/ovn_northbound/api.py +++ b/ovsdbapp/schema/ovn_northbound/api.py @@ -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 """ diff --git a/ovsdbapp/schema/ovn_northbound/impl_idl.py b/ovsdbapp/schema/ovn_northbound/impl_idl.py index 48b1780f..248a8ab5 100644 --- a/ovsdbapp/schema/ovn_northbound/impl_idl.py +++ b/ovsdbapp/schema/ovn_northbound/impl_idl.py @@ -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)