From 288cba7bf38719908cd938bb8d95e7f686a27ab4 Mon Sep 17 00:00:00 2001 From: Rohan Devasthale Date: Thu, 15 Sep 2022 10:49:33 -0400 Subject: [PATCH] Parallelizing API calls using concurrent.futures --- esiclient/v1/node_network.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/esiclient/v1/node_network.py b/esiclient/v1/node_network.py index 86ecfc8..892ccbc 100644 --- a/esiclient/v1/node_network.py +++ b/esiclient/v1/node_network.py @@ -10,6 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. +import concurrent.futures import logging from osc_lib.command import command @@ -54,8 +55,14 @@ def take_action(self, parsed_args): else: node_name = parsed_args.node else: - ports = ironic_client.port.list(detail=True) - nodes = ironic_client.node.list() + ports = None + nodes = None + + with concurrent.futures.ThreadPoolExecutor() as executor: + f1 = executor.submit(ironic_client.port.list, detail=True) + f2 = executor.submit(ironic_client.node.list) + ports = f1.result() + nodes = f2.result() filter_network = None if parsed_args.network: @@ -241,8 +248,14 @@ def take_action(self, parsed_args): ironic_client = self.app.client_manager.baremetal neutron_client = self.app.client_manager.network - node = ironic_client.node.get(node_uuid) - port = neutron_client.find_port(port_uuid) + node = None + port = None + + with concurrent.futures.ThreadPoolExecutor() as executor: + f1 = executor.submit(ironic_client.node.get, node_uuid) + f2 = executor.submit(neutron_client.find_port, port_uuid) + node = f1.result() + port = f2.result() if not port: raise exceptions.CommandError(