From 0cf229273a13d9fd7ab6e0825a5cf68d744775e4 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 19 Aug 2024 17:15:52 -0400 Subject: [PATCH] Add API endpoint for current primary node This was never exposed before, so expose it for use in other functions being built. --- api-daemon/pvcapid/flaskapi.py | 41 +++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/api-daemon/pvcapid/flaskapi.py b/api-daemon/pvcapid/flaskapi.py index f2334ba9..84d3aba1 100755 --- a/api-daemon/pvcapid/flaskapi.py +++ b/api-daemon/pvcapid/flaskapi.py @@ -597,7 +597,7 @@ class API_Status(Resource): Set the cluster maintenance mode --- tags: - - node + - root parameters: - in: query name: state @@ -622,6 +622,45 @@ class API_Status(Resource): api.add_resource(API_Status, "/status") +# /status/primary_node +class API_Status_Primary(Resource): + def get(self): + """ + Return the name of the current primary node. + --- + tags: + - root + responses: + 200: + description: OK + schema: + type: object + properties: + primary_node: + type: string + description: The name of the current primary node + 204: + description: No content + schema: + type: object + properties: + primary_node: + type: string + description: An empty response; there is not currently a primary node, try again later + """ + primary_node = get_primary_node() + if primary_node is None: + retdata = None + retcode = 204 + else: + retdata = {"primary_node": primary_node} + retcode = 200 + return retdata, retcode + + +api.add_resource(API_Status_Primary, "/status/primary_node") + + # /metrics class API_Metrics(Resource): def get(self):