Implement getting Node states via API
This commit is contained in:
		| @@ -52,6 +52,78 @@ def node_list(limit=None): | ||||
|     pvc_common.stopZKConnection(zk_conn) | ||||
|     return flask.jsonify(retdata), retcode | ||||
|  | ||||
| def node_daemon_state(node): | ||||
|     """ | ||||
|     Return the daemon state of node NODE. | ||||
|     """ | ||||
|     zk_conn = pvc_common.startZKConnection(config['coordinators']) | ||||
|     retflag, retdata = pvc_node.get_list(zk_conn, node, is_fuzzy=False) | ||||
|     if retflag: | ||||
|         if retdata: | ||||
|             retcode = 200 | ||||
|             retdata = { | ||||
|                 'name': node, | ||||
|                 'daemon_state': retdata[0]['daemon_state'] | ||||
|             } | ||||
|         else: | ||||
|             retcode = 404 | ||||
|             retdata = { | ||||
|                 'message': 'Node not found.' | ||||
|             } | ||||
|     else: | ||||
|         retcode = 400 | ||||
|  | ||||
|     pvc_common.stopZKConnection(zk_conn) | ||||
|     return flask.jsonify(retdata), retcode | ||||
|  | ||||
| def node_coordinator_state(node): | ||||
|     """ | ||||
|     Return the coordinator state of node NODE. | ||||
|     """ | ||||
|     zk_conn = pvc_common.startZKConnection(config['coordinators']) | ||||
|     retflag, retdata = pvc_node.get_list(zk_conn, node, is_fuzzy=False) | ||||
|     if retflag: | ||||
|         if retdata: | ||||
|             retcode = 200 | ||||
|             retdata = { | ||||
|                 'name': node, | ||||
|                 'coordinator_state': retdata[0]['coordinator_state'] | ||||
|             } | ||||
|         else: | ||||
|             retcode = 404 | ||||
|             retdata = { | ||||
|                 'message': 'Node not found.' | ||||
|             } | ||||
|     else: | ||||
|         retcode = 400 | ||||
|  | ||||
|     pvc_common.stopZKConnection(zk_conn) | ||||
|     return flask.jsonify(retdata), retcode | ||||
|  | ||||
| def node_domain_state(node): | ||||
|     """ | ||||
|     Return the domain state of node NODE. | ||||
|     """ | ||||
|     zk_conn = pvc_common.startZKConnection(config['coordinators']) | ||||
|     retflag, retdata = pvc_node.get_list(zk_conn, node, is_fuzzy=False) | ||||
|     if retflag: | ||||
|         if retdata: | ||||
|             retcode = 200 | ||||
|             retdata = { | ||||
|                 'name': node, | ||||
|                 'domain_state': retdata[0]['domain_state'] | ||||
|             } | ||||
|         else: | ||||
|             retcode = 404 | ||||
|             retdata = { | ||||
|                 'message': 'Node not found.' | ||||
|             } | ||||
|     else: | ||||
|         retcode = 400 | ||||
|  | ||||
|     pvc_common.stopZKConnection(zk_conn) | ||||
|     return flask.jsonify(retdata), retcode | ||||
|  | ||||
| def node_secondary(node): | ||||
|     """ | ||||
|     Take NODE out of primary router mode. | ||||
|   | ||||
| @@ -157,12 +157,17 @@ def api_node_element(node): | ||||
|     # Same as specifying /node?limit=NODE | ||||
|     return pvcapi.node_list(node) | ||||
|  | ||||
| @api.route('/api/v1/node/<node>/daemon-state', methods=['GET']) | ||||
| @authenticator | ||||
| def api_node_daemon_state(node): | ||||
|     if flask.request.method == 'GET': | ||||
|         return pvcapi.node_daemon_state(node) | ||||
|  | ||||
| @api.route('/api/v1/node/<node>/coordinator-state', methods=['GET', 'POST']) | ||||
| @authenticator | ||||
| def api_node_coordinator_state(node): | ||||
|     if flask.request.method == 'GET': | ||||
|         return "Test", 200 | ||||
|         return pvcapi.node_coordinator_state(node) | ||||
|  | ||||
|     if flask.request.method == 'POST': | ||||
|         if not 'coordinator-state' in flask.request.values: | ||||
| @@ -178,7 +183,7 @@ def api_node_coordinator_state(node): | ||||
| @authenticator | ||||
| def api_node_domain_state(node): | ||||
|     if flask.request.method == 'GET': | ||||
|         return "Test", 200 | ||||
|         return pvcapi.node_domain_state(node) | ||||
|  | ||||
|     if flask.request.method == 'POST': | ||||
|         if not 'domain-state' in flask.request.values: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user