Add API endpoint for current primary node

This was never exposed before, so expose it for use in other functions
being built.
This commit is contained in:
Joshua Boniface 2024-08-19 17:15:52 -04:00
parent 212ecaab68
commit 0cf229273a
1 changed files with 40 additions and 1 deletions

View File

@ -597,7 +597,7 @@ class API_Status(Resource):
Set the cluster maintenance mode Set the cluster maintenance mode
--- ---
tags: tags:
- node - root
parameters: parameters:
- in: query - in: query
name: state name: state
@ -622,6 +622,45 @@ class API_Status(Resource):
api.add_resource(API_Status, "/status") 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 # /metrics
class API_Metrics(Resource): class API_Metrics(Resource):
def get(self): def get(self):