示例#1
0
文件: router_api.py 项目: tsuru/rpaas
def add_backend(name):
    try:
        validate_name(name)
    except ValidationError as e:
        return str(e), 400
    data = request.get_json()
    if not data:
        return "could not decode body json", 400
    team = data.get('team') or data.get('tsuru.io/app-teamowner')
    plan = data.get('plan')
    flavor = data.get('flavor')
    if not team:
        return "team name is required", 400
    if require_plan() and not plan:
        return "plan is required", 400
    try:
        if flavor:
            get_manager().new_instance(name, team=team,
                                       plan_name=plan, flavor_name=flavor)
        else:
            get_manager().new_instance(name, team=team, plan_name=plan)
    except storage.PlanNotFoundError:
        return "Plan not found", 404
    except storage.FlavorNotFoundError:
        return "Flavor not found", 404
    except storage.DuplicateError:
        return "{} backend already exists".format(name), 409
    except manager.QuotaExceededError as e:
        return str(e), 403
    return "", 201
示例#2
0
文件: router_api.py 项目: tsuru/rpaas
def update_backend(name):
    data = request.get_json()
    if not data:
        return "could not decode body json", 400
    plan = data.get('plan')
    flavor = data.get('flavor')
    scale = data.get('scale')
    if not plan and not flavor and not scale:
        return "Invalid option. Valid update options are: scale, flavor and plan", 400
    try:
        if scale and int(scale) <= 0:
            raise ValueError
        get_manager().update_instance(name, plan, flavor)
        if scale:
            get_manager().scale_instance(name, scale)
    except tasks.NotReadyError as e:
        return "Backend not ready: {}".format(e), 412
    except storage.InstanceNotFoundError:
        return "Backend not found", 404
    except storage.PlanNotFoundError:
        return "Plan not found", 404
    except storage.FlavorNotFoundError:
        return "Flavor not found", 404
    except ValueError:
        return "Scale option should be integer and >0", 400
    return "", 204
示例#3
0
文件: api.py 项目: tsuru/rpaas
def add_instance():
    if "RPAAS_NEW_SERVICE" in os.environ:
        return "New instance disabled. Use {} service instead".format(os.environ["RPAAS_NEW_SERVICE"]), 405
    name = request.form.get("name")
    try:
        validate_name(name)
    except ValidationError as e:
        return str(e), 400
    team = request.form.get("team")
    if not team:
        return "team name is required", 400
    plan = request.form.get("plan")
    if require_plan() and not plan:
        return "plan is required", 400
    flavor = request.form.get("flavor")
    if not flavor:
        flavor = None
        tags = request.form.getlist("tags")
        for tag in tags:
            if 'flavor:' in tag:
                flavor = tag.split(':')[1]
    try:
        get_manager().new_instance(name, team=team,
                                   plan_name=plan, flavor_name=flavor)
    except storage.PlanNotFoundError:
        return "invalid plan", 400
    except storage.FlavorNotFoundError:
        return "invalid flavor", 400
    except storage.DuplicateError:
        return "{} instance already exists".format(name), 409
    except manager.QuotaExceededError as e:
        return str(e), 403
    return "", 201
示例#4
0
def add_backend(name):
    try:
        validate_name(name)
    except ValidationError as e:
        return str(e), 400
    data = request.get_json()
    if not data:
        return "could not decode body json", 400
    team = data.get('team') or data.get('tsuru.io/app-teamowner')
    plan = data.get('plan')
    flavor = data.get('flavor')
    if not team:
        return "team name is required", 400
    if require_plan() and not plan:
        return "plan is required", 400
    try:
        if flavor:
            get_manager().new_instance(name,
                                       team=team,
                                       plan_name=plan,
                                       flavor_name=flavor)
        else:
            get_manager().new_instance(name, team=team, plan_name=plan)
    except storage.PlanNotFoundError:
        return "Plan not found", 404
    except storage.FlavorNotFoundError:
        return "Flavor not found", 404
    except storage.DuplicateError:
        return "{} backend already exists".format(name), 409
    except manager.QuotaExceededError as e:
        return str(e), 403
    return "", 201
示例#5
0
def update_backend(name):
    data = request.get_json()
    if not data:
        return "could not decode body json", 400
    plan = data.get('plan')
    flavor = data.get('flavor')
    scale = data.get('scale')
    if not plan and not flavor and not scale:
        return "Invalid option. Valid update options are: scale, flavor and plan", 400
    try:
        if scale and int(scale) <= 0:
            raise ValueError
        get_manager().update_instance(name, plan, flavor)
        if scale:
            get_manager().scale_instance(name, scale)
    except tasks.NotReadyError as e:
        return "Backend not ready: {}".format(e), 412
    except storage.InstanceNotFoundError:
        return "Backend not found", 404
    except storage.PlanNotFoundError:
        return "Plan not found", 404
    except storage.FlavorNotFoundError:
        return "Flavor not found", 404
    except ValueError:
        return "Scale option should be integer and >0", 400
    return "", 204
示例#6
0
def delete_backend(name):
    try:
        get_manager().remove_instance(name)
    except storage.InstanceNotFoundError:
        return "Backend not found", 404
    except consul_manager.InstanceAlreadySwappedError:
        return "Instance with swap enabled", 412
    return "", 200
示例#7
0
文件: router_api.py 项目: tsuru/rpaas
def delete_backend(name):
    try:
        get_manager().remove_instance(name)
    except storage.InstanceNotFoundError:
        return "Backend not found", 404
    except consul_manager.InstanceAlreadySwappedError:
        return "Instance with swap enabled", 412
    return "", 200
示例#8
0
文件: api.py 项目: renatosis/rpaas
def delete_route(name):
    path = request.form.get('path')
    if not path:
        return 'missing path', 400
    try:
        get_manager().delete_route(name, path)
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    return "", 200
示例#9
0
def bind(name):
    app_host = request.form.get("app-host")
    if not app_host:
        return "app-host is required", 400
    try:
        get_manager().bind(name, app_host)
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    return Response(response="null", status=201, mimetype="application/json")
示例#10
0
文件: api.py 项目: vierno/rpaas
def delete_route(name):
    path = request.form.get('path')
    if not path:
        return 'missing path', 400
    try:
        get_manager().delete_route(name, path)
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    return "", 200
示例#11
0
文件: api.py 项目: vierno/rpaas
def unbind(name):
    app_host = request.form.get("app-host")
    if not app_host:
        return "app-host is required", 400
    try:
        get_manager().unbind(name, app_host)
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    return "", 200
示例#12
0
文件: api.py 项目: renatosis/rpaas
def unbind(name):
    app_host = request.form.get("app-host")
    if not app_host:
        return "app-host is required", 400
    try:
        get_manager().unbind(name)
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    return "", 200
示例#13
0
文件: api.py 项目: vierno/rpaas
def bind(name):
    app_host = request.form.get("app-host")
    if not app_host:
        return "app-host is required", 400
    try:
        get_manager().bind(name, app_host)
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    return Response(response="null", status=201,
                    mimetype="application/json")
示例#14
0
文件: api.py 项目: vierno/rpaas
def add_block(name):
    content = request.form.get('content')
    block_name = request.form.get('block_name')
    if block_name not in ('server', 'http'):
        return 'invalid block_name (valid values are "server" or "http")', 400
    if not content:
        return 'missing content', 400
    try:
        get_manager().add_block(name, block_name, content)
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    return "", 201
示例#15
0
文件: api.py 项目: tsuru/rpaas
def delete_lua(name):
    try:
        lua_module = request.form.get('lua_module_name')
        lua_module_type = request.form.get('lua_module_type')
        if lua_module_type not in ("server", "worker"):
            return 'Lua module type should be server or worker.', 400
        if not lua_module:
            return 'You should provide a lua module name.', 400
        get_manager().delete_lua(name, lua_module, lua_module_type)
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    return "", 200
示例#16
0
文件: api.py 项目: renatosis/rpaas
def add_block(name):
    content = request.form.get('content')
    block_name = request.form.get('block_name')
    if block_name not in ('server', 'http'):
        return 'invalid block_name (valid values are "server" or "http")', 400
    if not content:
        return 'missing content', 400
    try:
        get_manager().add_block(name, block_name, content)
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    return "", 201
示例#17
0
文件: api.py 项目: renatosis/rpaas
def delete_lua(name):
    try:
        lua_module = request.form.get('lua_module_name')
        lua_module_type = request.form.get('lua_module_type')
        if lua_module_type not in ("server", "worker"):
            return 'Lua module type should be server or worker.', 400
        if not lua_module:
            return 'You should provide a lua module name.', 400
        get_manager().delete_lua(name, lua_module, lua_module_type)
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    return "", 200
示例#18
0
文件: api.py 项目: renatosis/rpaas
def update_instance(name):
    plan = request.form.get("plan_name")
    if not plan:
        return "Plan is required", 404
    try:
        get_manager().update_instance(name, plan)
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    except storage.PlanNotFoundError:
        return "Plan not found", 404
    return "", 204
示例#19
0
文件: api.py 项目: vierno/rpaas
def cancel_restore_machine(name):
    if "RUN_RESTORE_MACHINE" not in os.environ:
        return "Restore machine not enabled", 412
    machine = request.form.get("machine")
    if not machine:
        return "missing machine name", 400
    try:
        get_manager().restore_machine_instance(name, machine, True)
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    except manager.InstanceMachineNotFoundError:
        return "Instance machine not found", 404
    return "", 201
示例#20
0
文件: api.py 项目: renatosis/rpaas
def add_lua(name):
    content = request.form.get('content')
    lua_module = request.form.get('lua_module_name')
    lua_module_type = request.form.get('lua_module_type')
    if lua_module_type not in ("server", "worker"):
        return 'Lua module type should be server or worker.', 400
    if not lua_module:
        return 'You should provide a lua module name.', 400
    if not content:
        return 'missing content', 400
    try:
        get_manager().add_lua(name, lua_module, lua_module_type, content)
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    return "", 201
示例#21
0
文件: api.py 项目: renatosis/rpaas
def cancel_restore_machine(name):
    if not check_option_enable(os.environ.get("RUN_RESTORE_MACHINE")):
        return "Restore machine not enabled", 412
    machine = request.form.get("machine")
    if not machine:
        return "missing machine name", 400
    try:
        get_manager().restore_machine_instance(name, machine, True)
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    except manager.InstanceMachineNotFoundError:
        return "Instance machine not found", 404
    return "", 201
示例#22
0
文件: api.py 项目: tsuru/rpaas
def add_lua(name):
    content = request.form.get('content')
    lua_module = request.form.get('lua_module_name')
    lua_module_type = request.form.get('lua_module_type')
    if lua_module_type not in ("server", "worker"):
        return 'Lua module type should be server or worker.', 400
    if not lua_module:
        return 'You should provide a lua module name.', 400
    if not content:
        return 'missing content', 400
    try:
        get_manager().add_lua(name, lua_module, lua_module_type, content)
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    return "", 201
示例#23
0
文件: api.py 项目: vierno/rpaas
def scale_instance(name):
    quantity = request.form.get("quantity")
    if not quantity:
        return "missing quantity", 400
    try:
        get_manager().scale_instance(name, int(quantity))
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    except ValueError as e:
        msg = " ".join(e.args)
        if "invalid literal" in msg:
            return "invalid quantity: %s" % quantity, 400
        return msg, 400
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    return "", 201
示例#24
0
文件: admin_api.py 项目: tsuru/rpaas
def retrieve_flavor(name):
    manager = get_manager()
    try:
        flavor = manager.storage.find_flavor(name)
    except storage.FlavorNotFoundError:
        return "flavor not found", 404
    return json.dumps(flavor.to_dict())
示例#25
0
文件: admin_api.py 项目: tsuru/rpaas
def healings():
    manager = get_manager()
    quantity = request.args.get("quantity", type=int)
    if quantity is None or quantity <= 0:
        quantity = 20
    healing_list = manager.storage.list_healings(quantity)
    return json.dumps(healing_list, default=json_util.default)
示例#26
0
def retrieve_flavor(name):
    manager = get_manager()
    try:
        flavor = manager.storage.find_flavor(name)
    except storage.FlavorNotFoundError:
        return "flavor not found", 404
    return json.dumps(flavor.to_dict())
示例#27
0
文件: router_api.py 项目: tsuru/rpaas
def delete_certificate(name, cname):
    m = get_manager()
    try:
        m.delete_certificate(name)
    except storage.InstanceNotFoundError:
        return "Backend not found", 404
    return "", 200
示例#28
0
文件: api.py 项目: vierno/rpaas
def add_https(name):
    domain = request.form.get('domain')
    if not domain:
        return "missing domain name", 400
    plugin = request.form.get('plugin', 'default')
    try:
        get_manager().activate_ssl(name, domain, plugin)
        return "", 200
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    except gaierror:
        return "can't find domain", 404
    except manager.SslError, e:
        return str(e), 412
示例#29
0
文件: api.py 项目: dmvieira/rpaas
def node_status(name):
    try:
        node_status = get_manager().node_status(name)
        return Response(response=json.dumps(node_status), status=200,
                        mimetype="application/json")
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
示例#30
0
文件: api.py 项目: vierno/rpaas
def list_block(name):
    try:
        blocks = {'blocks': get_manager().list_blocks(name)}
        return Response(response=json.dumps(blocks), status=200,
                        mimetype="application/json")
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
示例#31
0
def restore_instance():
    instance_name = request.form.get("instance_name")
    if not instance_name:
        return "instance name required", 400
    manager = get_manager()
    return Response(manager.restore_instance(instance_name),
                    content_type='event/stream')
示例#32
0
文件: api.py 项目: vierno/rpaas
def list_routes(name):
    try:
        info = get_manager().list_routes(name)
        return Response(response=json.dumps(info), status=200,
                        mimetype="application/json")
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
示例#33
0
文件: api.py 项目: renatosis/rpaas
def scale_instance(name):
    quantity = request.form.get("quantity")
    if not quantity:
        return "missing quantity", 400
    try:
        get_manager().scale_instance(name, int(quantity))
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    except ValueError as e:
        msg = " ".join(e.args)
        if "invalid literal" in msg:
            return "invalid quantity: %s" % quantity, 400
        return msg, 400
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    return "", 201
示例#34
0
文件: api.py 项目: vierno/rpaas
def update_certificate(name):
    cert = request.form.get('cert')
    if cert is None:
        cert = request.files['cert'].read()
    key = request.form.get('key')
    if key is None:
        key = request.files['key'].read()
    try:
        get_manager().update_certificate(name, cert, key)
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    except manager.SslError:
        return "Invalid key or certificate", 412
    return "", 200
示例#35
0
文件: api.py 项目: renatosis/rpaas
def node_status(name):
    try:
        node_status = get_manager().node_status(name)
        return Response(response=json.dumps(node_status), status=200,
                        mimetype="application/json")
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
示例#36
0
文件: admin_api.py 项目: tsuru/rpaas
def delete_flavor(name):
    manager = get_manager()
    try:
        manager.storage.delete_flavor(name)
    except storage.FlavorNotFoundError:
        return "flavor not found", 404
    return ""
示例#37
0
def delete_plan(name):
    manager = get_manager()
    try:
        manager.storage.delete_plan(name)
    except storage.PlanNotFoundError:
        return "plan not found", 404
    return ""
示例#38
0
文件: admin_api.py 项目: bhyvex/rpaas
def healings():
    manager = get_manager()
    quantity = request.args.get("quantity", type=int)
    if quantity is None or quantity <= 0:
        quantity = 20
    healing_list = manager.storage.list_healings(quantity)
    return json.dumps(healing_list, default=json_util.default)
示例#39
0
def delete_flavor(name):
    manager = get_manager()
    try:
        manager.storage.delete_flavor(name)
    except storage.FlavorNotFoundError:
        return "flavor not found", 404
    return ""
示例#40
0
def delete_certificate(name, cname):
    m = get_manager()
    try:
        m.delete_certificate(name)
    except storage.InstanceNotFoundError:
        return "Backend not found", 404
    return "", 200
示例#41
0
文件: admin_api.py 项目: bhyvex/rpaas
def delete_plan(name):
    manager = get_manager()
    try:
        manager.storage.delete_plan(name)
    except storage.PlanNotFoundError:
        return "plan not found", 404
    return ""
示例#42
0
文件: api.py 项目: renatosis/rpaas
def add_https(name):
    domain = request.form.get('domain')
    if not domain:
        return "missing domain name", 400
    plugin = request.form.get('plugin', 'default')
    try:
        get_manager().activate_ssl(name, domain, plugin)
        return "", 200
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    except gaierror:
        return "can't find domain", 404
    except manager.SslError, e:
        return str(e), 412
示例#43
0
def update_backend(name):
    data = request.get_json()
    if not data:
        return "could not decode body json", 400
    plan = data.get('plan')
    if not plan:
        return "Plan is required", 400
    try:
        get_manager().update_instance(name, plan)
    except tasks.NotReadyError as e:
        return "Backend not ready: {}".format(e), 412
    except storage.InstanceNotFoundError:
        return "Backend not found", 404
    except storage.PlanNotFoundError:
        return "Plan not found", 404
    return "", 204
示例#44
0
文件: api.py 项目: renatosis/rpaas
def list_block(name):
    try:
        blocks = {'blocks': get_manager().list_blocks(name)}
        return Response(response=json.dumps(blocks), status=200,
                        mimetype="application/json")
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
示例#45
0
def retrieve_plan(name):
    manager = get_manager()
    try:
        plan = manager.storage.find_plan(name)
    except storage.PlanNotFoundError:
        return "plan not found", 404
    return json.dumps(plan.to_dict())
示例#46
0
文件: api.py 项目: renatosis/rpaas
def list_routes(name):
    try:
        info = get_manager().list_routes(name)
        return Response(response=json.dumps(info), status=200,
                        mimetype="application/json")
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
示例#47
0
文件: api.py 项目: renatosis/rpaas
def update_certificate(name):
    cert = request.form.get('cert')
    if cert is None:
        cert = request.files['cert'].read()
    key = request.form.get('key')
    if key is None:
        key = request.files['key'].read()
    try:
        get_manager().update_certificate(name, cert, key)
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    except manager.SslError:
        return "Invalid key or certificate", 412
    return "", 200
示例#48
0
文件: admin_api.py 项目: bhyvex/rpaas
def retrieve_plan(name):
    manager = get_manager()
    try:
        plan = manager.storage.find_plan(name)
    except storage.PlanNotFoundError:
        return "plan not found", 404
    return json.dumps(plan.to_dict())
示例#49
0
文件: api.py 项目: vierno/rpaas
def add_route(name):
    path = request.form.get('path')
    if not path:
        return 'missing path', 400
    destination = request.form.get('destination')
    content = request.form.get('content')
    if not destination and not content:
        return 'either content xor destination are required', 400
    if destination and content:
        return 'cannot have both content and destination', 400
    try:
        get_manager().add_route(name, path, destination, content)
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    return "", 201
示例#50
0
def list_lua(name):
    try:
        modules = get_manager().list_lua(name)
        return Response(json.dumps({"modules": modules}),
                        status=200,
                        mimetype="application/json")
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
示例#51
0
文件: api.py 项目: renatosis/rpaas
def add_route(name):
    path = request.form.get('path')
    if not path:
        return 'missing path', 400
    destination = request.form.get('destination')
    content = request.form.get('content')
    if not destination and not content:
        return 'either content xor destination are required', 400
    if destination and content:
        return 'cannot have both content and destination', 400
    try:
        get_manager().add_route(name, path, destination, content)
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    except tasks.NotReadyError as e:
        return "Instance not ready: {}".format(e), 412
    return "", 201
示例#52
0
def update_plan(name):
    description = request.form.get("description")
    config = json.loads(request.form.get("config", "null"))
    manager = get_manager()
    try:
        manager.storage.update_plan(name, description, config)
    except storage.PlanNotFoundError:
        return "plan not found", 404
    return ""
示例#53
0
文件: router_api.py 项目: tsuru/rpaas
def status(name):
    node_status = get_manager().node_status(name)
    status = []
    for node in node_status:
        status.append("{} - {}: {}".format(node, node_status[node]['address'], node_status[node]['status']))
    node_status = {}
    node_status['status'] = "\n".join(status)
    return Response(response=json.dumps(node_status), status=200,
                    mimetype="application/json")
示例#54
0
文件: admin_api.py 项目: bhyvex/rpaas
def update_plan(name):
    description = request.form.get("description")
    config = json.loads(request.form.get("config", "null"))
    manager = get_manager()
    try:
        manager.storage.update_plan(name, description, config)
    except storage.PlanNotFoundError:
        return "plan not found", 404
    return ""
示例#55
0
文件: router_api.py 项目: tsuru/rpaas
def get_certificate(name, cname):
    m = get_manager()
    try:
        certificate, _ = m.get_certificate(name)
    except storage.InstanceNotFoundError:
        return "Backend not found", 404
    except consul_manager.CertificateNotFoundError:
        return "Certificate not found", 404
    return Response(response=json.dumps({'certificate': certificate}),
                    status=200, mimetype="application/json")
示例#56
0
def list_routes(name):
    try:
        routes = get_manager().list_upstreams(name, name)
        routes = ["http://{}".format(route) for route in routes]
    except tasks.NotReadyError as e:
        return "Backend not ready: {}".format(e), 412
    except storage.InstanceNotFoundError:
        return "Backend not found", 404
    return Response(response=json.dumps({"addresses": list(routes)}), status=200,
                    mimetype="application/json")
示例#57
0
文件: router_api.py 项目: tsuru/rpaas
def info():
    plans = get_manager().storage.list_plans()
    flavors = get_manager().storage.list_flavors()
    options_plans = ["{} - {}".format(p.name, p.description) for p in plans]
    options_flavors = ["{} - {}".format(f.name, f.description) for f in flavors]
    options = """
scale  - number of instance vms
plan   - set instance to plan
flavor - set instance to flavor
"""
    if options_plans:
        options = options + "\nAvailable plans: \n" + "\n".join(options_plans)
    if options_plans:
        options = options + "\n"
    if options_flavors:
        options = options + "\nAvailable flavors: \n" + "\n".join(options_flavors)

    return Response(response=json.dumps({'Router options': options}), status=200,
                    mimetype="application/json")
示例#58
0
def get_certificate(name, cname):
    m = get_manager()
    try:
        certificate, _ = m.get_certificate(name)
    except storage.InstanceNotFoundError:
        return "Backend not found", 404
    except consul_manager.CertificateNotFoundError:
        return "Certificate not found", 404
    return Response(response=json.dumps({'certificate': certificate}),
                    status=200, mimetype="application/json")
示例#59
0
文件: router_api.py 项目: tsuru/rpaas
def list_routes(name):
    try:
        routes = get_manager().list_upstreams(name, name)
        routes = ["http://{}".format(route) for route in routes]
    except tasks.NotReadyError as e:
        return "Backend not ready: {}".format(e), 412
    except storage.InstanceNotFoundError:
        return "Backend not found", 404
    return Response(response=json.dumps({"addresses": list(routes)}), status=200,
                    mimetype="application/json")
示例#60
0
文件: api.py 项目: vierno/rpaas
def status(name):
    try:
        status = get_manager().status(name)
    except storage.InstanceNotFoundError:
        return "Instance not found", 404
    if status == manager.FAILURE:
        return status, 500
    if status == manager.PENDING:
        return status, 202
    return status, 204