Coverage for appr/api/deployment.py: 0%

# Coverage for appr/api/deployment.py : 0%

## 30 statements 0 run 30 missing 0 excluded

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | from flask import jsonify, request, Blueprint, current_app import etcd import appr.platforms.kubernetes from appr.exception import (ApprException, InvalidUsage, InvalidVersion, PackageAlreadyExists, PackageNotFound, PackageVersionNotFound) deployment_app = Blueprint( 'deployment', __name__, ) etcd_client = etcd.Client(port=2379) ETCD_PREFIX = "appr/deployments/" @deployment_app.errorhandler(PackageAlreadyExists) @deployment_app.errorhandler(PackageNotFound) @deployment_app.errorhandler(PackageVersionNotFound) @deployment_app.errorhandler(ApprException) @deployment_app.errorhandler(InvalidVersion) @deployment_app.errorhandler(InvalidUsage) def render_error(error): response = jsonify({"error": error.to_dict()}) response.status_code = error.status_code return response def _cmd(cmd, package): jsonbody = request.get_json(force=True, silent=True) values = request.values.to_dict() if jsonbody: values.update(jsonbody) params = { "version": values.get("version"), "namespace": values.get("namespace"), "dry": values.get("dry", False) == 'true', "variables": values.get("variables", None), "endpoint": current_app.config['APPR_REGISTRY_HOST'], "proxy": current_app.config['KUBE_APIMASTER'], "fmt": "json"} current_app.logger.info("%s %s: %s", cmd, package, params) return getattr(appr.platforms.kubernetes, cmd)(package, **params) @deployment_app.route("/api/v1/deployments/<path:package>", methods=['DELETE'], strict_slashes=False) def remove(package): r = _cmd('delete', package) return jsonify({"result": r}) @deployment_app.route("/api/v1/deployments/<path:package>", methods=['POST'], strict_slashes=False) def deploy(package): r = _cmd('deploy', package) return jsonify({"result": r})