1672 lines
190 KiB
HTML
1672 lines
190 KiB
HTML
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<title>pylorax.api.v0 — Lorax 19.7.10 documentation</title>
|
|
|
|
<link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
|
|
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
|
|
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT: '../../../',
|
|
VERSION: '19.7.10',
|
|
COLLAPSE_INDEX: false,
|
|
FILE_SUFFIX: '.html',
|
|
HAS_SOURCE: true
|
|
};
|
|
</script>
|
|
<script type="text/javascript" src="../../../_static/jquery.js"></script>
|
|
<script type="text/javascript" src="../../../_static/underscore.js"></script>
|
|
<script type="text/javascript" src="../../../_static/doctools.js"></script>
|
|
<link rel="top" title="Lorax 19.7.10 documentation" href="../../../index.html" />
|
|
<link rel="up" title="pylorax.api" href="../api.html" />
|
|
</head>
|
|
<body>
|
|
<div class="related">
|
|
<h3>Navigation</h3>
|
|
<ul>
|
|
<li class="right" style="margin-right: 10px">
|
|
<a href="../../../genindex.html" title="General Index"
|
|
accesskey="I">index</a></li>
|
|
<li class="right" >
|
|
<a href="../../../py-modindex.html" title="Python Module Index"
|
|
>modules</a> |</li>
|
|
<li><a href="../../../index.html">Lorax 19.7.10 documentation</a> »</li>
|
|
<li><a href="../../index.html" >Module code</a> »</li>
|
|
<li><a href="../api.html" accesskey="U">pylorax.api</a> »</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
<div class="body">
|
|
|
|
<h1>Source code for pylorax.api.v0</h1><div class="highlight"><pre>
|
|
<span class="c">#</span>
|
|
<span class="c"># Copyright (C) 2017-2018 Red Hat, Inc.</span>
|
|
<span class="c">#</span>
|
|
<span class="c"># This program is free software; you can redistribute it and/or modify</span>
|
|
<span class="c"># it under the terms of the GNU General Public License as published by</span>
|
|
<span class="c"># the Free Software Foundation; either version 2 of the License, or</span>
|
|
<span class="c"># (at your option) any later version.</span>
|
|
<span class="c">#</span>
|
|
<span class="c"># This program is distributed in the hope that it will be useful,</span>
|
|
<span class="c"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
|
|
<span class="c"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
|
|
<span class="c"># GNU General Public License for more details.</span>
|
|
<span class="c">#</span>
|
|
<span class="c"># You should have received a copy of the GNU General Public License</span>
|
|
<span class="c"># along with this program. If not, see <http://www.gnu.org/licenses/>.</span>
|
|
<span class="c">#</span>
|
|
<span class="sd">""" Setup v0 of the API server</span>
|
|
|
|
<span class="sd">v0_api() must be called to setup the API routes for Flask</span>
|
|
|
|
<span class="sd">Status Responses</span>
|
|
<span class="sd">----------------</span>
|
|
|
|
<span class="sd">Some requests only return a status/error response.</span>
|
|
|
|
<span class="sd"> The response will be a status response with `status` set to true, or an</span>
|
|
<span class="sd"> error response with it set to false and an error message included.</span>
|
|
|
|
<span class="sd"> Example response::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "status": true</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd"> Error response::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "error": {</span>
|
|
<span class="sd"> "msg": "ggit-error: Failed to remove entry. File isn't in the tree - jboss.toml (-1)"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> "status": false</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">API Routes</span>
|
|
<span class="sd">----------</span>
|
|
|
|
<span class="sd">All of the recipes routes support the optional `branch` argument. If it is not</span>
|
|
<span class="sd">used then the API will use the `master` branch for recipes. If you want to create</span>
|
|
<span class="sd">a new branch use the `new` or `workspace` routes with ?branch=<branch-name> to</span>
|
|
<span class="sd">store the new recipe on the new branch.</span>
|
|
|
|
<span class="sd">`/api/v0/test`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Return a test string. It is not JSON encoded.</span>
|
|
|
|
<span class="sd">`/api/v0/status`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^</span>
|
|
<span class="sd"> Return the status of the API Server::</span>
|
|
|
|
<span class="sd"> { "api": "0",</span>
|
|
<span class="sd"> "build": "devel",</span>
|
|
<span class="sd"> "db_supported": false,</span>
|
|
<span class="sd"> "db_version": "0",</span>
|
|
<span class="sd"> "schema_version": "0" }</span>
|
|
|
|
<span class="sd">`/api/v0/recipes/list`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> List the available recipes::</span>
|
|
|
|
<span class="sd"> { "limit": 20,</span>
|
|
<span class="sd"> "offset": 0,</span>
|
|
<span class="sd"> "recipes": [</span>
|
|
<span class="sd"> "atlas",</span>
|
|
<span class="sd"> "development",</span>
|
|
<span class="sd"> "glusterfs",</span>
|
|
<span class="sd"> "http-server",</span>
|
|
<span class="sd"> "jboss",</span>
|
|
<span class="sd"> "kubernetes" ],</span>
|
|
<span class="sd"> "total": 6 }</span>
|
|
|
|
<span class="sd">`/api/v0/recipes/info/<recipe_names>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Return the JSON representation of the recipe. This includes 3 top level</span>
|
|
<span class="sd"> objects. `changes` which lists whether or not the workspace is different from</span>
|
|
<span class="sd"> the most recent commit. `recipes` which lists the JSON representation of the</span>
|
|
<span class="sd"> recipe, and `errors` which will list any errors, like non-existant recipes.</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "changes": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "changed": false,</span>
|
|
<span class="sd"> "name": "glusterfs"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ],</span>
|
|
<span class="sd"> "errors": [],</span>
|
|
<span class="sd"> "recipes": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "description": "An example GlusterFS server with samba",</span>
|
|
<span class="sd"> "modules": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "name": "glusterfs",</span>
|
|
<span class="sd"> "version": "3.7.*"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "name": "glusterfs-cli",</span>
|
|
<span class="sd"> "version": "3.7.*"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ],</span>
|
|
<span class="sd"> "name": "glusterfs",</span>
|
|
<span class="sd"> "packages": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "name": "2ping",</span>
|
|
<span class="sd"> "version": "3.2.1"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "name": "samba",</span>
|
|
<span class="sd"> "version": "4.2.*"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ],</span>
|
|
<span class="sd"> "version": "0.0.6"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ]</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd"> Error example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "changes": [],</span>
|
|
<span class="sd"> "errors": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "msg": "ggit-error: the path 'missing.toml' does not exist in the given tree (-3)",</span>
|
|
<span class="sd"> "recipe": "missing"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ],</span>
|
|
<span class="sd"> "recipes": []</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">`/api/v0/recipes/changes/<recipe_names>[?offset=0&limit=20]`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Return the commits to a recipe. By default it returns the first 20 commits, this</span>
|
|
<span class="sd"> can be changed by passing `offset` and/or `limit`. The response will include the</span>
|
|
<span class="sd"> commit hash, summary, timestamp, and optionally the revision number. The commit</span>
|
|
<span class="sd"> hash can be passed to `/api/v0/recipes/diff/` to retrieve the exact changes.</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "errors": [],</span>
|
|
<span class="sd"> "limit": 20,</span>
|
|
<span class="sd"> "offset": 0,</span>
|
|
<span class="sd"> "recipes": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "changes": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "commit": "e083921a7ed1cf2eec91ad12b9ad1e70ef3470be",</span>
|
|
<span class="sd"> "message": "Recipe glusterfs, version 0.0.6 saved.",</span>
|
|
<span class="sd"> "revision": null,</span>
|
|
<span class="sd"> "timestamp": "2017-11-23T00:18:13Z"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "commit": "cee5f4c20fc33ea4d54bfecf56f4ad41ad15f4f3",</span>
|
|
<span class="sd"> "message": "Recipe glusterfs, version 0.0.5 saved.",</span>
|
|
<span class="sd"> "revision": null,</span>
|
|
<span class="sd"> "timestamp": "2017-11-11T01:00:28Z"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "commit": "29b492f26ed35d80800b536623bafc51e2f0eff2",</span>
|
|
<span class="sd"> "message": "Recipe glusterfs, version 0.0.4 saved.",</span>
|
|
<span class="sd"> "revision": null,</span>
|
|
<span class="sd"> "timestamp": "2017-11-11T00:28:30Z"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "commit": "03374adbf080fe34f5c6c29f2e49cc2b86958bf2",</span>
|
|
<span class="sd"> "message": "Recipe glusterfs, version 0.0.3 saved.",</span>
|
|
<span class="sd"> "revision": null,</span>
|
|
<span class="sd"> "timestamp": "2017-11-10T23:15:52Z"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "commit": "0e08ecbb708675bfabc82952599a1712a843779d",</span>
|
|
<span class="sd"> "message": "Recipe glusterfs, version 0.0.2 saved.",</span>
|
|
<span class="sd"> "revision": null,</span>
|
|
<span class="sd"> "timestamp": "2017-11-10T23:14:56Z"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "commit": "3e11eb87a63d289662cba4b1804a0947a6843379",</span>
|
|
<span class="sd"> "message": "Recipe glusterfs, version 0.0.1 saved.",</span>
|
|
<span class="sd"> "revision": null,</span>
|
|
<span class="sd"> "timestamp": "2017-11-08T00:02:47Z"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ],</span>
|
|
<span class="sd"> "name": "glusterfs",</span>
|
|
<span class="sd"> "total": 6</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ]</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">POST `/api/v0/recipes/new`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Create a new recipe, or update an existing recipe. This supports both JSON and TOML</span>
|
|
<span class="sd"> for the recipe format. The recipe should be in the body of the request with the</span>
|
|
<span class="sd"> `Content-Type` header set to either `application/json` or `text/x-toml`.</span>
|
|
|
|
<span class="sd"> The response will be a status response with `status` set to true, or an</span>
|
|
<span class="sd"> error response with it set to false and an error message included.</span>
|
|
|
|
<span class="sd">DELETE `/api/v0/recipes/delete/<recipe_name>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Delete a recipe. The recipe is deleted from the branch, and will no longer</span>
|
|
<span class="sd"> be listed by the `list` route. A recipe can be undeleted using the `undo` route</span>
|
|
<span class="sd"> to revert to a previous commit.</span>
|
|
|
|
<span class="sd"> The response will be a status response with `status` set to true, or an</span>
|
|
<span class="sd"> error response with it set to false and an error message included.</span>
|
|
|
|
<span class="sd">POST `/api/v0/recipes/workspace`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Write a recipe to the temporary workspace. This works exactly the same as `new` except</span>
|
|
<span class="sd"> that it does not create a commit. JSON and TOML bodies are supported.</span>
|
|
|
|
<span class="sd"> The workspace is meant to be used as a temporary recipe storage for clients.</span>
|
|
<span class="sd"> It will be read by the `info` and `diff` routes if it is different from the</span>
|
|
<span class="sd"> most recent commit.</span>
|
|
|
|
<span class="sd"> The response will be a status response with `status` set to true, or an</span>
|
|
<span class="sd"> error response with it set to false and an error message included.</span>
|
|
|
|
<span class="sd">DELETE `/api/v0/recipes/workspace/<recipe_name>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Remove the temporary workspace copy of a recipe. The `info` route will now</span>
|
|
<span class="sd"> return the most recent commit of the recipe. Any changes that were in the</span>
|
|
<span class="sd"> workspace will be lost.</span>
|
|
|
|
<span class="sd"> The response will be a status response with `status` set to true, or an</span>
|
|
<span class="sd"> error response with it set to false and an error message included.</span>
|
|
|
|
<span class="sd">POST `/api/v0/recipes/undo/<recipe_name>/<commit>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> This will revert the recipe to a previous commit. The commit hash from the `changes`</span>
|
|
<span class="sd"> route can be used in this request.</span>
|
|
|
|
<span class="sd"> The response will be a status response with `status` set to true, or an</span>
|
|
<span class="sd"> error response with it set to false and an error message included.</span>
|
|
|
|
<span class="sd">POST `/api/v0/recipes/tag/<recipe_name>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Tag a recipe as a new release. This uses git tags with a special format.</span>
|
|
<span class="sd"> `refs/tags/<branch>/<filename>/r<revision>`. Only the most recent recipe commit</span>
|
|
<span class="sd"> can be tagged. Revisions start at 1 and increment for each new tag</span>
|
|
<span class="sd"> (per-recipe). If the commit has already been tagged it will return false.</span>
|
|
|
|
<span class="sd"> The response will be a status response with `status` set to true, or an</span>
|
|
<span class="sd"> error response with it set to false and an error message included.</span>
|
|
|
|
<span class="sd">`/api/v0/recipes/diff/<recipe_name>/<from_commit>/<to_commit>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Return the differences between two commits, or the workspace. The commit hash</span>
|
|
<span class="sd"> from the `changes` response can be used here, or several special strings:</span>
|
|
|
|
<span class="sd"> - NEWEST will select the newest git commit. This works for `from_commit` or `to_commit`</span>
|
|
<span class="sd"> - WORKSPACE will select the workspace copy. This can only be used in `to_commit`</span>
|
|
|
|
<span class="sd"> eg. `/api/v0/recipes/diff/glusterfs/NEWEST/WORKSPACE` will return the differences</span>
|
|
<span class="sd"> between the most recent git commit and the contents of the workspace.</span>
|
|
|
|
<span class="sd"> Each entry in the response's diff object contains the old recipe value and the new one.</span>
|
|
<span class="sd"> If old is null and new is set, then it was added.</span>
|
|
<span class="sd"> If new is null and old is set, then it was removed.</span>
|
|
<span class="sd"> If both are set, then it was changed.</span>
|
|
|
|
<span class="sd"> The old/new entries will have the name of the recipe field that was changed. This</span>
|
|
<span class="sd"> can be one of: Name, Description, Version, Module, or Package.</span>
|
|
<span class="sd"> The contents for these will be the old/new values for them.</span>
|
|
|
|
<span class="sd"> In the example below the version was changed and the ping package was added.</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "diff": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "new": {</span>
|
|
<span class="sd"> "Version": "0.0.6"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> "old": {</span>
|
|
<span class="sd"> "Version": "0.0.5"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "new": {</span>
|
|
<span class="sd"> "Package": {</span>
|
|
<span class="sd"> "name": "ping",</span>
|
|
<span class="sd"> "version": "3.2.1"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> "old": null</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ]</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">`/api/v0/recipes/freeze/<recipe_names>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Return a JSON representation of the recipe with the package and module versions set</span>
|
|
<span class="sd"> to the exact versions chosen by depsolving the recipe.</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "errors": [],</span>
|
|
<span class="sd"> "recipes": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "recipe": {</span>
|
|
<span class="sd"> "description": "An example GlusterFS server with samba",</span>
|
|
<span class="sd"> "modules": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "name": "glusterfs",</span>
|
|
<span class="sd"> "version": "3.8.4-18.4.el7.x86_64"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "name": "glusterfs-cli",</span>
|
|
<span class="sd"> "version": "3.8.4-18.4.el7.x86_64"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ],</span>
|
|
<span class="sd"> "name": "glusterfs",</span>
|
|
<span class="sd"> "packages": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "name": "ping",</span>
|
|
<span class="sd"> "version": "2:3.2.1-2.el7.noarch"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "name": "samba",</span>
|
|
<span class="sd"> "version": "4.6.2-8.el7.x86_64"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ],</span>
|
|
<span class="sd"> "version": "0.0.6"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ]</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">`/api/v0/recipes/depsolve/<recipe_names>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Depsolve the recipe using yum, return the recipe used, and the NEVRAs of the packages</span>
|
|
<span class="sd"> chosen to satisfy the recipe's requirements. The response will include a list of results,</span>
|
|
<span class="sd"> with the full dependency list in `dependencies`, the NEVRAs for the recipe's direct modules</span>
|
|
<span class="sd"> and packages in `modules`, and any error will be in `errors`.</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "errors": [],</span>
|
|
<span class="sd"> "recipes": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "dependencies": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "arch": "noarch",</span>
|
|
<span class="sd"> "epoch": "0",</span>
|
|
<span class="sd"> "name": "2ping",</span>
|
|
<span class="sd"> "release": "2.el7",</span>
|
|
<span class="sd"> "version": "3.2.1"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "arch": "x86_64",</span>
|
|
<span class="sd"> "epoch": "0",</span>
|
|
<span class="sd"> "name": "acl",</span>
|
|
<span class="sd"> "release": "12.el7",</span>
|
|
<span class="sd"> "version": "2.2.51"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "arch": "x86_64",</span>
|
|
<span class="sd"> "epoch": "0",</span>
|
|
<span class="sd"> "name": "audit-libs",</span>
|
|
<span class="sd"> "release": "3.el7",</span>
|
|
<span class="sd"> "version": "2.7.6"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "arch": "x86_64",</span>
|
|
<span class="sd"> "epoch": "0",</span>
|
|
<span class="sd"> "name": "avahi-libs",</span>
|
|
<span class="sd"> "release": "17.el7",</span>
|
|
<span class="sd"> "version": "0.6.31"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> ...</span>
|
|
<span class="sd"> ],</span>
|
|
<span class="sd"> "modules": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "arch": "noarch",</span>
|
|
<span class="sd"> "epoch": "0",</span>
|
|
<span class="sd"> "name": "2ping",</span>
|
|
<span class="sd"> "release": "2.el7",</span>
|
|
<span class="sd"> "version": "3.2.1"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "arch": "x86_64",</span>
|
|
<span class="sd"> "epoch": "0",</span>
|
|
<span class="sd"> "name": "glusterfs",</span>
|
|
<span class="sd"> "release": "18.4.el7",</span>
|
|
<span class="sd"> "version": "3.8.4"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> ...</span>
|
|
<span class="sd"> ],</span>
|
|
<span class="sd"> "recipe": {</span>
|
|
<span class="sd"> "description": "An example GlusterFS server with samba",</span>
|
|
<span class="sd"> "modules": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "name": "glusterfs",</span>
|
|
<span class="sd"> "version": "3.7.*"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> ...</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ]</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">`/api/v0/projects/list[?offset=0&limit=20]`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> List all of the available projects. By default this returns the first 20 items,</span>
|
|
<span class="sd"> but this can be changed by setting the `offset` and `limit` arguments.</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "limit": 20,</span>
|
|
<span class="sd"> "offset": 0,</span>
|
|
<span class="sd"> "projects": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "description": "0 A.D. (pronounced \"zero ey-dee\") is a ...",</span>
|
|
<span class="sd"> "homepage": "http://play0ad.com",</span>
|
|
<span class="sd"> "name": "0ad",</span>
|
|
<span class="sd"> "summary": "Cross-Platform RTS Game of Ancient Warfare",</span>
|
|
<span class="sd"> "upstream_vcs": "UPSTREAM_VCS"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> ...</span>
|
|
<span class="sd"> ],</span>
|
|
<span class="sd"> "total": 21770</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">`/api/v0/projects/info/<project_names>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Return information about the comma-separated list of projects. It includes the description</span>
|
|
<span class="sd"> of the package along with the list of available builds.</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "projects": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "builds": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "arch": "x86_64",</span>
|
|
<span class="sd"> "build_config_ref": "BUILD_CONFIG_REF",</span>
|
|
<span class="sd"> "build_env_ref": "BUILD_ENV_REF",</span>
|
|
<span class="sd"> "build_time": "2017-03-01T08:39:23",</span>
|
|
<span class="sd"> "changelog": "- restore incremental backups correctly, files ...",</span>
|
|
<span class="sd"> "epoch": "2",</span>
|
|
<span class="sd"> "metadata": {},</span>
|
|
<span class="sd"> "release": "32.el7",</span>
|
|
<span class="sd"> "source": {</span>
|
|
<span class="sd"> "license": "GPLv3+",</span>
|
|
<span class="sd"> "metadata": {},</span>
|
|
<span class="sd"> "source_ref": "SOURCE_REF",</span>
|
|
<span class="sd"> "version": "1.26"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ],</span>
|
|
<span class="sd"> "description": "The GNU tar program saves many ...",</span>
|
|
<span class="sd"> "homepage": "http://www.gnu.org/software/tar/",</span>
|
|
<span class="sd"> "name": "tar",</span>
|
|
<span class="sd"> "summary": "A GNU file archiving program",</span>
|
|
<span class="sd"> "upstream_vcs": "UPSTREAM_VCS"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ]</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">`/api/v0/projects/depsolve/<project_names>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Depsolve the comma-separated list of projects and return the list of NEVRAs needed</span>
|
|
<span class="sd"> to satisfy the request.</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "projects": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "arch": "noarch",</span>
|
|
<span class="sd"> "epoch": "0",</span>
|
|
<span class="sd"> "name": "basesystem",</span>
|
|
<span class="sd"> "release": "7.el7",</span>
|
|
<span class="sd"> "version": "10.0"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "arch": "x86_64",</span>
|
|
<span class="sd"> "epoch": "0",</span>
|
|
<span class="sd"> "name": "bash",</span>
|
|
<span class="sd"> "release": "28.el7",</span>
|
|
<span class="sd"> "version": "4.2.46"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "arch": "x86_64",</span>
|
|
<span class="sd"> "epoch": "0",</span>
|
|
<span class="sd"> "name": "filesystem",</span>
|
|
<span class="sd"> "release": "21.el7",</span>
|
|
<span class="sd"> "version": "3.2"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> ...</span>
|
|
<span class="sd"> ]</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">`/api/v0/modules/list[?offset=0&limit=20]`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Return a list of all of the available modules. This includes the name and the</span>
|
|
<span class="sd"> group_type, which is always "rpm" for lorax-composer. By default this returns</span>
|
|
<span class="sd"> the first 20 items. This can be changed by setting the `offset` and `limit`</span>
|
|
<span class="sd"> arguments.</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "limit": 20,</span>
|
|
<span class="sd"> "modules": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "group_type": "rpm",</span>
|
|
<span class="sd"> "name": "0ad"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "group_type": "rpm",</span>
|
|
<span class="sd"> "name": "0ad-data"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "group_type": "rpm",</span>
|
|
<span class="sd"> "name": "0install"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "group_type": "rpm",</span>
|
|
<span class="sd"> "name": "2048-cli"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> ...</span>
|
|
<span class="sd"> ]</span>
|
|
<span class="sd"> "total": 21770</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">`/api/v0/modules/list/<module_names>[?offset=0&limit=20]`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Return the list of comma-separated modules. Output is the same as `/modules/list`</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "limit": 20,</span>
|
|
<span class="sd"> "modules": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "group_type": "rpm",</span>
|
|
<span class="sd"> "name": "tar"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ],</span>
|
|
<span class="sd"> "offset": 0,</span>
|
|
<span class="sd"> "total": 1</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">`/api/v0/modules/info/<module_names>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Return the module's dependencies, and the information about the module.</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "modules": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "dependencies": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "arch": "noarch",</span>
|
|
<span class="sd"> "epoch": "0",</span>
|
|
<span class="sd"> "name": "basesystem",</span>
|
|
<span class="sd"> "release": "7.el7",</span>
|
|
<span class="sd"> "version": "10.0"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "arch": "x86_64",</span>
|
|
<span class="sd"> "epoch": "0",</span>
|
|
<span class="sd"> "name": "bash",</span>
|
|
<span class="sd"> "release": "28.el7",</span>
|
|
<span class="sd"> "version": "4.2.46"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> ...</span>
|
|
<span class="sd"> ],</span>
|
|
<span class="sd"> "description": "The GNU tar program saves ...",</span>
|
|
<span class="sd"> "homepage": "http://www.gnu.org/software/tar/",</span>
|
|
<span class="sd"> "name": "tar",</span>
|
|
<span class="sd"> "summary": "A GNU file archiving program",</span>
|
|
<span class="sd"> "upstream_vcs": "UPSTREAM_VCS"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ]</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">POST `/api/v0/compose`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Start a compose. The content type should be 'application/json' and the body of the POST</span>
|
|
<span class="sd"> should look like this::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "recipe_name": "http-server",</span>
|
|
<span class="sd"> "compose_type": "tar",</span>
|
|
<span class="sd"> "branch": "master"</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd"> Pass it the name of the recipe, the type of output (from '/api/v0/compose/types'), and the</span>
|
|
<span class="sd"> recipe branch to use. 'branch' is optional and will default to master. It will create a new</span>
|
|
<span class="sd"> build and add it to the queue. It returns the build uuid and a status if it succeeds::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "build_id": "e6fa6db4-9c81-4b70-870f-a697ca405cdf",</span>
|
|
<span class="sd"> "status": true</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">`/api/v0/compose/types`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Returns the list of supported output types that are valid for use with 'POST /api/v0/compose'</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "types": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "enabled": true,</span>
|
|
<span class="sd"> "name": "tar"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ]</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">`/api/v0/compose/queue`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Return the status of the build queue. It includes information about the builds waiting,</span>
|
|
<span class="sd"> and the build that is running.</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "new": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "id": "45502a6d-06e8-48a5-a215-2b4174b3614b",</span>
|
|
<span class="sd"> "recipe": "glusterfs",</span>
|
|
<span class="sd"> "queue_status": "WAITING",</span>
|
|
<span class="sd"> "timestamp": 1517362647.4570868,</span>
|
|
<span class="sd"> "version": "0.0.6"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "id": "6d292bd0-bec7-4825-8d7d-41ef9c3e4b73",</span>
|
|
<span class="sd"> "recipe": "kubernetes",</span>
|
|
<span class="sd"> "queue_status": "WAITING",</span>
|
|
<span class="sd"> "timestamp": 1517362659.0034983,</span>
|
|
<span class="sd"> "version": "0.0.1"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ],</span>
|
|
<span class="sd"> "run": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "id": "745712b2-96db-44c0-8014-fe925c35e795",</span>
|
|
<span class="sd"> "recipe": "glusterfs",</span>
|
|
<span class="sd"> "queue_status": "RUNNING",</span>
|
|
<span class="sd"> "timestamp": 1517362633.7965999,</span>
|
|
<span class="sd"> "version": "0.0.6"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ]</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">`/api/v0/compose/finished`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Return the details on all of the finished composes on the system.</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "finished": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "id": "70b84195-9817-4b8a-af92-45e380f39894",</span>
|
|
<span class="sd"> "recipe": "glusterfs",</span>
|
|
<span class="sd"> "queue_status": "FINISHED",</span>
|
|
<span class="sd"> "timestamp": 1517351003.8210032,</span>
|
|
<span class="sd"> "version": "0.0.6"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "id": "e695affd-397f-4af9-9022-add2636e7459",</span>
|
|
<span class="sd"> "recipe": "glusterfs",</span>
|
|
<span class="sd"> "queue_status": "FINISHED",</span>
|
|
<span class="sd"> "timestamp": 1517362289.7193348,</span>
|
|
<span class="sd"> "version": "0.0.6"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ]</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">`/api/v0/compose/failed`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Return the details on all of the failed composes on the system.</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "failed": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "id": "8c8435ef-d6bd-4c68-9bf1-a2ef832e6b1a",</span>
|
|
<span class="sd"> "recipe": "http-server",</span>
|
|
<span class="sd"> "queue_status": "FAILED",</span>
|
|
<span class="sd"> "timestamp": 1517523249.9301329,</span>
|
|
<span class="sd"> "version": "0.0.2"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ]</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">`/api/v0/compose/status/<uuids>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Return the details for each of the comma-separated list of uuids.</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "uuids": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "id": "8c8435ef-d6bd-4c68-9bf1-a2ef832e6b1a",</span>
|
|
<span class="sd"> "recipe": "http-server",</span>
|
|
<span class="sd"> "queue_status": "FINISHED",</span>
|
|
<span class="sd"> "timestamp": 1517523644.2384307,</span>
|
|
<span class="sd"> "version": "0.0.2"</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "id": "45502a6d-06e8-48a5-a215-2b4174b3614b",</span>
|
|
<span class="sd"> "recipe": "glusterfs",</span>
|
|
<span class="sd"> "queue_status": "FINISHED",</span>
|
|
<span class="sd"> "timestamp": 1517363442.188399,</span>
|
|
<span class="sd"> "version": "0.0.6"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ]</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">DELETE `/api/v0/recipes/cancel/<uuid>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Cancel the build, if it is not finished, and delete the results. It will return a</span>
|
|
<span class="sd"> status of True if it is successful.</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "status": true,</span>
|
|
<span class="sd"> "uuid": "03397f8d-acff-4cdb-bd31-f629b7a948f5"</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">DELETE `/api/v0/compose/delete/<uuids>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Delete the list of comma-separated uuids from the compose results.</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "errors": [],</span>
|
|
<span class="sd"> "uuids": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "status": true,</span>
|
|
<span class="sd"> "uuid": "ae1bf7e3-7f16-4c9f-b36e-3726a1093fd0"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ]</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">`/api/v0/compose/info/<uuid>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Get detailed information about the compose. The returned JSON string will</span>
|
|
<span class="sd"> contain the following information:</span>
|
|
|
|
<span class="sd"> * id - The uuid of the comoposition</span>
|
|
<span class="sd"> * config - containing the configuration settings used to run Anaconda</span>
|
|
<span class="sd"> * recipe - The depsolved recipe used to generate the kickstart</span>
|
|
<span class="sd"> * commit - The (local) git commit hash for the recipe used</span>
|
|
<span class="sd"> * deps - The NEVRA of all of the dependencies used in the composition</span>
|
|
<span class="sd"> * compose_type - The type of output generated (tar, iso, etc.)</span>
|
|
<span class="sd"> * queue_status - The final status of the composition (FINISHED or FAILED)</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "commit": "7078e521a54b12eae31c3fd028680da7a0815a4d",</span>
|
|
<span class="sd"> "compose_type": "tar",</span>
|
|
<span class="sd"> "config": {</span>
|
|
<span class="sd"> "anaconda_args": "",</span>
|
|
<span class="sd"> "armplatform": "",</span>
|
|
<span class="sd"> "compress_args": [],</span>
|
|
<span class="sd"> "compression": "xz",</span>
|
|
<span class="sd"> "image_name": "root.tar.xz",</span>
|
|
<span class="sd"> ...</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> "deps": {</span>
|
|
<span class="sd"> "packages": [</span>
|
|
<span class="sd"> {</span>
|
|
<span class="sd"> "arch": "x86_64",</span>
|
|
<span class="sd"> "epoch": "0",</span>
|
|
<span class="sd"> "name": "acl",</span>
|
|
<span class="sd"> "release": "14.el7",</span>
|
|
<span class="sd"> "version": "2.2.51"</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> ]</span>
|
|
<span class="sd"> },</span>
|
|
<span class="sd"> "id": "c30b7d80-523b-4a23-ad52-61b799739ce8",</span>
|
|
<span class="sd"> "queue_status": "FINISHED",</span>
|
|
<span class="sd"> "recipe": {</span>
|
|
<span class="sd"> "description": "An example kubernetes master",</span>
|
|
<span class="sd"> ...</span>
|
|
<span class="sd"> }</span>
|
|
<span class="sd"> }</span>
|
|
|
|
<span class="sd">`/api/v0/compose/metadata/<uuid>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Returns a .tar of the metadata used for the build. This includes all the</span>
|
|
<span class="sd"> information needed to reproduce the build, including the final kickstart</span>
|
|
<span class="sd"> populated with repository and package NEVRA.</span>
|
|
|
|
<span class="sd"> The mime type is set to 'application/x-tar' and the filename is set to</span>
|
|
<span class="sd"> UUID-metadata.tar</span>
|
|
|
|
<span class="sd"> The .tar is uncompressed, but is not large.</span>
|
|
|
|
<span class="sd">`/api/v0/compose/results/<uuid>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Returns a .tar of the metadata, logs, and output image of the build. This</span>
|
|
<span class="sd"> includes all the information needed to reproduce the build, including the</span>
|
|
<span class="sd"> final kickstart populated with repository and package NEVRA. The output image</span>
|
|
<span class="sd"> is already in compressed form so the returned tar is not compressed.</span>
|
|
|
|
<span class="sd"> The mime type is set to 'application/x-tar' and the filename is set to</span>
|
|
<span class="sd"> UUID.tar</span>
|
|
|
|
<span class="sd">`/api/v0/compose/logs/<uuid>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Returns a .tar of the anaconda build logs. The tar is not compressed, but is</span>
|
|
<span class="sd"> not large.</span>
|
|
|
|
<span class="sd"> The mime type is set to 'application/x-tar' and the filename is set to</span>
|
|
<span class="sd"> UUID-logs.tar</span>
|
|
|
|
<span class="sd">`/api/v0/compose/image/<uuid>`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Returns the output image from the build. The filename is set to the filename</span>
|
|
<span class="sd"> from the build. eg. root.tar.xz or boot.iso.</span>
|
|
|
|
<span class="sd">`/api/v0/compose/log/<uuid>[?size=kbytes]`</span>
|
|
<span class="sd">^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
|
|
|
<span class="sd"> Returns the end of the anaconda.log. The size parameter is optional and defaults to 1Mbytes</span>
|
|
<span class="sd"> if it is not included. The returned data is raw text from the end of the logfile, starting on</span>
|
|
<span class="sd"> a line boundry.</span>
|
|
|
|
<span class="sd"> Example::</span>
|
|
|
|
<span class="sd"> 12:59:24,222 INFO anaconda: Running Thread: AnaConfigurationThread (140629395244800)</span>
|
|
<span class="sd"> 12:59:24,223 INFO anaconda: Configuring installed system</span>
|
|
<span class="sd"> 12:59:24,912 INFO anaconda: Configuring installed system</span>
|
|
<span class="sd"> 12:59:24,912 INFO anaconda: Creating users</span>
|
|
<span class="sd"> 12:59:24,913 INFO anaconda: Clearing libuser.conf at /tmp/libuser.Dyy8Gj</span>
|
|
<span class="sd"> 12:59:25,154 INFO anaconda: Creating users</span>
|
|
<span class="sd"> 12:59:25,155 INFO anaconda: Configuring addons</span>
|
|
<span class="sd"> 12:59:25,155 INFO anaconda: Configuring addons</span>
|
|
<span class="sd"> 12:59:25,155 INFO anaconda: Generating initramfs</span>
|
|
<span class="sd"> 12:59:49,467 INFO anaconda: Generating initramfs</span>
|
|
<span class="sd"> 12:59:49,467 INFO anaconda: Running post-installation scripts</span>
|
|
<span class="sd"> 12:59:49,467 INFO anaconda: Running kickstart %%post script(s)</span>
|
|
<span class="sd"> 12:59:50,782 INFO anaconda: All kickstart %%post script(s) have been run</span>
|
|
<span class="sd"> 12:59:50,782 INFO anaconda: Running post-installation scripts</span>
|
|
<span class="sd"> 12:59:50,784 INFO anaconda: Thread Done: AnaConfigurationThread (140629395244800)</span>
|
|
|
|
<span class="sd">"""</span>
|
|
|
|
<span class="kn">import</span> <span class="nn">logging</span>
|
|
<span class="n">log</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s">"lorax-composer"</span><span class="p">)</span>
|
|
|
|
<span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">jsonify</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">Response</span><span class="p">,</span> <span class="n">send_file</span>
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.compose</span> <span class="kn">import</span> <span class="n">start_build</span><span class="p">,</span> <span class="n">compose_types</span>
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.crossdomain</span> <span class="kn">import</span> <span class="n">crossdomain</span>
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.projects</span> <span class="kn">import</span> <span class="n">projects_list</span><span class="p">,</span> <span class="n">projects_info</span><span class="p">,</span> <span class="n">projects_depsolve</span>
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.projects</span> <span class="kn">import</span> <span class="n">modules_list</span><span class="p">,</span> <span class="n">modules_info</span><span class="p">,</span> <span class="n">ProjectsError</span>
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.queue</span> <span class="kn">import</span> <span class="n">queue_status</span><span class="p">,</span> <span class="n">build_status</span><span class="p">,</span> <span class="n">uuid_delete</span><span class="p">,</span> <span class="n">uuid_status</span><span class="p">,</span> <span class="n">uuid_info</span>
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.queue</span> <span class="kn">import</span> <span class="n">uuid_tar</span><span class="p">,</span> <span class="n">uuid_image</span><span class="p">,</span> <span class="n">uuid_cancel</span><span class="p">,</span> <span class="n">uuid_log</span>
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.recipes</span> <span class="kn">import</span> <span class="n">list_branch_files</span><span class="p">,</span> <span class="n">read_recipe_commit</span><span class="p">,</span> <span class="n">recipe_filename</span><span class="p">,</span> <span class="n">list_commits</span>
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.recipes</span> <span class="kn">import</span> <span class="n">recipe_from_dict</span><span class="p">,</span> <span class="n">recipe_from_toml</span><span class="p">,</span> <span class="n">commit_recipe</span><span class="p">,</span> <span class="n">delete_recipe</span><span class="p">,</span> <span class="n">revert_recipe</span>
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.recipes</span> <span class="kn">import</span> <span class="n">tag_recipe_commit</span><span class="p">,</span> <span class="n">recipe_diff</span>
|
|
<span class="kn">from</span> <span class="nn">pylorax.api.workspace</span> <span class="kn">import</span> <span class="n">workspace_read</span><span class="p">,</span> <span class="n">workspace_write</span><span class="p">,</span> <span class="n">workspace_delete</span>
|
|
|
|
<span class="c"># The API functions don't actually get called by any code here</span>
|
|
<span class="c"># pylint: disable=unused-variable</span>
|
|
|
|
<div class="viewcode-block" id="take_limits"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.v0.take_limits">[docs]</a><span class="k">def</span> <span class="nf">take_limits</span><span class="p">(</span><span class="n">iterable</span><span class="p">,</span> <span class="n">offset</span><span class="p">,</span> <span class="n">limit</span><span class="p">):</span>
|
|
<span class="sd">""" Apply offset and limit to an iterable object</span>
|
|
|
|
<span class="sd"> :param iterable: The object to limit</span>
|
|
<span class="sd"> :type iterable: iter</span>
|
|
<span class="sd"> :param offset: The number of items to skip</span>
|
|
<span class="sd"> :type offset: int</span>
|
|
<span class="sd"> :param limit: The total number of items to return</span>
|
|
<span class="sd"> :type limit: int</span>
|
|
<span class="sd"> :returns: A subset of the iterable</span>
|
|
<span class="sd"> """</span>
|
|
<span class="k">return</span> <span class="n">iterable</span><span class="p">[</span><span class="n">offset</span><span class="p">:][:</span><span class="n">limit</span><span class="p">]</span>
|
|
</div>
|
|
<div class="viewcode-block" id="v0_api"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.v0.v0_api">[docs]</a><span class="k">def</span> <span class="nf">v0_api</span><span class="p">(</span><span class="n">api</span><span class="p">):</span>
|
|
<span class="c"># Note that Sphinx will not generate documentations for any of these.</span>
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/test"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_test</span><span class="p">():</span>
|
|
<span class="k">return</span> <span class="s">"API v0 test"</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/status"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_status</span><span class="p">():</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">build</span><span class="o">=</span><span class="s">"devel"</span><span class="p">,</span> <span class="n">api</span><span class="o">=</span><span class="s">"0"</span><span class="p">,</span> <span class="n">db_version</span><span class="o">=</span><span class="s">"0"</span><span class="p">,</span> <span class="n">schema_version</span><span class="o">=</span><span class="s">"0"</span><span class="p">,</span> <span class="n">db_supported</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/recipes/list"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_recipes_list</span><span class="p">():</span>
|
|
<span class="sd">"""List the available recipes on a branch."""</span>
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"branch"</span><span class="p">,</span> <span class="s">"master"</span><span class="p">)</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">limit</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"limit"</span><span class="p">,</span> <span class="s">"20"</span><span class="p">))</span>
|
|
<span class="n">offset</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"offset"</span><span class="p">,</span> <span class="s">"0"</span><span class="p">))</span>
|
|
<span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">recipes</span> <span class="o">=</span> <span class="n">take_limits</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">f</span><span class="p">:</span> <span class="n">f</span><span class="p">[:</span><span class="o">-</span><span class="mi">5</span><span class="p">],</span> <span class="n">list_branch_files</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">)),</span> <span class="n">offset</span><span class="p">,</span> <span class="n">limit</span><span class="p">)</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">recipes</span><span class="o">=</span><span class="n">recipes</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="n">limit</span><span class="p">,</span> <span class="n">offset</span><span class="o">=</span><span class="n">offset</span><span class="p">,</span> <span class="n">total</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">recipes</span><span class="p">))</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/recipes/info/<recipe_names>"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_recipes_info</span><span class="p">(</span><span class="n">recipe_names</span><span class="p">):</span>
|
|
<span class="sd">"""Return the contents of the recipe, or a list of recipes"""</span>
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"branch"</span><span class="p">,</span> <span class="s">"master"</span><span class="p">)</span>
|
|
<span class="n">recipes</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="n">changes</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="k">for</span> <span class="n">recipe_name</span> <span class="ow">in</span> <span class="p">[</span><span class="n">n</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">recipe_names</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">","</span><span class="p">)]:</span>
|
|
<span class="n">exceptions</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="c"># Get the workspace version (if it exists)</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">ws_recipe</span> <span class="o">=</span> <span class="n">workspace_read</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">ws_recipe</span> <span class="o">=</span> <span class="bp">None</span>
|
|
<span class="n">exceptions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_recipes_info) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
<span class="c"># Get the git version (if it exists)</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">git_recipe</span> <span class="o">=</span> <span class="n">read_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">git_recipe</span> <span class="o">=</span> <span class="bp">None</span>
|
|
<span class="n">exceptions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_recipes_info) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">ws_recipe</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">git_recipe</span><span class="p">:</span>
|
|
<span class="c"># Neither recipe, return an error</span>
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"recipe"</span><span class="p">:</span><span class="n">recipe_name</span><span class="p">,</span> <span class="s">"msg"</span><span class="p">:</span><span class="s">", "</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">exceptions</span><span class="p">)})</span>
|
|
<span class="k">elif</span> <span class="n">ws_recipe</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">git_recipe</span><span class="p">:</span>
|
|
<span class="c"># No git recipe, return the workspace recipe</span>
|
|
<span class="n">changes</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"name"</span><span class="p">:</span><span class="n">recipe_name</span><span class="p">,</span> <span class="s">"changed"</span><span class="p">:</span><span class="bp">True</span><span class="p">})</span>
|
|
<span class="n">recipes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ws_recipe</span><span class="p">)</span>
|
|
<span class="k">elif</span> <span class="ow">not</span> <span class="n">ws_recipe</span> <span class="ow">and</span> <span class="n">git_recipe</span><span class="p">:</span>
|
|
<span class="c"># No workspace recipe, no change, return the git recipe</span>
|
|
<span class="n">changes</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"name"</span><span class="p">:</span><span class="n">recipe_name</span><span class="p">,</span> <span class="s">"changed"</span><span class="p">:</span><span class="bp">False</span><span class="p">})</span>
|
|
<span class="n">recipes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">git_recipe</span><span class="p">)</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="c"># Both exist, maybe changed, return the workspace recipe</span>
|
|
<span class="n">changes</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"name"</span><span class="p">:</span><span class="n">recipe_name</span><span class="p">,</span> <span class="s">"changed"</span><span class="p">:</span><span class="n">ws_recipe</span> <span class="o">!=</span> <span class="n">git_recipe</span><span class="p">})</span>
|
|
<span class="n">recipes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ws_recipe</span><span class="p">)</span>
|
|
|
|
<span class="c"># Sort all the results by case-insensitive recipe name</span>
|
|
<span class="n">changes</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">changes</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">c</span><span class="p">:</span> <span class="n">c</span><span class="p">[</span><span class="s">"name"</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
<span class="n">recipes</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">recipes</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">r</span><span class="p">:</span> <span class="n">r</span><span class="p">[</span><span class="s">"name"</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
<span class="n">errors</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">errors</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">e</span><span class="p">:</span> <span class="n">e</span><span class="p">[</span><span class="s">"recipe"</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">changes</span><span class="o">=</span><span class="n">changes</span><span class="p">,</span> <span class="n">recipes</span><span class="o">=</span><span class="n">recipes</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="n">errors</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/recipes/changes/<recipe_names>"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_recipes_changes</span><span class="p">(</span><span class="n">recipe_names</span><span class="p">):</span>
|
|
<span class="sd">"""Return the changes to a recipe or list of recipes"""</span>
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"branch"</span><span class="p">,</span> <span class="s">"master"</span><span class="p">)</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">limit</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"limit"</span><span class="p">,</span> <span class="s">"20"</span><span class="p">))</span>
|
|
<span class="n">offset</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"offset"</span><span class="p">,</span> <span class="s">"0"</span><span class="p">))</span>
|
|
<span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
|
|
<span class="n">recipes</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="k">for</span> <span class="n">recipe_name</span> <span class="ow">in</span> <span class="p">[</span><span class="n">n</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">recipe_names</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">","</span><span class="p">)]:</span>
|
|
<span class="n">filename</span> <span class="o">=</span> <span class="n">recipe_filename</span><span class="p">(</span><span class="n">recipe_name</span><span class="p">)</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">commits</span> <span class="o">=</span> <span class="n">take_limits</span><span class="p">(</span><span class="n">list_commits</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">filename</span><span class="p">),</span> <span class="n">offset</span><span class="p">,</span> <span class="n">limit</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"recipe"</span><span class="p">:</span><span class="n">recipe_name</span><span class="p">,</span> <span class="s">"msg"</span><span class="p">:</span><span class="n">e</span><span class="p">})</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_recipes_changes) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="n">recipes</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"name"</span><span class="p">:</span><span class="n">recipe_name</span><span class="p">,</span> <span class="s">"changes"</span><span class="p">:</span><span class="n">commits</span><span class="p">,</span> <span class="s">"total"</span><span class="p">:</span><span class="nb">len</span><span class="p">(</span><span class="n">commits</span><span class="p">)})</span>
|
|
|
|
<span class="n">recipes</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">recipes</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">r</span><span class="p">:</span> <span class="n">r</span><span class="p">[</span><span class="s">"name"</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
<span class="n">errors</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">errors</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">e</span><span class="p">:</span> <span class="n">e</span><span class="p">[</span><span class="s">"recipe"</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">recipes</span><span class="o">=</span><span class="n">recipes</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="n">errors</span><span class="p">,</span> <span class="n">offset</span><span class="o">=</span><span class="n">offset</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="n">limit</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/recipes/new"</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s">"POST"</span><span class="p">])</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_recipes_new</span><span class="p">():</span>
|
|
<span class="sd">"""Commit a new recipe"""</span>
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"branch"</span><span class="p">,</span> <span class="s">"master"</span><span class="p">)</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s">'Content-Type'</span><span class="p">]</span> <span class="o">==</span> <span class="s">"text/x-toml"</span><span class="p">:</span>
|
|
<span class="n">recipe</span> <span class="o">=</span> <span class="n">recipe_from_toml</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">data</span><span class="p">)</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="n">recipe</span> <span class="o">=</span> <span class="n">recipe_from_dict</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">get_json</span><span class="p">(</span><span class="n">cache</span><span class="o">=</span><span class="bp">False</span><span class="p">))</span>
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">commit_recipe</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe</span><span class="p">)</span>
|
|
|
|
<span class="c"># Read the recipe with new version and write it to the workspace</span>
|
|
<span class="n">recipe</span> <span class="o">=</span> <span class="n">read_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe</span><span class="p">[</span><span class="s">"name"</span><span class="p">])</span>
|
|
<span class="n">workspace_write</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_recipes_new) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/recipes/delete/<recipe_name>"</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s">"DELETE"</span><span class="p">])</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_recipes_delete</span><span class="p">(</span><span class="n">recipe_name</span><span class="p">):</span>
|
|
<span class="sd">"""Delete a recipe from git"""</span>
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"branch"</span><span class="p">,</span> <span class="s">"master"</span><span class="p">)</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">delete_recipe</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_recipes_delete) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/recipes/workspace"</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s">"POST"</span><span class="p">])</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_recipes_workspace</span><span class="p">():</span>
|
|
<span class="sd">"""Write a recipe to the workspace"""</span>
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"branch"</span><span class="p">,</span> <span class="s">"master"</span><span class="p">)</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s">'Content-Type'</span><span class="p">]</span> <span class="o">==</span> <span class="s">"text/x-toml"</span><span class="p">:</span>
|
|
<span class="n">recipe</span> <span class="o">=</span> <span class="n">recipe_from_toml</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">data</span><span class="p">)</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="n">recipe</span> <span class="o">=</span> <span class="n">recipe_from_dict</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">get_json</span><span class="p">(</span><span class="n">cache</span><span class="o">=</span><span class="bp">False</span><span class="p">))</span>
|
|
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">workspace_write</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_recipes_workspace) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/recipes/workspace/<recipe_name>"</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s">"DELETE"</span><span class="p">])</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_recipes_delete_workspace</span><span class="p">(</span><span class="n">recipe_name</span><span class="p">):</span>
|
|
<span class="sd">"""Delete a recipe from the workspace"""</span>
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"branch"</span><span class="p">,</span> <span class="s">"master"</span><span class="p">)</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">workspace_delete</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_recipes_delete_workspace) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/recipes/undo/<recipe_name>/<commit>"</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s">"POST"</span><span class="p">])</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_recipes_undo</span><span class="p">(</span><span class="n">recipe_name</span><span class="p">,</span> <span class="n">commit</span><span class="p">):</span>
|
|
<span class="sd">"""Undo changes to a recipe by reverting to a previous commit."""</span>
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"branch"</span><span class="p">,</span> <span class="s">"master"</span><span class="p">)</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">revert_recipe</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">,</span> <span class="n">commit</span><span class="p">)</span>
|
|
|
|
<span class="c"># Read the new recipe and write it to the workspace</span>
|
|
<span class="n">recipe</span> <span class="o">=</span> <span class="n">read_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">)</span>
|
|
<span class="n">workspace_write</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_recipes_undo) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/recipes/tag/<recipe_name>"</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s">"POST"</span><span class="p">])</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_recipes_tag</span><span class="p">(</span><span class="n">recipe_name</span><span class="p">):</span>
|
|
<span class="sd">"""Tag a recipe's latest recipe commit as a 'revision'"""</span>
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"branch"</span><span class="p">,</span> <span class="s">"master"</span><span class="p">)</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">tag_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_recipes_tag) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/recipes/diff/<recipe_name>/<from_commit>/<to_commit>"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_recipes_diff</span><span class="p">(</span><span class="n">recipe_name</span><span class="p">,</span> <span class="n">from_commit</span><span class="p">,</span> <span class="n">to_commit</span><span class="p">):</span>
|
|
<span class="sd">"""Return the differences between two commits of a recipe"""</span>
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"branch"</span><span class="p">,</span> <span class="s">"master"</span><span class="p">)</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">if</span> <span class="n">from_commit</span> <span class="o">==</span> <span class="s">"NEWEST"</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">old_recipe</span> <span class="o">=</span> <span class="n">read_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">)</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">old_recipe</span> <span class="o">=</span> <span class="n">read_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">,</span> <span class="n">from_commit</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_recipes_diff) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">if</span> <span class="n">to_commit</span> <span class="o">==</span> <span class="s">"WORKSPACE"</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">new_recipe</span> <span class="o">=</span> <span class="n">workspace_read</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">)</span>
|
|
<span class="c"># If there is no workspace, use the newest commit instead</span>
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">new_recipe</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">new_recipe</span> <span class="o">=</span> <span class="n">read_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">)</span>
|
|
<span class="k">elif</span> <span class="n">to_commit</span> <span class="o">==</span> <span class="s">"NEWEST"</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">new_recipe</span> <span class="o">=</span> <span class="n">read_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">)</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">new_recipe</span> <span class="o">=</span> <span class="n">read_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">,</span> <span class="n">to_commit</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_recipes_diff) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
|
|
<span class="n">diff</span> <span class="o">=</span> <span class="n">recipe_diff</span><span class="p">(</span><span class="n">old_recipe</span><span class="p">,</span> <span class="n">new_recipe</span><span class="p">)</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">diff</span><span class="o">=</span><span class="n">diff</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/recipes/freeze/<recipe_names>"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_recipes_freeze</span><span class="p">(</span><span class="n">recipe_names</span><span class="p">):</span>
|
|
<span class="sd">"""Return the recipe with the exact modules and packages selected by depsolve"""</span>
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"branch"</span><span class="p">,</span> <span class="s">"master"</span><span class="p">)</span>
|
|
<span class="n">recipes</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="k">for</span> <span class="n">recipe_name</span> <span class="ow">in</span> <span class="p">[</span><span class="n">n</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">recipe_names</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">","</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span><span class="o">.</span><span class="n">lower</span><span class="p">())]:</span>
|
|
<span class="c"># get the recipe</span>
|
|
<span class="c"># Get the workspace version (if it exists)</span>
|
|
<span class="n">recipe</span> <span class="o">=</span> <span class="bp">None</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">recipe</span> <span class="o">=</span> <span class="n">workspace_read</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
|
|
<span class="k">pass</span>
|
|
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">recipe</span><span class="p">:</span>
|
|
<span class="c"># No workspace version, get the git version (if it exists)</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">recipe</span> <span class="o">=</span> <span class="n">read_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"recipe"</span><span class="p">:</span><span class="n">recipe_name</span><span class="p">,</span> <span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)})</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_recipes_freeze) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
<span class="c"># No recipe found, skip it.</span>
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">recipe</span><span class="p">:</span>
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"recipe"</span><span class="p">:</span><span class="n">recipe_name</span><span class="p">,</span> <span class="s">"msg"</span><span class="p">:</span><span class="s">"Recipe not found"</span><span class="p">})</span>
|
|
<span class="k">continue</span>
|
|
|
|
<span class="c"># Combine modules and packages and depsolve the list</span>
|
|
<span class="c"># TODO include the version/glob in the depsolving</span>
|
|
<span class="n">module_names</span> <span class="o">=</span> <span class="n">recipe</span><span class="o">.</span><span class="n">module_names</span>
|
|
<span class="n">package_names</span> <span class="o">=</span> <span class="n">recipe</span><span class="o">.</span><span class="n">package_names</span>
|
|
<span class="n">projects</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">module_names</span><span class="o">+</span><span class="n">package_names</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
<span class="n">deps</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"YUMLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">deps</span> <span class="o">=</span> <span class="n">projects_depsolve</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"YUMLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">yb</span><span class="p">,</span> <span class="n">projects</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="n">ProjectsError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"recipe"</span><span class="p">:</span><span class="n">recipe_name</span><span class="p">,</span> <span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)})</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_recipes_freeze) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
<span class="n">recipes</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"recipe"</span><span class="p">:</span> <span class="n">recipe</span><span class="o">.</span><span class="n">freeze</span><span class="p">(</span><span class="n">deps</span><span class="p">)})</span>
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">recipes</span><span class="o">=</span><span class="n">recipes</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="n">errors</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/recipes/depsolve/<recipe_names>"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_recipes_depsolve</span><span class="p">(</span><span class="n">recipe_names</span><span class="p">):</span>
|
|
<span class="sd">"""Return the dependencies for a recipe"""</span>
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"branch"</span><span class="p">,</span> <span class="s">"master"</span><span class="p">)</span>
|
|
<span class="n">recipes</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="k">for</span> <span class="n">recipe_name</span> <span class="ow">in</span> <span class="p">[</span><span class="n">n</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">recipe_names</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">","</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span><span class="o">.</span><span class="n">lower</span><span class="p">())]:</span>
|
|
<span class="c"># get the recipe</span>
|
|
<span class="c"># Get the workspace version (if it exists)</span>
|
|
<span class="n">recipe</span> <span class="o">=</span> <span class="bp">None</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">recipe</span> <span class="o">=</span> <span class="n">workspace_read</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
|
|
<span class="k">pass</span>
|
|
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">recipe</span><span class="p">:</span>
|
|
<span class="c"># No workspace version, get the git version (if it exists)</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">recipe</span> <span class="o">=</span> <span class="n">read_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"recipe"</span><span class="p">:</span><span class="n">recipe_name</span><span class="p">,</span> <span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)})</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_recipes_depsolve) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
<span class="c"># No recipe found, skip it.</span>
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">recipe</span><span class="p">:</span>
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"recipe"</span><span class="p">:</span><span class="n">recipe_name</span><span class="p">,</span> <span class="s">"msg"</span><span class="p">:</span><span class="s">"Recipe not found"</span><span class="p">})</span>
|
|
<span class="k">continue</span>
|
|
|
|
<span class="c"># Combine modules and packages and depsolve the list</span>
|
|
<span class="c"># TODO include the version/glob in the depsolving</span>
|
|
<span class="n">module_names</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">m</span><span class="p">:</span> <span class="n">m</span><span class="p">[</span><span class="s">"name"</span><span class="p">],</span> <span class="n">recipe</span><span class="p">[</span><span class="s">"modules"</span><span class="p">]</span> <span class="ow">or</span> <span class="p">[])</span>
|
|
<span class="n">package_names</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">p</span><span class="p">:</span> <span class="n">p</span><span class="p">[</span><span class="s">"name"</span><span class="p">],</span> <span class="n">recipe</span><span class="p">[</span><span class="s">"packages"</span><span class="p">]</span> <span class="ow">or</span> <span class="p">[])</span>
|
|
<span class="n">projects</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">module_names</span><span class="o">+</span><span class="n">package_names</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
<span class="n">deps</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"YUMLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">deps</span> <span class="o">=</span> <span class="n">projects_depsolve</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"YUMLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">yb</span><span class="p">,</span> <span class="n">projects</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="n">ProjectsError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"recipe"</span><span class="p">:</span><span class="n">recipe_name</span><span class="p">,</span> <span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)})</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_recipes_depsolve) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
<span class="c"># Get the NEVRA's of the modules and projects, add as "modules"</span>
|
|
<span class="n">modules</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="k">for</span> <span class="n">dep</span> <span class="ow">in</span> <span class="n">deps</span><span class="p">:</span>
|
|
<span class="k">if</span> <span class="n">dep</span><span class="p">[</span><span class="s">"name"</span><span class="p">]</span> <span class="ow">in</span> <span class="n">projects</span><span class="p">:</span>
|
|
<span class="n">modules</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">dep</span><span class="p">)</span>
|
|
<span class="n">modules</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">modules</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">m</span><span class="p">:</span> <span class="n">m</span><span class="p">[</span><span class="s">"name"</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
|
|
<span class="n">recipes</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"recipe"</span><span class="p">:</span><span class="n">recipe</span><span class="p">,</span> <span class="s">"dependencies"</span><span class="p">:</span><span class="n">deps</span><span class="p">,</span> <span class="s">"modules"</span><span class="p">:</span><span class="n">modules</span><span class="p">})</span>
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">recipes</span><span class="o">=</span><span class="n">recipes</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="n">errors</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/projects/list"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_projects_list</span><span class="p">():</span>
|
|
<span class="sd">"""List all of the available projects/packages"""</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">limit</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"limit"</span><span class="p">,</span> <span class="s">"20"</span><span class="p">))</span>
|
|
<span class="n">offset</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"offset"</span><span class="p">,</span> <span class="s">"0"</span><span class="p">))</span>
|
|
<span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"YUMLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">available</span> <span class="o">=</span> <span class="n">projects_list</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"YUMLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">yb</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="n">ProjectsError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_projects_list) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
|
|
<span class="n">projects</span> <span class="o">=</span> <span class="n">take_limits</span><span class="p">(</span><span class="n">available</span><span class="p">,</span> <span class="n">offset</span><span class="p">,</span> <span class="n">limit</span><span class="p">)</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">projects</span><span class="o">=</span><span class="n">projects</span><span class="p">,</span> <span class="n">offset</span><span class="o">=</span><span class="n">offset</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="n">limit</span><span class="p">,</span> <span class="n">total</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">available</span><span class="p">))</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/projects/info/<project_names>"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_projects_info</span><span class="p">(</span><span class="n">project_names</span><span class="p">):</span>
|
|
<span class="sd">"""Return detailed information about the listed projects"""</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"YUMLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">projects</span> <span class="o">=</span> <span class="n">projects_info</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"YUMLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">yb</span><span class="p">,</span> <span class="n">project_names</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">","</span><span class="p">))</span>
|
|
<span class="k">except</span> <span class="n">ProjectsError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_projects_info) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">projects</span><span class="o">=</span><span class="n">projects</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/projects/depsolve/<project_names>"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_projects_depsolve</span><span class="p">(</span><span class="n">project_names</span><span class="p">):</span>
|
|
<span class="sd">"""Return detailed information about the listed projects"""</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"YUMLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">deps</span> <span class="o">=</span> <span class="n">projects_depsolve</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"YUMLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">yb</span><span class="p">,</span> <span class="n">project_names</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">","</span><span class="p">))</span>
|
|
<span class="k">except</span> <span class="n">ProjectsError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_projects_depsolve) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">projects</span><span class="o">=</span><span class="n">deps</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/modules/list"</span><span class="p">)</span>
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/modules/list/<module_names>"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_modules_list</span><span class="p">(</span><span class="n">module_names</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
|
|
<span class="sd">"""List available modules, filtering by module_names"""</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">limit</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"limit"</span><span class="p">,</span> <span class="s">"20"</span><span class="p">))</span>
|
|
<span class="n">offset</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"offset"</span><span class="p">,</span> <span class="s">"0"</span><span class="p">))</span>
|
|
<span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
|
|
<span class="k">if</span> <span class="n">module_names</span><span class="p">:</span>
|
|
<span class="n">module_names</span> <span class="o">=</span> <span class="n">module_names</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">","</span><span class="p">)</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"YUMLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">available</span> <span class="o">=</span> <span class="n">modules_list</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"YUMLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">yb</span><span class="p">,</span> <span class="n">module_names</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="n">ProjectsError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_modules_list) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
|
|
<span class="n">modules</span> <span class="o">=</span> <span class="n">take_limits</span><span class="p">(</span><span class="n">available</span><span class="p">,</span> <span class="n">offset</span><span class="p">,</span> <span class="n">limit</span><span class="p">)</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">modules</span><span class="o">=</span><span class="n">modules</span><span class="p">,</span> <span class="n">offset</span><span class="o">=</span><span class="n">offset</span><span class="p">,</span> <span class="n">limit</span><span class="o">=</span><span class="n">limit</span><span class="p">,</span> <span class="n">total</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">available</span><span class="p">))</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/modules/info/<module_names>"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_modules_info</span><span class="p">(</span><span class="n">module_names</span><span class="p">):</span>
|
|
<span class="sd">"""Return detailed information about the listed modules"""</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"YUMLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
|
|
<span class="n">modules</span> <span class="o">=</span> <span class="n">modules_info</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"YUMLOCK"</span><span class="p">]</span><span class="o">.</span><span class="n">yb</span><span class="p">,</span> <span class="n">module_names</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">","</span><span class="p">))</span>
|
|
<span class="k">except</span> <span class="n">ProjectsError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s">"(v0_modules_info) </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">modules</span><span class="o">=</span><span class="n">modules</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/compose"</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s">"POST"</span><span class="p">])</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_compose_start</span><span class="p">():</span>
|
|
<span class="sd">"""Start a compose</span>
|
|
|
|
<span class="sd"> The body of the post should have these fields:</span>
|
|
<span class="sd"> recipe_name - The recipe name from /recipes/list/</span>
|
|
<span class="sd"> compose_type - The type of output to create, from /compose/types</span>
|
|
<span class="sd"> branch - Optional, defaults to master, selects the git branch to use for the recipe.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="c"># Passing ?test=1 will generate a fake FAILED compose.</span>
|
|
<span class="c"># Passing ?test=2 will generate a fake FINISHED compose.</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">test_mode</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"test"</span><span class="p">,</span> <span class="s">"0"</span><span class="p">))</span>
|
|
<span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
|
|
<span class="n">test_mode</span> <span class="o">=</span> <span class="mi">0</span>
|
|
|
|
<span class="n">compose</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">get_json</span><span class="p">(</span><span class="n">cache</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
|
|
|
|
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">compose</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="s">"Missing POST body"</span><span class="p">}),</span> <span class="mi">400</span>
|
|
|
|
<span class="k">if</span> <span class="s">"recipe_name"</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">compose</span><span class="p">:</span>
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">"No 'recipe_name' in the JSON request"</span><span class="p">)</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="n">recipe_name</span> <span class="o">=</span> <span class="n">compose</span><span class="p">[</span><span class="s">"recipe_name"</span><span class="p">]</span>
|
|
|
|
<span class="k">if</span> <span class="s">"branch"</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">compose</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">compose</span><span class="p">[</span><span class="s">"branch"</span><span class="p">]:</span>
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="s">"master"</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="n">branch</span> <span class="o">=</span> <span class="n">compose</span><span class="p">[</span><span class="s">"branch"</span><span class="p">]</span>
|
|
|
|
<span class="k">if</span> <span class="s">"compose_type"</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">compose</span><span class="p">:</span>
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">"No 'compose_type' in the JSON request"</span><span class="p">)</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="n">compose_type</span> <span class="o">=</span> <span class="n">compose</span><span class="p">[</span><span class="s">"compose_type"</span><span class="p">]</span>
|
|
|
|
<span class="k">if</span> <span class="n">errors</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">errors</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">build_id</span> <span class="o">=</span> <span class="n">start_build</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"YUMLOCK"</span><span class="p">],</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"GITLOCK"</span><span class="p">],</span>
|
|
<span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">,</span> <span class="n">compose_type</span><span class="p">,</span> <span class="n">test_mode</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">build_id</span><span class="o">=</span><span class="n">build_id</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/compose/types"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_compose_types</span><span class="p">():</span>
|
|
<span class="sd">"""Return the list of enabled output types</span>
|
|
|
|
<span class="sd"> (only enabled types are returned)</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">share_dir</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"composer"</span><span class="p">,</span> <span class="s">"share_dir"</span><span class="p">)</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">types</span><span class="o">=</span><span class="p">[{</span><span class="s">"name"</span><span class="p">:</span> <span class="n">k</span><span class="p">,</span> <span class="s">"enabled"</span><span class="p">:</span> <span class="bp">True</span><span class="p">}</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">compose_types</span><span class="p">(</span><span class="n">share_dir</span><span class="p">)])</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/compose/queue"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_compose_queue</span><span class="p">():</span>
|
|
<span class="sd">"""Return the status of the new and running queues"""</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">queue_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">]))</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/compose/finished"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_compose_finished</span><span class="p">():</span>
|
|
<span class="sd">"""Return the list of finished composes"""</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">finished</span><span class="o">=</span><span class="n">build_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="s">"FINISHED"</span><span class="p">))</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/compose/failed"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_compose_failed</span><span class="p">():</span>
|
|
<span class="sd">"""Return the list of failed composes"""</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">failed</span><span class="o">=</span><span class="n">build_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="s">"FAILED"</span><span class="p">))</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/compose/status/<uuids>"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_compose_status</span><span class="p">(</span><span class="n">uuids</span><span class="p">):</span>
|
|
<span class="sd">"""Return the status of the listed uuids"""</span>
|
|
<span class="n">results</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="k">for</span> <span class="n">uuid</span> <span class="ow">in</span> <span class="p">[</span><span class="n">n</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">uuids</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">","</span><span class="p">)]:</span>
|
|
<span class="n">details</span> <span class="o">=</span> <span class="n">uuid_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="n">details</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
|
|
<span class="n">results</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">details</span><span class="p">)</span>
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">uuids</span><span class="o">=</span><span class="n">results</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/compose/cancel/<uuid>"</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s">"DELETE"</span><span class="p">])</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_compose_cancel</span><span class="p">(</span><span class="n">uuid</span><span class="p">):</span>
|
|
<span class="sd">"""Cancel a running compose and delete its results directory"""</span>
|
|
<span class="n">status</span> <span class="o">=</span> <span class="n">uuid_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="n">status</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s">"</span><span class="si">%s</span><span class="s"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">),</span> <span class="mi">400</span>
|
|
|
|
<span class="k">if</span> <span class="n">status</span><span class="p">[</span><span class="s">"queue_status"</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s">"WAITING"</span><span class="p">,</span> <span class="s">"RUNNING"</span><span class="p">]:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">uuid</span><span class="o">=</span><span class="n">uuid</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s">"Cannot cancel a build that is in the </span><span class="si">%s</span><span class="s"> state"</span> <span class="o">%</span> <span class="n">status</span><span class="p">[</span><span class="s">"queue_status"</span><span class="p">])</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">uuid_cancel</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">uuid</span><span class="o">=</span><span class="n">uuid</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">uuid</span><span class="o">=</span><span class="n">uuid</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/compose/delete/<uuids>"</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s">"DELETE"</span><span class="p">])</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_compose_delete</span><span class="p">(</span><span class="n">uuids</span><span class="p">):</span>
|
|
<span class="sd">"""Delete the compose results for the listed uuids"""</span>
|
|
<span class="n">results</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
|
|
<span class="k">for</span> <span class="n">uuid</span> <span class="ow">in</span> <span class="p">[</span><span class="n">n</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">uuids</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">","</span><span class="p">)]:</span>
|
|
<span class="n">status</span> <span class="o">=</span> <span class="n">uuid_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="n">status</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"uuid"</span><span class="p">:</span> <span class="n">uuid</span><span class="p">,</span> <span class="s">"msg"</span><span class="p">:</span> <span class="s">"Not a valid build uuid"</span><span class="p">})</span>
|
|
<span class="k">elif</span> <span class="n">status</span><span class="p">[</span><span class="s">"queue_status"</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s">"FINISHED"</span><span class="p">,</span> <span class="s">"FAILED"</span><span class="p">]:</span>
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"uuid"</span><span class="p">:</span><span class="n">uuid</span><span class="p">,</span> <span class="s">"msg"</span><span class="p">:</span><span class="s">"Build not in FINISHED or FAILED."</span><span class="p">})</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">uuid_delete</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"uuid"</span><span class="p">:</span><span class="n">uuid</span><span class="p">,</span> <span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)})</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="n">results</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s">"uuid"</span><span class="p">:</span><span class="n">uuid</span><span class="p">,</span> <span class="s">"status"</span><span class="p">:</span><span class="bp">True</span><span class="p">})</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">uuids</span><span class="o">=</span><span class="n">results</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="n">errors</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/compose/info/<uuid>"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_compose_info</span><span class="p">(</span><span class="n">uuid</span><span class="p">):</span>
|
|
<span class="sd">"""Return detailed info about a compose"""</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">info</span> <span class="o">=</span> <span class="n">uuid_info</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="o">**</span><span class="n">info</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/compose/metadata/<uuid>"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_compose_metadata</span><span class="p">(</span><span class="n">uuid</span><span class="p">):</span>
|
|
<span class="sd">"""Return a tar of the metadata for the build"""</span>
|
|
<span class="n">status</span> <span class="o">=</span> <span class="n">uuid_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="n">status</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s">"</span><span class="si">%s</span><span class="s"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">),</span> <span class="mi">400</span>
|
|
<span class="k">if</span> <span class="n">status</span><span class="p">[</span><span class="s">"queue_status"</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s">"FINISHED"</span><span class="p">,</span> <span class="s">"FAILED"</span><span class="p">]:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">uuid</span><span class="o">=</span><span class="n">uuid</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s">"Build not in FINISHED or FAILED."</span><span class="p">)</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">Response</span><span class="p">(</span><span class="n">uuid_tar</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">,</span> <span class="n">metadata</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">image</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">logs</span><span class="o">=</span><span class="bp">False</span><span class="p">),</span>
|
|
<span class="n">mimetype</span><span class="o">=</span><span class="s">"application/x-tar"</span><span class="p">,</span>
|
|
<span class="n">headers</span><span class="o">=</span><span class="p">[(</span><span class="s">"Content-Disposition"</span><span class="p">,</span> <span class="s">"attachment; filename=</span><span class="si">%s</span><span class="s">-metadata.tar;"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">)],</span>
|
|
<span class="n">direct_passthrough</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/compose/results/<uuid>"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_compose_results</span><span class="p">(</span><span class="n">uuid</span><span class="p">):</span>
|
|
<span class="sd">"""Return a tar of the metadata and the results for the build"""</span>
|
|
<span class="n">status</span> <span class="o">=</span> <span class="n">uuid_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="n">status</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s">"</span><span class="si">%s</span><span class="s"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">),</span> <span class="mi">400</span>
|
|
<span class="k">elif</span> <span class="n">status</span><span class="p">[</span><span class="s">"queue_status"</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s">"FINISHED"</span><span class="p">,</span> <span class="s">"FAILED"</span><span class="p">]:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">uuid</span><span class="o">=</span><span class="n">uuid</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s">"Build not in FINISHED or FAILED."</span><span class="p">)</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">Response</span><span class="p">(</span><span class="n">uuid_tar</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">,</span> <span class="n">metadata</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">image</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">logs</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
|
|
<span class="n">mimetype</span><span class="o">=</span><span class="s">"application/x-tar"</span><span class="p">,</span>
|
|
<span class="n">headers</span><span class="o">=</span><span class="p">[(</span><span class="s">"Content-Disposition"</span><span class="p">,</span> <span class="s">"attachment; filename=</span><span class="si">%s</span><span class="s">.tar;"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">)],</span>
|
|
<span class="n">direct_passthrough</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/compose/logs/<uuid>"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_compose_logs</span><span class="p">(</span><span class="n">uuid</span><span class="p">):</span>
|
|
<span class="sd">"""Return a tar of the metadata for the build"""</span>
|
|
<span class="n">status</span> <span class="o">=</span> <span class="n">uuid_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="n">status</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s">"</span><span class="si">%s</span><span class="s"> is not a valid build uuid"</span><span class="p">),</span> <span class="mi">400</span>
|
|
<span class="k">elif</span> <span class="n">status</span><span class="p">[</span><span class="s">"queue_status"</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s">"FINISHED"</span><span class="p">,</span> <span class="s">"FAILED"</span><span class="p">]:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">uuid</span><span class="o">=</span><span class="n">uuid</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s">"Build not in FINISHED or FAILED."</span><span class="p">)</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">Response</span><span class="p">(</span><span class="n">uuid_tar</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">,</span> <span class="n">metadata</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">image</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">logs</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
|
|
<span class="n">mimetype</span><span class="o">=</span><span class="s">"application/x-tar"</span><span class="p">,</span>
|
|
<span class="n">headers</span><span class="o">=</span><span class="p">[(</span><span class="s">"Content-Disposition"</span><span class="p">,</span> <span class="s">"attachment; filename=</span><span class="si">%s</span><span class="s">-logs.tar;"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">)],</span>
|
|
<span class="n">direct_passthrough</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/compose/image/<uuid>"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_compose_image</span><span class="p">(</span><span class="n">uuid</span><span class="p">):</span>
|
|
<span class="sd">"""Return the output image for the build"""</span>
|
|
<span class="n">status</span> <span class="o">=</span> <span class="n">uuid_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="n">status</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s">"</span><span class="si">%s</span><span class="s"> is not a valid build uuid"</span> <span class="o">%</span> <span class="n">uuid</span><span class="p">),</span> <span class="mi">400</span>
|
|
<span class="k">elif</span> <span class="n">status</span><span class="p">[</span><span class="s">"queue_status"</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s">"FINISHED"</span><span class="p">,</span> <span class="s">"FAILED"</span><span class="p">]:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">uuid</span><span class="o">=</span><span class="n">uuid</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s">"Build not in FINISHED or FAILED."</span><span class="p">)</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="n">image_name</span><span class="p">,</span> <span class="n">image_path</span> <span class="o">=</span> <span class="n">uuid_image</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
|
|
<span class="c"># XXX - Will mime type guessing work for all our output?</span>
|
|
<span class="k">return</span> <span class="n">send_file</span><span class="p">(</span><span class="n">image_path</span><span class="p">,</span> <span class="n">as_attachment</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">attachment_filename</span><span class="o">=</span><span class="n">image_name</span><span class="p">,</span> <span class="n">add_etags</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
|
|
|
|
<span class="nd">@api.route</span><span class="p">(</span><span class="s">"/api/v0/compose/log/<uuid>"</span><span class="p">)</span>
|
|
<span class="nd">@crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="o">=</span><span class="s">"*"</span><span class="p">)</span>
|
|
<span class="k">def</span> <span class="nf">v0_compose_log_tail</span><span class="p">(</span><span class="n">uuid</span><span class="p">):</span>
|
|
<span class="sd">"""Return the end of the main anaconda.log, defaults to 1Mbytes"""</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">size</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"size"</span><span class="p">,</span> <span class="s">"1024"</span><span class="p">))</span>
|
|
<span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">error</span><span class="o">=</span><span class="p">{</span><span class="s">"msg"</span><span class="p">:</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)}),</span> <span class="mi">400</span>
|
|
|
|
<span class="n">status</span> <span class="o">=</span> <span class="n">uuid_status</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="n">status</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">status</span><span class="p">[</span><span class="s">"queue_status"</span><span class="p">]</span> <span class="o">==</span> <span class="s">"WAITING"</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">uuid</span><span class="o">=</span><span class="n">uuid</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s">"Build has not started yet. No logs to view"</span><span class="p">)</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">Response</span><span class="p">(</span><span class="n">uuid_log</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">"COMPOSER_CFG"</span><span class="p">],</span> <span class="n">uuid</span><span class="p">,</span> <span class="n">size</span><span class="p">),</span> <span class="n">direct_passthrough</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="ne">RuntimeError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">uuid</span><span class="o">=</span><span class="n">uuid</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span></div>
|
|
</pre></div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="sphinxsidebar">
|
|
<div class="sphinxsidebarwrapper">
|
|
<div id="searchbox" style="display: none">
|
|
<h3>Quick search</h3>
|
|
<form class="search" action="../../../search.html" method="get">
|
|
<input type="text" name="q" />
|
|
<input type="submit" value="Go" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
<p class="searchtip" style="font-size: 90%">
|
|
Enter search terms or a module, class or function name.
|
|
</p>
|
|
</div>
|
|
<script type="text/javascript">$('#searchbox').show(0);</script>
|
|
</div>
|
|
</div>
|
|
<div class="clearer"></div>
|
|
</div>
|
|
<div class="related">
|
|
<h3>Navigation</h3>
|
|
<ul>
|
|
<li class="right" style="margin-right: 10px">
|
|
<a href="../../../genindex.html" title="General Index"
|
|
>index</a></li>
|
|
<li class="right" >
|
|
<a href="../../../py-modindex.html" title="Python Module Index"
|
|
>modules</a> |</li>
|
|
<li><a href="../../../index.html">Lorax 19.7.10 documentation</a> »</li>
|
|
<li><a href="../../index.html" >Module code</a> »</li>
|
|
<li><a href="../api.html" >pylorax.api</a> »</li>
|
|
</ul>
|
|
</div>
|
|
<div class="footer">
|
|
© Copyright 2017, Red Hat, Inc..
|
|
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
|
|
</div>
|
|
</body>
|
|
</html> |