From e0c7397703de7cc0d92b9c342f3ab253915c5790 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Thu, 26 Dec 2019 17:52:57 -0500 Subject: [PATCH] Complete node API client functions --- client-cli/cli_lib/node.py | 35 +++++++++++++++++++++++++++++++++++ client-cli/pvc.py | 5 ++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/client-cli/cli_lib/node.py b/client-cli/cli_lib/node.py index e20412d3..58d5f21e 100644 --- a/client-cli/cli_lib/node.py +++ b/client-cli/cli_lib/node.py @@ -133,6 +133,41 @@ def node_info(config, node): else: return False, response.json()['message'] +def node_list(config, limit): + """ + Get list information about nodes (limited by {limit}) + + API endpoint: GET /api/v1/node + API arguments: limit={limit} + API schema: [{json_data_object},{json_data_object},etc.] + """ + if limit: + params = {'limit': limit} + else: + params = {} + + request_uri = get_request_uri(config, '/node') + response = requests.get( + request_uri, + params=params + ) + + if config['debug']: + print( + 'API endpoint: GET {}'.format(request_uri) + ) + print( + 'Response code: {}'.format(response.status_code) + ) + print( + 'Response headers: {}'.format(response.headers) + ) + + if response.status_code == 200: + return True, response.json() + else: + return False, response.json()['message'] + # # Output display functions # diff --git a/client-cli/pvc.py b/client-cli/pvc.py index c662b6e3..a576c5d0 100755 --- a/client-cli/pvc.py +++ b/client-cli/pvc.py @@ -187,12 +187,11 @@ def node_list(limit): List all nodes in the cluster; optionally only match names matching regex LIMIT. """ - zk_conn = pvc_common.startZKConnection(zk_host) - retcode, retdata = pvc_node.get_list(zk_conn, limit) + retcode, retdata = pvc_node.node_list(config, limit) if retcode: pvc_node.format_list(retdata) retdata = '' - cleanup(retcode, retdata, zk_conn) + cleanup(retcode, retdata) ############################################################################### # pvc vm