From 2d90c8b9d68bd9159b093ddce97f572bbdcf13b4 Mon Sep 17 00:00:00 2001 From: Michael Still Date: Mon, 29 Apr 2024 18:47:23 +1000 Subject: [PATCH 1/2] Expose cluster resources to admins. --- shakenfist/external_api/admin.py | 20 +++++++++ shakenfist/external_api/app.py | 2 +- shakenfist/scheduler.py | 72 +++++++++++++++++++++++++++++++- 3 files changed, 92 insertions(+), 2 deletions(-) diff --git a/shakenfist/external_api/admin.py b/shakenfist/external_api/admin.py index f44c11901..533e3d449 100644 --- a/shakenfist/external_api/admin.py +++ b/shakenfist/external_api/admin.py @@ -14,6 +14,7 @@ from shakenfist import etcd from shakenfist.external_api import base as api_base +from shakenfist import scheduler admin_locks_get_example = """{ @@ -61,3 +62,22 @@ def get(self): resp = flask.Response(cacert, mimetype='text/plain') resp.status_code = 200 return resp + + +admin_resources_get_example = """{ + ... +}""" + + +class AdminREsourcesEndpoint(sf_api.Resource): + @swag_from(api_base.swagger_helper( + 'admin', 'List resources currently available in the cluster.', [], + [(200, 'All summary of resource usage and availability in the cluster.', + admin_resources_get_example)], + requires_admin=True)) + @api_base.verify_token + @api_base.caller_is_admin + @api_base.log_token_use + def get(self): + s = scheduler.Scheduler() + return s.summarize_resources() diff --git a/shakenfist/external_api/app.py b/shakenfist/external_api/app.py index 9b34fe3be..1139271e7 100644 --- a/shakenfist/external_api/app.py +++ b/shakenfist/external_api/app.py @@ -121,7 +121,7 @@ def get(self): '

Shaken Fist REST API service

' '

You might be interested in the apidocs.

' '

Machine searchable API capabilities: