Add filter arguments to /compose/status

This adds the following optional arguments to the /compose/status route:

  - type, matches the compose_type field
  - status, matches the queue_status field
  - blueprint, matches the blueprint field
This commit is contained in:
David Shea 2018-08-06 15:01:27 -04:00 committed by Brian C. Lane
parent 844ff9998b
commit 40f23f093d

View File

@ -801,8 +801,8 @@ POST `/api/v0/compose`
] ]
} }
`/api/v0/compose/status/<uuids>` `/api/v0/compose/status/<uuids>[?blueprint=<blueprint_name>&status=<compose_status>&type=<compose_type>]`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Return the details for each of the comma-separated list of uuids. Return the details for each of the comma-separated list of uuids.
@ -1822,14 +1822,29 @@ def v0_api(api):
if VALID_API_STRING.match(uuids) is None: if VALID_API_STRING.match(uuids) is None:
return jsonify(status=False, errors=[{"id": INVALID_CHARS, "msg": "Invalid characters in API path"}]), 400 return jsonify(status=False, errors=[{"id": INVALID_CHARS, "msg": "Invalid characters in API path"}]), 400
blueprint = request.args.get("blueprint", None)
status = request.args.get("status", None)
compose_type = request.args.get("type", None)
results = [] results = []
errors = [] errors = []
for uuid in [n.strip().lower() for n in uuids.split(",")]: for uuid in [n.strip().lower() for n in uuids.split(",")]:
details = uuid_status(api.config["COMPOSER_CFG"], uuid) details = uuid_status(api.config["COMPOSER_CFG"], uuid)
if details is not None:
results.append(details) if details is None:
else:
errors.append({"id": UNKNOWN_UUID, "msg": "%s is not a valid build uuid" % uuid}) errors.append({"id": UNKNOWN_UUID, "msg": "%s is not a valid build uuid" % uuid})
continue
if blueprint is not None and details['blueprint'] != blueprint:
continue
if status is not None and details['queue_status'] != status:
continue
if compose_type is not None and details['compose_type'] != compose_type:
continue
results.append(details)
return jsonify(uuids=results, errors=errors) return jsonify(uuids=results, errors=errors)