Unverified Commit d2314e04 authored by Jakob Görgen's avatar Jakob Görgen
Browse files

client/simbricks/client/client: added admin client

parent 7b6f7fd1
......@@ -20,4 +20,4 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from .client import BaseClient, NSClient, SimBricksClient, RunnerClient
from .client import BaseClient, AdminClient, NSClient, SimBricksClient, RunnerClient
......@@ -107,11 +107,38 @@ class BaseClient:
return await resp.json()
class AdminClient:
def __init__(self, base_client: BaseClient = BaseClient()):
self._base_client = base_client
def _prefix(self, url: str) -> str:
return f"/admin{url}"
async def get_ns(self, ns_id: int):
async with self._base_client.get(url=self._prefix(f"/{ns_id}")) as resp:
return await resp.json()
async def get_all_ns(self):
async with self._base_client.get(url=self._prefix("/")) as resp:
return await resp.json()
async def create_ns(self, parent_id: int | None, name: str):
namespace_json = {"name": name}
if parent_id:
namespace_json["parent_id"] = parent_id
async with self._base_client.post(url=self._prefix("/"), json=namespace_json) as resp:
return await resp.json()
async def delete(self, ns_id: int):
async with self._base_client.delete(url=self._prefix(f"/{ns_id}")) as resp:
return await resp.json()
class NSClient:
def __init__(self, base_client: BaseClient = BaseClient(), namespace: str = ""):
self._base_client: BaseClient = base_client
self._namespace = namespace
self._session: aiohttp.ClientSession | None = None
def _build_ns_prefix(self, url: str) -> str:
return f"/ns/{self._namespace}/-{url}"
......@@ -226,7 +253,7 @@ class SimBricksClient:
async with self._ns_client.get(url=f"/runs/{run_id}") as resp:
return await resp.json()
async def get_runs(self) -> [dict]:
async def get_runs(self) -> list[dict]:
async with self._ns_client.get(url=f"/runs") as resp:
return await resp.json()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment