Skip to content
Snippets Groups Projects
Commit 2f72c47b authored by Neda Moeini's avatar Neda Moeini
Browse files

Added pagination support.

parent 0590fcd8
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !37. Comments created here will be created in the context of that merge request.
...@@ -125,33 +125,48 @@ def extract_router_info(device: dict, token: str, app_config: dict) -> dict or N ...@@ -125,33 +125,48 @@ def extract_router_info(device: dict, token: str, app_config: dict) -> dict or N
def load_routers_from_orchestrator(app_config: dict) -> dict: def load_routers_from_orchestrator(app_config: dict) -> dict:
"""Gets devices from the orchestrator and returns a dictionary of FQDNs and vendors.""" """Gets devices from the orchestrator and returns a dictionary of FQDNs and vendors."""
token = get_token(app_config['aai']) token = get_token(app_config['aai'])
query = """
{
subscriptions(
filterBy: {field: "status", value: "PROVISIONING|ACTIVE"},
first: 500,
query: "tag:(RTR|OFFICE_ROUTER|Super_POP_SWITCH)"
) {
page {
subscriptionId
product {
tag
}
}
}
}
"""
routers = {} routers = {}
response = make_request(body={'query': query}, token=token, app_config=app_config) end_cursor = 0
try: has_next_page = True
devices = response['data']['subscriptions']['page']
except (TypeError, KeyError): while has_next_page:
devices = [] query = f"""
{{
with concurrent.futures.ThreadPoolExecutor() as executor: subscriptions(
futures = [executor.submit(extract_router_info, device, token, app_config) for device in devices] filterBy: {{field: "status", value: "PROVISIONING|ACTIVE"}},
for future in concurrent.futures.as_completed(futures): first: 100,
router_info = future.result() after: {end_cursor},
if router_info is not None: query: "tag:(RTR|OFFICE_ROUTER|Super_POP_SWITCH)"
routers[router_info['fqdn']] = router_info['vendor'] ) {{
pageInfo {{
hasNextPage
endCursor
}}
page {{
subscriptionId
product {{
tag
}}
}}
}}
}}
"""
response = make_request(body={'query': query}, token=token, app_config=app_config)
try:
devices = response['data']['subscriptions']['page']
page_info = response['data']['subscriptions']['pageInfo']
end_cursor = page_info['endCursor']
has_next_page = page_info['hasNextPage']
except (TypeError, KeyError):
devices = []
has_next_page = False
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [executor.submit(extract_router_info, device, token, app_config) for device in devices]
for future in concurrent.futures.as_completed(futures):
router_info = future.result()
if router_info is not None:
routers[router_info['fqdn']] = router_info['vendor']
return routers return routers
...@@ -71,7 +71,14 @@ def test_load_routers_from_orchestrator(mocker): ...@@ -71,7 +71,14 @@ def test_load_routers_from_orchestrator(mocker):
'page': [ 'page': [
{'subscriptionId': '1', 'product': {'tag': 'RTR'}}, {'subscriptionId': '1', 'product': {'tag': 'RTR'}},
{'subscriptionId': '2', 'product': {'tag': 'OFFICE_ROUTER'}} {'subscriptionId': '2', 'product': {'tag': 'OFFICE_ROUTER'}}
] ],
"pageInfo": {
"totalItems": 2,
"startCursor": 0,
"hasPreviousPage": False,
"hasNextPage": False,
"endCursor": 2
}
} }
} }
}) })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment