Remove obsolete status and add cluster task
Removes the obsoleted "pvc provisioner status" command and replaces it with a generalized "pvc cluster task" command to show all currently-active or pending tasks on the cluster workers.
This commit is contained in:
parent
484e6542c2
commit
d727764ebc
|
@ -534,6 +534,30 @@ def cli_cluster_maintenance_off():
|
||||||
finish(retcode, retdata)
|
finish(retcode, retdata)
|
||||||
|
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# > pvc cluster task
|
||||||
|
###############################################################################
|
||||||
|
@click.command(name="task", short_help="Show status of worker task.")
|
||||||
|
@connection_req
|
||||||
|
@click.argument("job_id", required=False, default=None)
|
||||||
|
@format_opt(
|
||||||
|
{
|
||||||
|
"pretty": cli_provisioner_status_format_pretty,
|
||||||
|
"raw": lambda d: "\n".join([t["id"] for t in d])
|
||||||
|
if isinstance(d, list)
|
||||||
|
else d["state"],
|
||||||
|
"json": lambda d: jdumps(d),
|
||||||
|
"json-pretty": lambda d: jdumps(d, indent=2),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
def cli_cluster_task(job_id, format_function):
|
||||||
|
"""
|
||||||
|
Show the current status of worker task JOB_ID or a list of all active and pending tasks.
|
||||||
|
"""
|
||||||
|
retcode, retdata = pvc.lib.common.task_status(CLI_CONFIG, job_id)
|
||||||
|
finish(retcode, retdata, format_function)
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# > pvc node
|
# > pvc node
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -5630,30 +5654,6 @@ def cli_provisioner_create(
|
||||||
finish(retcode, retmsg)
|
finish(retcode, retmsg)
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# > pvc provisioner status
|
|
||||||
###############################################################################
|
|
||||||
@click.command(name="status", short_help="Show status of provisioner job.")
|
|
||||||
@connection_req
|
|
||||||
@click.argument("job", required=False, default=None)
|
|
||||||
@format_opt(
|
|
||||||
{
|
|
||||||
"pretty": cli_provisioner_status_format_pretty,
|
|
||||||
"raw": lambda d: "\n".join([t["id"] for t in d])
|
|
||||||
if isinstance(d, list)
|
|
||||||
else d["state"],
|
|
||||||
"json": lambda d: jdumps(d),
|
|
||||||
"json-pretty": lambda d: jdumps(d, indent=2),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
def cli_provisioner_status(job, format_function):
|
|
||||||
"""
|
|
||||||
Show status of provisioner job JOB or a list of jobs.
|
|
||||||
"""
|
|
||||||
retcode, retdata = pvc.lib.provisioner.task_status(CLI_CONFIG, job)
|
|
||||||
finish(retcode, retdata, format_function)
|
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# > pvc connection
|
# > pvc connection
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -6168,7 +6168,6 @@ cli_provisioner_profile.add_command(cli_provisioner_profile_remove)
|
||||||
cli_provisioner_profile.add_command(cli_provisioner_profile_list)
|
cli_provisioner_profile.add_command(cli_provisioner_profile_list)
|
||||||
cli_provisioner.add_command(cli_provisioner_profile)
|
cli_provisioner.add_command(cli_provisioner_profile)
|
||||||
cli_provisioner.add_command(cli_provisioner_create)
|
cli_provisioner.add_command(cli_provisioner_create)
|
||||||
cli_provisioner.add_command(cli_provisioner_status)
|
|
||||||
cli.add_command(cli_provisioner)
|
cli.add_command(cli_provisioner)
|
||||||
cli_cluster.add_command(cli_cluster_status)
|
cli_cluster.add_command(cli_cluster_status)
|
||||||
cli_cluster.add_command(cli_cluster_init)
|
cli_cluster.add_command(cli_cluster_init)
|
||||||
|
@ -6177,6 +6176,7 @@ cli_cluster.add_command(cli_cluster_restore)
|
||||||
cli_cluster_maintenance.add_command(cli_cluster_maintenance_on)
|
cli_cluster_maintenance.add_command(cli_cluster_maintenance_on)
|
||||||
cli_cluster_maintenance.add_command(cli_cluster_maintenance_off)
|
cli_cluster_maintenance.add_command(cli_cluster_maintenance_off)
|
||||||
cli_cluster.add_command(cli_cluster_maintenance)
|
cli_cluster.add_command(cli_cluster_maintenance)
|
||||||
|
cli_cluster.add_command(cli_cluster_task)
|
||||||
cli.add_command(cli_cluster)
|
cli.add_command(cli_cluster)
|
||||||
cli_connection.add_command(cli_connection_add)
|
cli_connection.add_command(cli_connection_add)
|
||||||
cli_connection.add_command(cli_connection_remove)
|
cli_connection.add_command(cli_connection_remove)
|
||||||
|
|
|
@ -26,7 +26,6 @@ from requests_toolbelt.multipart.encoder import (
|
||||||
|
|
||||||
import pvc.lib.ansiprint as ansiprint
|
import pvc.lib.ansiprint as ansiprint
|
||||||
from pvc.lib.common import UploadProgressBar, call_api, get_wait_retdata
|
from pvc.lib.common import UploadProgressBar, call_api, get_wait_retdata
|
||||||
from ast import literal_eval
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -720,73 +719,6 @@ def vm_create(config, name, profile, define_flag, start_flag, script_args, wait_
|
||||||
return get_wait_retdata(response, wait_flag)
|
return get_wait_retdata(response, wait_flag)
|
||||||
|
|
||||||
|
|
||||||
def task_status(config, task_id=None, is_watching=False):
|
|
||||||
"""
|
|
||||||
Get information about provisioner job {task_id} or all tasks if None
|
|
||||||
|
|
||||||
API endpoint: GET /api/v1/provisioner/status
|
|
||||||
API arguments:
|
|
||||||
API schema: {json_data_object}
|
|
||||||
"""
|
|
||||||
if task_id is not None:
|
|
||||||
response = call_api(
|
|
||||||
config, "get", "/provisioner/status/{task_id}".format(task_id=task_id)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
response = call_api(config, "get", "/provisioner/status")
|
|
||||||
|
|
||||||
if task_id is not None:
|
|
||||||
if response.status_code == 200:
|
|
||||||
retvalue = True
|
|
||||||
respjson = response.json()
|
|
||||||
if is_watching:
|
|
||||||
# Just return the raw JSON to the watching process instead of including value
|
|
||||||
return respjson
|
|
||||||
else:
|
|
||||||
return retvalue, respjson
|
|
||||||
else:
|
|
||||||
retvalue = False
|
|
||||||
retdata = response.json().get("message", "")
|
|
||||||
else:
|
|
||||||
retvalue = True
|
|
||||||
task_data_raw = response.json()
|
|
||||||
# Format the Celery data into a more useful data structure
|
|
||||||
task_data = list()
|
|
||||||
for task_type in ["active", "reserved", "scheduled"]:
|
|
||||||
try:
|
|
||||||
type_data = task_data_raw[task_type]
|
|
||||||
except Exception:
|
|
||||||
type_data = None
|
|
||||||
|
|
||||||
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")
|
|
||||||
try:
|
|
||||||
task_args = literal_eval(task_job.get("args"))
|
|
||||||
except Exception:
|
|
||||||
task_args = task_job.get("args")
|
|
||||||
task["vm_name"] = task_args[0]
|
|
||||||
task["vm_profile"] = task_args[1]
|
|
||||||
try:
|
|
||||||
task_kwargs = literal_eval(task_job.get("kwargs"))
|
|
||||||
except Exception:
|
|
||||||
task_kwargs = 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
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Format functions
|
# Format functions
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue