Remove interface networks when class set to none
When an interface class was modified from platform to none, the associated interface-network were not removed. This update deletes the interface-network records for the interface to disassociate the networks from the interface. Depends-On: https://review.openstack.org/604128 Closes-Bug: 1793349 Change-Id: I5eac2b4cb0ee62a8bf37c024aa08ca110ee80e7c Signed-off-by: Teresa Ho <teresa.ho@windriver.com>
This commit is contained in:
parent
001e02ab27
commit
b4e81b288d
|
@ -440,6 +440,7 @@ class InterfaceController(rest.RestController):
|
|||
ports = None
|
||||
networks = []
|
||||
networks_to_add = []
|
||||
interface_networks_to_remove = []
|
||||
patches_to_remove = []
|
||||
for p in patch:
|
||||
if '/ifclass' == p['path']:
|
||||
|
@ -457,6 +458,9 @@ class InterfaceController(rest.RestController):
|
|||
elif '/networks_to_add' == p['path']:
|
||||
networks_to_add = p['value'].split(',')
|
||||
patches_to_remove.append(p)
|
||||
elif '/interface_networks_to_remove' == p['path']:
|
||||
interface_networks_to_remove = p['value'].split(',')
|
||||
patches_to_remove.append(p)
|
||||
|
||||
if uses:
|
||||
patch.append(dict(path='/uses', value=uses, op='replace'))
|
||||
|
@ -627,7 +631,7 @@ class InterfaceController(rest.RestController):
|
|||
|
||||
saved_interface = copy.deepcopy(rpc_interface)
|
||||
|
||||
# Update network-interface
|
||||
# Update interface-network
|
||||
try:
|
||||
if networks_to_add:
|
||||
for network_id in networks_to_add:
|
||||
|
@ -647,6 +651,23 @@ class InterfaceController(rest.RestController):
|
|||
"interface %s" % (interface['ifname']))
|
||||
raise wsme.exc.ClientSideError(msg)
|
||||
|
||||
try:
|
||||
# Remove old networks from the interface
|
||||
if interface_networks_to_remove:
|
||||
for ifnet_id in interface_networks_to_remove:
|
||||
pecan.request.dbapi.interface_network_destroy(ifnet_id)
|
||||
elif (not ifclass and
|
||||
orig_ifclass == constants.INTERFACE_CLASS_PLATFORM):
|
||||
ifnets = pecan.request.dbapi.interface_network_get_by_interface(
|
||||
rpc_interface['uuid'])
|
||||
for ifnet in ifnets:
|
||||
pecan.request.dbapi.interface_network_destroy(ifnet.uuid)
|
||||
except Exception as e:
|
||||
LOG.exception(e)
|
||||
msg = _("Failed to remove interface network association for "
|
||||
"interface %s" % (interface['ifname']))
|
||||
raise wsme.exc.ClientSideError(msg)
|
||||
|
||||
try:
|
||||
# Update only the fields that have changed
|
||||
for field in objects.interface.fields:
|
||||
|
|
|
@ -4329,3 +4329,26 @@ class Connection(object):
|
|||
}
|
||||
:returns: An interface network association
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def interface_network_get_by_interface(self, interface_id,
|
||||
limit=None, marker=None,
|
||||
sort_key=None, sort_dir=None):
|
||||
"""List all the interface networks for a given interface.
|
||||
|
||||
:param interface_id: The id or uuid of an interface.
|
||||
:param limit: Maximum number of items to return.
|
||||
:param marker: the last item of the previous page; we return the next
|
||||
result set.
|
||||
:param sort_key: Attribute by which results should be sorted
|
||||
:param sort_dir: direction in which results should be sorted
|
||||
(asc, desc)
|
||||
:returns: A list of interface-network.
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def interface_network_destroy(self, uuid):
|
||||
"""Destroy an interface network association
|
||||
|
||||
:param uuid: The uuid of an interface network association.
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue