33 lines
892 B
Python
33 lines
892 B
Python
from api import Api, ApiAuthType
|
|
from typing import Tuple
|
|
|
|
|
|
class PelicanApi(Api):
|
|
base_url = "http://svr.pve.local:80/api"
|
|
|
|
def __init__(self):
|
|
pass
|
|
|
|
def apply_authentication(self) -> Tuple[ApiAuthType, dict]:
|
|
return ApiAuthType.Header, {
|
|
"Authorization": "Bearer peli_MiN4ALiBUBoRLA5glkfaUVMTjwDuJTm7kLEa5Xbpwm0"
|
|
}
|
|
|
|
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")
|