Skip to content

Commit

Permalink
Parallelizing API calls using concurrent.futures
Browse files Browse the repository at this point in the history
  • Loading branch information
rd4398 committed Sep 15, 2022
1 parent 509e9e6 commit 288cba7
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions esiclient/v1/node_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 288cba7

Please sign in to comment.