Node info moved to API

This commit is contained in:
Joshua Boniface 2019-12-26 11:20:57 -05:00
parent 3d178304f1
commit 28a0ce772b
2 changed files with 39 additions and 12 deletions

View File

@ -49,7 +49,6 @@ def node_coordinator_state(config, node, action):
API schema: {"message": "{data}"}
"""
request_uri = get_request_uri(config, '/node/{node}/coordinator-state'.format(node=node))
response = requests.post(
request_uri,
params={'state': action}
@ -82,7 +81,6 @@ def node_domain_state(config, node, action, wait):
API schema: {"message": "{data}"}
"""
request_uri = get_request_uri(config, '/node/{node}/domain-state'.format(node=node))
response = requests.post(
request_uri,
params={'state': action, 'wait': wait}
@ -106,6 +104,35 @@ def node_domain_state(config, node, action, wait):
return retstatus, response.json()['message']
def node_info(config, node):
"""
Get information about node
API endpoint: GET /api/v1/node/{node}
API arguments:
API schema: {json_data_object}
"""
request_uri = get_request_uri(config, '/node/{node}'.format(node=node))
response = requests.get(
request_uri
)
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
#

View File

@ -42,7 +42,7 @@ myhostname = socket.gethostname().split('.')[0]
zk_host = ''
config = dict()
config['debug'] = True
config['debug'] = False
config['api_scheme'] = 'http'
config['api_host'] = 'localhost:7370'
config['api_prefix'] = '/api/v1'
@ -169,17 +169,11 @@ def node_info(node, long_output):
Show information about node NODE. If unspecified, defaults to this host.
"""
zk_conn = pvc_common.startZKConnection(zk_host)
retcode, retdata = pvc_node.get_info(zk_conn, node)
retcode, retdata = pvc_node.node_info(config, node)
if retcode:
pvc_node.format_info(retdata, long_output)
if long_output:
click.echo('{}Virtual machines on node:{}'.format(ansiprint.bold(), ansiprint.end()))
click.echo('')
pvc_vm.get_list(zk_conn, node, None, None, None)
click.echo('')
retdata = ''
cleanup(retcode, retdata, zk_conn)
cleanup(retcode, retdata)
###############################################################################
# pvc node list
@ -1811,7 +1805,11 @@ def init_cluster(yes):
'-z', '--zookeeper', '_zk_host', envvar='PVC_ZOOKEEPER', default=None,
help='Zookeeper connection string.'
)
def cli(_zk_host):
@click.option(
'-v', '--debug', '_debug', envvar='PVC_DEBUG', is_flag=True, default=False,
help='Additional debug details.'
)
def cli(_zk_host, _debug):
"""
Parallel Virtual Cluster CLI management tool
@ -1838,6 +1836,8 @@ def cli(_zk_host):
global zk_host
zk_host = _zk_host
global config
config['debug'] = _debug
#