from api import Api, ApiAuthType from typing import Tuple class PelicanApi(Api): def __init__(self, base_url, auth_token): self.base_url = base_url self.auth_token = auth_token def apply_authentication(self) -> Tuple[ApiAuthType, dict]: return ApiAuthType.Header, { "Authorization": "Bearer " + self.auth_token } def transform(self, data): type = data["object"] if type == "list": return [self.transform(x) for x in data["data"]] if type in ["allocation", "server", "node"]: return data["attributes"] return data def nodes(self): return self._get("/application/nodes") def servers(self): return self._get("/application/servers") def allocations(self, node_id: int): return self._get("/application/nodes/" + str(node_id) + "/allocations")