Add /compose/queue to get the status of the build queue
This will return a JSON result that includes the waiting builds, and the running builds.
This commit is contained in:
parent
47f21af7fb
commit
520177afca
@ -18,11 +18,13 @@ import logging
|
|||||||
log = logging.getLogger("pylorax")
|
log = logging.getLogger("pylorax")
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from glob import glob
|
||||||
import pytoml as toml
|
import pytoml as toml
|
||||||
import time
|
import time
|
||||||
from pykickstart.version import makeVersion, RHEL7
|
from pykickstart.version import makeVersion, RHEL7
|
||||||
from pykickstart.parser import KickstartParser
|
from pykickstart.parser import KickstartParser
|
||||||
|
|
||||||
|
from pylorax.api.recipes import recipe_from_file
|
||||||
from pylorax.base import DataHolder
|
from pylorax.base import DataHolder
|
||||||
from pylorax.installer import novirt_install
|
from pylorax.installer import novirt_install
|
||||||
from pylorax.sysutils import joinpaths
|
from pylorax.sysutils import joinpaths
|
||||||
@ -109,3 +111,39 @@ def make_compose(cfg, results_dir):
|
|||||||
|
|
||||||
log.debug("repo_url = %s, cfg = %s", repo_url, install_cfg)
|
log.debug("repo_url = %s, cfg = %s", repo_url, install_cfg)
|
||||||
novirt_install(install_cfg, joinpaths(results_dir, install_cfg.image_name), None, repo_url)
|
novirt_install(install_cfg, joinpaths(results_dir, install_cfg.image_name), None, repo_url)
|
||||||
|
|
||||||
|
def compose_detail(results_dir):
|
||||||
|
""" Return details about the build."""
|
||||||
|
|
||||||
|
# Just in case it went away
|
||||||
|
if not os.path.exists(results_dir):
|
||||||
|
return {}
|
||||||
|
|
||||||
|
build_id = os.path.basename(os.path.abspath(results_dir))
|
||||||
|
status = open(joinpaths(results_dir, "STATUS")).read().strip()
|
||||||
|
mtime = os.stat(joinpaths(results_dir, "STATUS")).st_mtime
|
||||||
|
recipe = recipe_from_file(joinpaths(results_dir, "recipe.toml"))
|
||||||
|
|
||||||
|
# Should only be 2 kickstarts, the final-kickstart.ks and the template
|
||||||
|
types = [os.path.basename(ks)[:-3] for ks in glob(joinpaths(results_dir, "*.ks"))
|
||||||
|
if "final-kickstart" not in ks]
|
||||||
|
if len(types) != 1:
|
||||||
|
raise RuntimeError("Cannot find ks template for build %s" % build_id)
|
||||||
|
|
||||||
|
return {"id": build_id,
|
||||||
|
"status": status,
|
||||||
|
"timestamp":mtime,
|
||||||
|
"recipe": recipe["name"],
|
||||||
|
"version": recipe["version"]
|
||||||
|
}
|
||||||
|
|
||||||
|
def queue_status(cfg):
|
||||||
|
""" Return details about what is in the queue."""
|
||||||
|
queue_dir = joinpaths(cfg.get("composer", "lib_dir"), "queue")
|
||||||
|
new_queue = [os.path.realpath(p) for p in glob(joinpaths(queue_dir, "new/*"))]
|
||||||
|
run_queue = [os.path.realpath(p) for p in glob(joinpaths(queue_dir, "run/*"))]
|
||||||
|
|
||||||
|
return {
|
||||||
|
"new": [compose_detail(n) for n in new_queue],
|
||||||
|
"run": [compose_detail(r) for r in run_queue]
|
||||||
|
}
|
||||||
|
@ -611,6 +611,43 @@ POST `/api/v0/recipes/tag/<recipe_name>`
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
`/api/v0/compose/queue`
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
Return the status of the build queue. It includes information about the builds waiting,
|
||||||
|
and the build that is running.
|
||||||
|
|
||||||
|
Example::
|
||||||
|
|
||||||
|
{
|
||||||
|
"new": [
|
||||||
|
{
|
||||||
|
"id": "45502a6d-06e8-48a5-a215-2b4174b3614b",
|
||||||
|
"recipe": "glusterfs",
|
||||||
|
"status": "WAITING",
|
||||||
|
"timestamp": 1517362647.4570868,
|
||||||
|
"version": "0.0.6"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "6d292bd0-bec7-4825-8d7d-41ef9c3e4b73",
|
||||||
|
"recipe": "kubernetes",
|
||||||
|
"status": "WAITING",
|
||||||
|
"timestamp": 1517362659.0034983,
|
||||||
|
"version": "0.0.1"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"run": [
|
||||||
|
{
|
||||||
|
"id": "745712b2-96db-44c0-8014-fe925c35e795",
|
||||||
|
"recipe": "glusterfs",
|
||||||
|
"status": "RUNNING",
|
||||||
|
"timestamp": 1517362633.7965999,
|
||||||
|
"version": "0.0.6"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@ -622,6 +659,7 @@ from pylorax.api.compose import start_build, compose_types
|
|||||||
from pylorax.api.crossdomain import crossdomain
|
from pylorax.api.crossdomain import crossdomain
|
||||||
from pylorax.api.projects import projects_list, projects_info, projects_depsolve
|
from pylorax.api.projects import projects_list, projects_info, projects_depsolve
|
||||||
from pylorax.api.projects import modules_list, modules_info, ProjectsError
|
from pylorax.api.projects import modules_list, modules_info, ProjectsError
|
||||||
|
from pylorax.api.queue import queue_status
|
||||||
from pylorax.api.recipes import list_branch_files, read_recipe_commit, recipe_filename, list_commits
|
from pylorax.api.recipes import list_branch_files, read_recipe_commit, recipe_filename, list_commits
|
||||||
from pylorax.api.recipes import recipe_from_dict, recipe_from_toml, commit_recipe, delete_recipe, revert_recipe
|
from pylorax.api.recipes import recipe_from_dict, recipe_from_toml, commit_recipe, delete_recipe, revert_recipe
|
||||||
from pylorax.api.recipes import tag_recipe_commit, recipe_diff
|
from pylorax.api.recipes import tag_recipe_commit, recipe_diff
|
||||||
@ -1128,3 +1166,9 @@ def v0_api(api):
|
|||||||
"""
|
"""
|
||||||
share_dir = api.config["COMPOSER_CFG"].get("composer", "share_dir")
|
share_dir = api.config["COMPOSER_CFG"].get("composer", "share_dir")
|
||||||
return jsonify(types=[{"name": k, "enabled": True} for k in compose_types(share_dir)])
|
return jsonify(types=[{"name": k, "enabled": True} for k in compose_types(share_dir)])
|
||||||
|
|
||||||
|
@api.route("/api/v0/compose/queue")
|
||||||
|
@crossdomain(origin="*")
|
||||||
|
def v0_compose_queue():
|
||||||
|
"""Return the status of the new and running queues"""
|
||||||
|
return jsonify(queue_status(api.config["COMPOSER_CFG"]))
|
||||||
|
Loading…
Reference in New Issue
Block a user