Refactor provisioner data+list format to match

This commit is contained in:
Joshua Boniface 2020-01-12 14:23:11 -05:00
parent b9177c2f26
commit c4ef73c953
2 changed files with 27 additions and 26 deletions

View File

@ -501,8 +501,30 @@ def task_status(config, task_id=None, is_watching=False):
retdata = response.json()['message'] retdata = response.json()['message']
else: else:
retvalue = True retvalue = True
respjson = response.json() task_data_raw = response.json()
retdata = format_list_task(respjson) # Format the Celery data into a more useful data structure
task_data = list()
for task_type in ['active', 'reserved', 'scheduled']:
type_data = task_data_raw[task_type]
if not type_data:
type_data = dict()
for task_host in type_data:
for task_job in task_data_raw[task_type][task_host]:
task = dict()
if task_type == 'reserved':
task['type'] = 'pending'
else:
task['type'] = task_type
task['worker'] = task_host
task['id'] = task_job.get('id')
task_args = ast.literal_eval(task_job.get('args'))
task['vm_name'] = task_args[0]
task['vm_profile'] = task_args[1]
task_kwargs = ast.literal_eval(task_job.get('kwargs'))
task['vm_define'] = str(bool(task_kwargs['define_vm']))
task['vm_start'] = str(bool(task_kwargs['start_vm']))
task_data.append(task)
retdata = task_data
return retvalue, retdata return retvalue, retdata
@ -1152,30 +1174,7 @@ Data: {profile_userdata: <{profile_userdata_length}} \
return '\n'.join([profile_list_output_header] + profile_list_output) return '\n'.join([profile_list_output_header] + profile_list_output)
def format_list_task(task_data_raw): def format_list_task(task_data):
# Format the Celery data into a more useful data structure
task_data = list()
for task_type in ['active', 'reserved', 'scheduled']:
type_data = task_data_raw[task_type]
if not type_data:
type_data = dict()
for task_host in type_data:
for task_job in task_data_raw[task_type][task_host]:
task = dict()
if task_type == 'reserved':
task['type'] = 'pending'
else:
task['type'] = task_type
task['worker'] = task_host
task['id'] = task_job.get('id')
task_args = ast.literal_eval(task_job.get('args'))
task['vm_name'] = task_args[0]
task['vm_profile'] = task_args[1]
task_kwargs = ast.literal_eval(task_job.get('kwargs'))
task['vm_define'] = str(bool(task_kwargs['define_vm']))
task['vm_start'] = str(bool(task_kwargs['start_vm']))
task_data.append(task)
task_list_output = [] task_list_output = []
# Determine optimal column widths # Determine optimal column widths

View File

@ -3036,6 +3036,8 @@ def provisioner_status(job):
Show status of provisioner job JOB or a list of jobs. Show status of provisioner job JOB or a list of jobs.
""" """
retcode, retdata = pvc_provisioner.task_status(config, job) retcode, retdata = pvc_provisioner.task_status(config, job)
if job is None and retcode:
retdata = pvc_provisioner.format_list_task(retdata)
cleanup(retcode, retdata) cleanup(retcode, retdata)