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

Updated gap.py to support older Python versions

parent 0c589a07
Branches
Tags
No related merge requests found
import concurrent.futures
import logging
import socket
from typing import Dict, Optional
import requests
from requests.adapters import HTTPAdapter
......@@ -52,7 +53,7 @@ def get_token(aai_config: dict) -> str:
return response.json()['access_token']
def make_request(body: dict, token: str, app_config: dict) -> dict:
def make_request(body: dict, token: str, app_config: dict) -> Dict:
"""Make a request to the orchestrator using the given body."""
api_url = f'{app_config["orchestrator"]["url"]}/api/graphql'
headers = {'Authorization': f'Bearer {token}'}
......@@ -66,14 +67,15 @@ def make_request(body: dict, token: str, app_config: dict) -> dict:
response = session.post(api_url, headers=headers, json=body)
response.raise_for_status()
# The graphql API returns a 200 status code even if there are errors in the response
if errors := response.json().get('errors'):
errors = response.json().get('errors')
if errors:
err_msg = f'GraphQL query returned errors: {errors}'
logger.error(err_msg)
raise ValueError(err_msg)
return response.json()
def extract_router_info(device: dict, token: str, app_config: dict) -> dict or None:
def extract_router_info(device: dict, token: str, app_config: dict) -> Optional[dict]:
tag_to_key_map = {
"RTR": "router",
"OFFICE_ROUTER": "officeRouter",
......@@ -122,7 +124,7 @@ def extract_router_info(device: dict, token: str, app_config: dict) -> dict or N
return None
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."""
token = get_token(app_config['aai'])
routers = {}
......
......@@ -940,7 +940,7 @@ def load_error_report_interfaces(
)
)
def transform_interface(interface: dict) -> dict:
def transform_interface(interface: dict) -> Dict:
return {
"router": interface["router"],
"name": interface["name"],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment