Port remaining tasks to new task handler
Move the create_vm and run_benchmark tasks to use the new Celery subsystem, handlers, and wait command. Remove the obsolete, dedicated API endpoints. Standardize the CLI client and move the repeated handler code into a separate common function.
This commit is contained in:
@ -202,6 +202,24 @@ def call_api(
|
||||
return response
|
||||
|
||||
|
||||
def get_wait_retdata(response, wait_flag):
|
||||
if response.status_code == 202:
|
||||
retvalue = True
|
||||
retjson = response.json()
|
||||
if not wait_flag:
|
||||
retdata = (
|
||||
f"Task ID: {retjson['task_id']} assigned to node {retjson['run_on']}"
|
||||
)
|
||||
else:
|
||||
# Just return the task JSON without formatting
|
||||
retdata = response.json()
|
||||
else:
|
||||
retvalue = False
|
||||
retdata = response.json().get("message", "")
|
||||
|
||||
return retvalue, retdata
|
||||
|
||||
|
||||
def task_status(config, task_id=None, is_watching=False):
|
||||
"""
|
||||
Get information about Celery job {task_id}, or all tasks if None
|
||||
|
@ -25,7 +25,7 @@ from requests_toolbelt.multipart.encoder import (
|
||||
)
|
||||
|
||||
import pvc.lib.ansiprint as ansiprint
|
||||
from pvc.lib.common import UploadProgressBar, call_api
|
||||
from pvc.lib.common import UploadProgressBar, call_api, get_wait_retdata
|
||||
from ast import literal_eval
|
||||
|
||||
|
||||
@ -700,7 +700,7 @@ def profile_remove(config, name):
|
||||
return retvalue, response.json().get("message", "")
|
||||
|
||||
|
||||
def vm_create(config, name, profile, wait_flag, define_flag, start_flag, script_args):
|
||||
def vm_create(config, name, profile, define_flag, start_flag, script_args, wait_flag):
|
||||
"""
|
||||
Create a new VM named {name} with profile {profile}
|
||||
|
||||
@ -717,18 +717,7 @@ def vm_create(config, name, profile, wait_flag, define_flag, start_flag, script_
|
||||
}
|
||||
response = call_api(config, "post", "/provisioner/create", params=params)
|
||||
|
||||
if response.status_code == 202:
|
||||
retvalue = True
|
||||
if not wait_flag:
|
||||
retdata = "Task ID: {}".format(response.json()["task_id"])
|
||||
else:
|
||||
# Just return the task_id raw, instead of formatting it
|
||||
retdata = response.json()["task_id"]
|
||||
else:
|
||||
retvalue = False
|
||||
retdata = response.json().get("message", "")
|
||||
|
||||
return retvalue, retdata
|
||||
return get_wait_retdata(response, wait_flag)
|
||||
|
||||
|
||||
def task_status(config, task_id=None, is_watching=False):
|
||||
|
@ -29,7 +29,7 @@ from requests_toolbelt.multipart.encoder import (
|
||||
)
|
||||
|
||||
import pvc.lib.ansiprint as ansiprint
|
||||
from pvc.lib.common import UploadProgressBar, call_api
|
||||
from pvc.lib.common import UploadProgressBar, call_api, get_wait_retdata
|
||||
|
||||
#
|
||||
# Supplemental functions
|
||||
@ -175,21 +175,7 @@ def ceph_osd_db_vg_add(config, node, device, wait_flag):
|
||||
params = {"node": node, "device": device}
|
||||
response = call_api(config, "post", "/storage/ceph/osddb", params=params)
|
||||
|
||||
if response.status_code == 202:
|
||||
retvalue = True
|
||||
retjson = response.json()
|
||||
if not wait_flag:
|
||||
retdata = (
|
||||
f"Task ID: {retjson['task_id']} assigned to node {retjson['run_on']}"
|
||||
)
|
||||
else:
|
||||
# Just return the task JSON without formatting
|
||||
retdata = response.json()
|
||||
else:
|
||||
retvalue = False
|
||||
retdata = response.json().get("message", "")
|
||||
|
||||
return retvalue, retdata
|
||||
return get_wait_retdata(response, wait_flag)
|
||||
|
||||
|
||||
#
|
||||
@ -265,21 +251,7 @@ def ceph_osd_add(
|
||||
|
||||
response = call_api(config, "post", "/storage/ceph/osd", params=params)
|
||||
|
||||
if response.status_code == 202:
|
||||
retvalue = True
|
||||
retjson = response.json()
|
||||
if not wait_flag:
|
||||
retdata = (
|
||||
f"Task ID: {retjson['task_id']} assigned to node {retjson['run_on']}"
|
||||
)
|
||||
else:
|
||||
# Just return the task JSON without formatting
|
||||
retdata = response.json()
|
||||
else:
|
||||
retvalue = False
|
||||
retdata = response.json().get("message", "")
|
||||
|
||||
return retvalue, retdata
|
||||
return get_wait_retdata(response, wait_flag)
|
||||
|
||||
|
||||
def ceph_osd_replace(
|
||||
@ -308,21 +280,7 @@ def ceph_osd_replace(
|
||||
|
||||
response = call_api(config, "post", f"/storage/ceph/osd/{osdid}", params=params)
|
||||
|
||||
if response.status_code == 202:
|
||||
retvalue = True
|
||||
retjson = response.json()
|
||||
if not wait_flag:
|
||||
retdata = (
|
||||
f"Task ID: {retjson['task_id']} assigned to node {retjson['run_on']}"
|
||||
)
|
||||
else:
|
||||
# Just return the task JSON without formatting
|
||||
retdata = response.json()
|
||||
else:
|
||||
retvalue = False
|
||||
retdata = response.json().get("message", "")
|
||||
|
||||
return retvalue, retdata
|
||||
return get_wait_retdata(response, wait_flag)
|
||||
|
||||
|
||||
def ceph_osd_refresh(config, osdid, device, wait_flag):
|
||||
@ -338,21 +296,7 @@ def ceph_osd_refresh(config, osdid, device, wait_flag):
|
||||
}
|
||||
response = call_api(config, "put", f"/storage/ceph/osd/{osdid}", params=params)
|
||||
|
||||
if response.status_code == 202:
|
||||
retvalue = True
|
||||
retjson = response.json()
|
||||
if not wait_flag:
|
||||
retdata = (
|
||||
f"Task ID: {retjson['task_id']} assigned to node {retjson['run_on']}"
|
||||
)
|
||||
else:
|
||||
# Just return the task JSON without formatting
|
||||
retdata = response.json()
|
||||
else:
|
||||
retvalue = False
|
||||
retdata = response.json().get("message", "")
|
||||
|
||||
return retvalue, retdata
|
||||
return get_wait_retdata(response, wait_flag)
|
||||
|
||||
|
||||
def ceph_osd_remove(config, osdid, force_flag, wait_flag):
|
||||
@ -368,21 +312,7 @@ def ceph_osd_remove(config, osdid, force_flag, wait_flag):
|
||||
config, "delete", "/storage/ceph/osd/{osdid}".format(osdid=osdid), params=params
|
||||
)
|
||||
|
||||
if response.status_code == 202:
|
||||
retvalue = True
|
||||
retjson = response.json()
|
||||
if not wait_flag:
|
||||
retdata = (
|
||||
f"Task ID: {retjson['task_id']} assigned to node {retjson['run_on']}"
|
||||
)
|
||||
else:
|
||||
# Just return the task JSON without formatting
|
||||
retdata = response.json()
|
||||
else:
|
||||
retvalue = False
|
||||
retdata = response.json().get("message", "")
|
||||
|
||||
return retvalue, retdata
|
||||
return get_wait_retdata(response, wait_flag)
|
||||
|
||||
|
||||
def ceph_osd_state(config, osdid, state):
|
||||
@ -1765,7 +1695,7 @@ def format_list_snapshot(config, snapshot_list):
|
||||
#
|
||||
# Benchmark functions
|
||||
#
|
||||
def ceph_benchmark_run(config, pool):
|
||||
def ceph_benchmark_run(config, pool, wait_flag):
|
||||
"""
|
||||
Run a storage benchmark against {pool}
|
||||
|
||||
@ -1776,14 +1706,7 @@ def ceph_benchmark_run(config, pool):
|
||||
params = {"pool": pool}
|
||||
response = call_api(config, "post", "/storage/ceph/benchmark", params=params)
|
||||
|
||||
if response.status_code == 202:
|
||||
retvalue = True
|
||||
retdata = "Task ID: {}".format(response.json()["task_id"])
|
||||
else:
|
||||
retvalue = False
|
||||
retdata = response.json().get("message", "")
|
||||
|
||||
return retvalue, retdata
|
||||
return get_wait_retdata(response, wait_flag)
|
||||
|
||||
|
||||
def ceph_benchmark_list(config, job):
|
||||
|
@ -23,7 +23,7 @@ import time
|
||||
import re
|
||||
|
||||
import pvc.lib.ansiprint as ansiprint
|
||||
from pvc.lib.common import call_api, format_bytes, format_metric
|
||||
from pvc.lib.common import call_api, format_bytes, format_metric, get_wait_retdata
|
||||
|
||||
|
||||
#
|
||||
@ -425,21 +425,7 @@ def vm_locks(config, vm, wait_flag):
|
||||
"""
|
||||
response = call_api(config, "post", f"/vm/{vm}/locks")
|
||||
|
||||
if response.status_code == 202:
|
||||
retvalue = True
|
||||
retjson = response.json()
|
||||
if not wait_flag:
|
||||
retdata = (
|
||||
f"Task ID: {retjson['task_id']} assigned to node {retjson['run_on']}"
|
||||
)
|
||||
else:
|
||||
# Just return the task JSON without formatting
|
||||
retdata = response.json()
|
||||
else:
|
||||
retvalue = False
|
||||
retdata = response.json().get("message", "")
|
||||
|
||||
return retvalue, retdata
|
||||
return get_wait_retdata(response, wait_flag)
|
||||
|
||||
|
||||
def vm_backup(config, vm, backup_path, incremental_parent=None, retain_snapshot=False):
|
||||
|
Reference in New Issue
Block a user