Exemplo n.º 1
0
# -*- coding: utf-8 -*-
"""Pod / Node management API"""

from flask import g, abort

from citadel.libs.view import create_api_blueprint, user_require
from citadel.models.container import Container
from citadel.rpc.client import get_core

bp = create_api_blueprint('pod', __name__, 'pod')


def _get_pod(name):
    pod = get_core(g.zone).get_pod(name)
    if not pod:
        abort(404, 'pod `%s` not found' % name)

    return pod


@bp.route('/')
@user_require(False)
def get_all_pods():
    """List all pods

    **Example response**:

    .. sourcecode:: http

        HTTP/1.1 200 OK
        Content-Type: application/json
Exemplo n.º 2
0
# -*- coding: utf-8 -*-

from flask import abort, request, g
from marshmallow import ValidationError
from sqlalchemy.exc import IntegrityError
from webargs.flaskparser import use_args

from citadel.libs.validation import ComboSchema, RegisterSchema, SimpleNameSchema, UserSchema
from citadel.libs.view import create_api_blueprint, DEFAULT_RETURN_VALUE, user_require
from citadel.models.app import App, Release
from citadel.models.container import Container
from citadel.models.user import User

bp = create_api_blueprint('app', __name__, 'app')


def _get_app(appname):
    app = App.get_by_name(appname)
    if not app:
        abort(404, 'App not found: {}'.format(appname))

    if not g.user.granted_to_app(app):
        abort(
            403,
            'You\'re not granted to this app, ask administrators for permission'
        )

    return app


def _get_release(appname, sha):
Exemplo n.º 3
0
# coding: utf-8

from flask import abort
from webargs.flaskparser import use_args

from citadel.libs.validation import GetContainerSchema
from citadel.libs.view import create_api_blueprint, user_require
from citadel.models.container import Container

bp = create_api_blueprint('container', __name__, 'container')


@bp.route('/')
@use_args(GetContainerSchema())
@user_require(False)
def get_by(args):
    cs = Container.get_by(**args)
    return cs


@bp.route('/<container_id>')
@user_require(False)
def get_container(container_id):
    try:
        container = Container.get_by_container_id(container_id)
    except ValueError as e:
        abort(404, str(e))

    if not container:
        abort(404, 'Container not found: {}'.format(container_id))
Exemplo n.º 4
0
# -*- coding: utf-8 -*-

from elb import ELBRespError
from flask import g, abort, request
from sqlalchemy.exc import SQLAlchemyError
from webargs.flaskparser import use_args

from citadel.config import ELB_BACKEND_NAME_DELIMITER
from citadel.libs.validation import CreateELBRulesSchema
from citadel.libs.view import DEFAULT_RETURN_VALUE, create_api_blueprint, user_require
from citadel.models.elb import ELBInstance, ELBRuleSet


bp = create_api_blueprint('elb', __name__, url_prefix='elb')


@bp.route('/')
@user_require(True)
def get_elbs():
    return ELBInstance.get_by_zone(g.zone)


def get_elb(elb_id):
    elb = ELBInstance.get(elb_id)
    if not elb:
        abort(404, 'ELB %s not found' % elb_id)
    return elb


# 获取和删除用id, 因为删除可能只删除其中一个.
@bp.route('/<elb_id>', methods=['GET', 'DELETE'])
Exemplo n.º 5
0
import json
from flask import session
from json.decoder import JSONDecodeError
from marshmallow import ValidationError

from citadel.libs.utils import logger
from citadel.libs.validation import renew_schema, build_args_schema, deploy_schema, remove_container_schema, deploy_elb_schema
from citadel.libs.view import create_api_blueprint, user_require
from citadel.models.app import App
from citadel.models.container import Container
from citadel.tasks import renew_container, celery_task_stream_response, build_image, create_container, remove_container, create_elb_instance

ws = create_api_blueprint('action',
                          __name__,
                          url_prefix='action',
                          jsonize=False,
                          handle_http_error=False)


@ws.route('/build')
@user_require(False)
def build(socket):
    """Build an image for the specified release, the API will return all docker
    build messages, key frames as shown in the example responses

    :<json string appname: required, the app name
    :<json string sha: required, minimum length is 7

    **Example response**: