diff --git a/client-api/api_lib/pvcapi_helper.py b/client-api/api_lib/pvcapi_helper.py index 38ae0012..1d93e868 100755 --- a/client-api/api_lib/pvcapi_helper.py +++ b/client-api/api_lib/pvcapi_helper.py @@ -26,6 +26,7 @@ import json from distutils.util import strtobool import client_lib.common as pvc_common +import client_lib.cluster as pvc_cluster import client_lib.node as pvc_node import client_lib.vm as pvc_vm import client_lib.network as pvc_network @@ -67,6 +68,17 @@ def initialize_cluster(): return True +# +# Status function +# +def cluster_status(): + """ + Get the overall status of the PVC cluster + """ + zk_conn = pvc_common.startZKConnection(config['coordinators']) + retflag, retdata = pvc_cluster.get_info(zk_conn) + return retdata, 200 + # # Node functions # diff --git a/client-api/pvc-api.py b/client-api/pvc-api.py index cf23f100..1767b405 100755 --- a/client-api/pvc-api.py +++ b/client-api/pvc-api.py @@ -310,13 +310,94 @@ class API_Initialize(Resource): 400: description: Bad request """ - # TODO: Implement me in api_helper if api_helper.initialize_cluster(): return { "message": "Successfully initialized a new PVC cluster" }, 200 else: return { "message": "PVC cluster already initialized" }, 400 api.add_resource(API_Initialize, '/initialize') +# /status +class API_Status(Resource): + @Authenticator + def get(self): + """ + Return the current PVC cluster status + --- + tags: + - root + responses: + 200: + description: OK + schema: + type: object + id: ClusterStatus + properties: + health: + type: string + description: The overall cluster health + example: Optimal + primary_node: + type: string + description: The current primary coordinator node + example: pvchv1 + upstream_ip: + type: string + description: The cluster upstream IP address in CIDR format + example: 10.0.0.254/24 + nodes: + type: array + items: + type: object + properties: + total: + type: integer + description: The total number of nodes in the cluster + example: 3 + state-combination: + type: integer + description: The total number of nodes in {state-combination} state, where {state-combination} is the node daemon and domain states in CSV format, e.g. "run,ready", "stop,flushed", etc. + vms: + type: array + items: + type: object + properties: + total: + type: integer + description: The total number of VMs in the cluster + example: 6 + state: + type: integer + description: The total number of VMs in {state} state, e.g. "start", "stop", etc. + networks: + type: integer + description: The total number of networks in the cluster + osds: + type: array + items: + type: object + properties: + total: + type: integer + description: The total number of OSDs in the storage cluster + example: 3 + state-combination: + type: integer + description: The total number of OSDs in {state-combination} state, where {state-combination} is the OSD up and in states in CSV format, e.g. "up,in", "down,out", etc. + pools: + type: integer + description: The total number of pools in the storage cluster + volumes: + type: integer + description: The total number of volumes in the storage cluster + snapshots: + type: integer + description: The total number of snapshots in the storage cluster + 400: + description: Bad request + """ + return api_helper.cluster_status() +api.add_resource(API_Status, '/status') + ########################################################## # Client API - Node