From f6154bb2e381d58fe6b9ca8e57aed7d0541c71b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Mon, 24 Sep 2018 16:23:23 +0200 Subject: [PATCH] Refactor attribute lookup to make it multithreaded (#45786) --- lib/ansible/plugins/inventory/netbox.py | 26 ++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/ansible/plugins/inventory/netbox.py b/lib/ansible/plugins/inventory/netbox.py index cf4bbbdf4a4..b545067700b 100644 --- a/lib/ansible/plugins/inventory/netbox.py +++ b/lib/ansible/plugins/inventory/netbox.py @@ -86,6 +86,7 @@ query_filters: import json import uuid from sys import version as python_version +from threading import Thread from ansible.plugins.inventory import BaseInventoryPlugin from ansible.module_utils.ansible_release import __version__ as ansible_version @@ -276,13 +277,24 @@ class InventoryModule(BaseInventoryPlugin): self.manufacturers_lookup = dict((manufacturer["id"], manufacturer["name"]) for manufacturer in manufacturers) def refresh_lookups(self): - self.refresh_sites_lookup() - self.refresh_regions_lookup() - self.refresh_tenants_lookup() - self.refresh_racks_lookup() - self.refresh_device_roles_lookup() - self.refresh_device_types_lookup() - self.refresh_manufacturers_lookup() + lookup_processes = ( + self.refresh_sites_lookup, + self.refresh_regions_lookup, + self.refresh_tenants_lookup, + self.refresh_racks_lookup, + self.refresh_device_roles_lookup, + self.refresh_device_types_lookup, + self.refresh_manufacturers_lookup, + ) + + thread_list = [] + for p in lookup_processes: + t = Thread(target=p) + thread_list.append(t) + t.start() + + for thread in thread_list: + thread.join() def validate_query_parameters(self, x): if not (isinstance(x, dict) and len(x) == 1):