From 49de66efab8c4dc870eca2e184c38d0d436d7494 Mon Sep 17 00:00:00 2001 From: Lars Kellogg-Stedman Date: Thu, 12 Dec 2024 22:13:25 -0500 Subject: [PATCH] Teach esi.lib.nodes how to detach all ports --- esi/lib/nodes.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/esi/lib/nodes.py b/esi/lib/nodes.py index ac64046..443a327 100644 --- a/esi/lib/nodes.py +++ b/esi/lib/nodes.py @@ -12,6 +12,7 @@ # under the License. import concurrent.futures +import warnings from openstack import exceptions @@ -20,7 +21,6 @@ OPENSTACK_IRONIC_API_VERSION = '1.69' - def node_and_port_list(connection, filter_node=None): """Get lists baremetal nodes and ports @@ -242,18 +242,24 @@ def network_attach(connection, node, attach_info): } -def network_detach(connection, node, port=None): +def network_detach(connection, node_name=None, port=None, port_names=None, all_ports=False): """Detaches a node's bare metal port from a network port :param port: The name or ID of a network port - :returns: ``True`` if the VIF was detached, otherwise ``False`` + :returns: A list of ``(port_uuid, bool)`` tuples, where ``bool`` is ``True`` if the port was removed + successfully, ``False`` otherwise. """ - node = connection.baremetal.get_node(node) + node= connection.baremetal.get_node(node_name) + ports = [] if port: - port = connection.network.find_port(port, ignore_missing=False) + port_names = [port] + warnings.warn("The 'port' parameter is deprecated and will be removed in a future release.", DeprecationWarning, stacklevel=2) + + if port_names: + ports = [connection.network.find_port(port, ignore_missing=False) for port in ports] else: bm_ports = connection.baremetal.ports(details=True, node=node.id) @@ -263,12 +269,16 @@ def network_detach(connection, node, port=None): if len(mapped_node_port_list) == 0: raise exceptions.ResourceFailure( 'Node {0} is not associated with any port'.format(node.name)) + + if all_ports: + ports = [connection.network.find_port(bmport.internal_info['tenant_vif_port_id'], ignore_missing=False) + for bmport in mapped_node_port_list] elif len(mapped_node_port_list) > 1: raise exceptions.ResourceFailure( - "Node {0} is associated with multiple ports. \ - Port must be specified".format(node.name)) + "Node {0} is associated with multiple ports. Port must be specified".format(node.name)) elif len(mapped_node_port_list) == 1: - port = mapped_node_port_list[0].internal_info["tenant_vif_port_id"] - port = connection.network.find_port(port, ignore_missing=False) + vif = mapped_node_port_list[0].internal_info["tenant_vif_port_id"] + port = connection.network.find_port(vif, ignore_missing=False) + ports = [port] - return connection.baremetal.detach_vif_from_node(node, port.id) + return [(port.id, connection.baremetal.detach_vif_from_node(node, port.id)) for port in ports]