container.py 952 B

1234567891011121314151617181920212223242526
  1. from flask import Blueprint
  2. from libs.tools import json_response, Argument, AttrDict
  3. from apps.deploy.models import AppHostRel, App
  4. from apps.configuration.models import Environment
  5. blueprint = Blueprint(__name__, __name__)
  6. args = AttrDict(
  7. app_id=Argument('app_id', type=int),
  8. env_id=Argument('env_id', type=int),
  9. cli_id=Argument('cli_id', type=int)
  10. )
  11. @blueprint.route('/<int:host_id>/', methods=['GET'])
  12. def get(host_id):
  13. relationships = [x.to_json() for x in AppHostRel.query.filter_by(host_id=host_id).all()]
  14. apps = App.query.filter(App.id.in_([x['app_id'] for x in relationships])).all() if relationships else []
  15. envs = Environment.query.filter(
  16. Environment.id.in_([x['env_id'] for x in relationships])).all() if relationships else []
  17. return json_response({
  18. 'relationships': relationships,
  19. 'apps': {x.id: x.to_json() for x in apps},
  20. 'envs': {x.id: x.to_json() for x in envs}
  21. })