Ejemplo n.º 1
0
def get_app_env(name):
    app = App.get_by_name(name)
    if not app:
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'App %s not found, env list ignored' % name)

    envconfig = app.get_resource_config(request.args['env'])
    return {'r': 0, 'msg': 'ok', 'data': envconfig.to_env_dict()}
Ejemplo n.º 2
0
def get_app_env(name):
    app = App.get_by_name(name)
    if not app:
        raise EruAbortException(consts.HTTP_BAD_REQUEST, "App %s not found, env list ignored" % name)

    envconfig = app.get_resource_config(request.args["env"])
    return {"r": 0, "msg": "ok", "data": envconfig.to_env_dict()}
Ejemplo n.º 3
0
def alloc_resource(name, env, res_name, res_alias):
    app = App.get_by_name(name)
    if not app:
        raise EruAbortException(code.HTTP_NOT_FOUND)

    r = RESOURCES.get(res_name)
    if not r:
        raise EruAbortException(code.HTTP_NOT_FOUND, '%s doesn\'t exist' % res_name)

    envconfig = app.get_resource_config(env)
    if envconfig.get(res_alias):
        raise EruAbortException(code.HTTP_CONFLICT, '%s already in env' % res_alias)

    try:
        mod = import_string(r)
        args = inspect.getargspec(mod.alloc)
        data = request.get_json()
        if set(data.iterkeys()) >= set(args.args[1:]):
            raise Exception()
        result = mod.alloc(**data)
        envconfig[res_alias] = result
        envconfig.save()
    except Exception, e:
        current_app.logger.exception(e)
        raise EruAbortException(code.HTTP_BAD_REQUEST, 'Error in creating %s' % res_name)
Ejemplo n.º 4
0
def list_app_containers(name):
    app = App.get_by_name(name)
    if not app:
        logger.error('app not found, env list ignored')
        raise EruAbortException(code.HTTP_BAD_REQUEST, 'App %s not found, env list ignored' % name)
    containers = app.containers.all()
    return {'r': 0, 'msg': 'ok', 'containers': containers}
Ejemplo n.º 5
0
def list_app_env(name):
    app = App.get_by_name(name)
    if not app:
        logger.error('app not found, env set ignored')
        raise EruAbortException(code.HTTP_BAD_REQUEST)

    return {'r': 0, 'msg': 'ok', 'data': app.list_resource_config()}
Ejemplo n.º 6
0
def list_version_tasks(name, version):
    app = App.get_by_name(name)
    if not app:
        raise EruAbortException(consts.HTTP_BAD_REQUEST, "App %s not found, env list ignored" % name)
    v = app.get_version(version)
    if not v:
        raise EruAbortException(consts.HTTP_NOT_FOUND, "Version %s not found" % version)
    return {"r": 0, "msg": "ok", "tasks": v.list_tasks(g.start, g.limit)}
Ejemplo n.º 7
0
def list_version_tasks(name, version):
    app = App.get_by_name(name)
    if not app:
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'App %s not found, env list ignored' % name)
    v = app.get_version(version)
    if not v:
        raise EruAbortException(consts.HTTP_NOT_FOUND, 'Version %s not found' % version)
    return {'r': 0, 'msg': 'ok', 'tasks': v.list_tasks(g.start, g.limit)}
Ejemplo n.º 8
0
def _get_app_and_version(appname, version, **kwargs):
    app = App.get_by_name(appname)
    if not app:
        abort(400, 'App `%s` not found' % appname)

    version = app.get_version(version)
    if not version:
        abort(400, 'Version `%s` not found' % version)
    return app, version
Ejemplo n.º 9
0
def list_version_containers(name, version):
    app = App.get_by_name(name)
    if not app:
        logger.error('app not found, env list ignored')
        raise EruAbortException(code.HTTP_BAD_REQUEST, 'App %s not found, env list ignored' % name)
    v = app.get_version(version)
    if not v:
        raise EruAbortException(code.HTTP_NOT_FOUND, 'Version %s not found' % version)
    return {'r': 0, 'msg': 'ok', 'containers': v.list_containers(g.start, g.limit)}
Ejemplo n.º 10
0
def get_version(name, version):
    app = App.get_by_name(name)
    if not app:
        raise EruAbortException(consts.HTTP_NOT_FOUND, 'App %s not found' % name)

    v = app.get_version(version)
    if not v:
        raise EruAbortException(consts.HTTP_NOT_FOUND, 'Version %s not found' % version)
    return v
Ejemplo n.º 11
0
def set_app_env(name):
    app = App.get_by_name(name)
    if not app:
        logger.error('app not found, env set ignored')
        raise EruAbortException(code.HTTP_BAD_REQUEST, 'App %s not found, env set ignored' % name)

    data = request.get_json()
    env = data.pop('env')
    envconfig = app.get_resource_config(env)
    envconfig.update(**data)
    envconfig.save()
    return {'r': 0, 'msg': 'ok'}
Ejemplo n.º 12
0
def set_app_env(name):
    data = request.get_json()
    env = data.pop('env')

    app = App.get_by_name(name)
    if not app:
        current_app.logger.error('App (name=%s) not found, env (env=%s) set ignored.', name, env)
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'App %s not found, env set ignored' % name)

    envconfig = app.get_resource_config(env)
    envconfig.update(**data)
    envconfig.save()
    current_app.logger.error('App (name=%s) set env (env=%s) values done', name, env)
    return {'r': 0, 'msg': 'ok'}
Ejemplo n.º 13
0
def set_app_env(name):
    data = request.get_json()
    env = data.pop("env")

    app = App.get_by_name(name)
    if not app:
        current_app.logger.error("App (name=%s) not found, env (env=%s) set ignored.", name, env)
        raise EruAbortException(consts.HTTP_BAD_REQUEST, "App %s not found, env set ignored" % name)

    envconfig = app.get_resource_config(env)
    envconfig.update(**data)
    envconfig.save()
    current_app.logger.error("App (name=%s) set env (env=%s) values done", name, env)
    return {"r": 0, "msg": "ok"}
Ejemplo n.º 14
0
def touch_version_scale_info(name, version):
    app = App.get_by_name(name)
    if not app:
        raise EruAbortException(code.HTTP_NOT_FOUND, 'App %s not found' % name)
    v = app.get_version(version)
    if not v:
        raise EruAbortException(code.HTTP_NOT_FOUND, 'Version %s not found' % version)
    containers = v.containers.limit(1).all()
    if not containers:
        raise EruAbortException(code.HTTP_NOT_FOUND, 'Not deployed')
    container = containers[0]
    return {
        'group': container.host.group.name,
        'pod': container.host.pod.name,
        'ncore': len(container.cores.all())
    }
Ejemplo n.º 15
0
def validate_instance(group_name, pod_name, appname, version):
    group = Group.get_by_name(group_name)
    if not group:
        abort(400, 'Group `%s` not found' % group_name)

    pod = Pod.get_by_name(pod_name)
    if not pod:
        abort(400, 'Pod `%s` not found' % pod_name)

    app = App.get_by_name(appname)
    if not app:
        abort(400, 'App `%s` not found' % appname)

    version = app.get_version(version)
    if not version:
        abort(400, 'Version `%s` not found' % version)

    return group, pod, app, version
Ejemplo n.º 16
0
def validate_instance(group_name, pod_name, appname, version):
    group = Group.get_by_name(group_name)
    if not group:
        raise EruAbortException(code.HTTP_BAD_REQUEST, 'Group `%s` not found' % group_name)

    pod = Pod.get_by_name(pod_name)
    if not pod:
        raise EruAbortException(code.HTTP_BAD_REQUEST, 'Pod `%s` not found' % pod_name)

    application = App.get_by_name(appname)
    if not application:
        raise EruAbortException(code.HTTP_BAD_REQUEST, 'App `%s` not found' % appname)

    version = application.get_version(version)
    if not version:
        raise EruAbortException(code.HTTP_BAD_REQUEST, 'Version `%s` not found' % version)

    return group, pod, application, version
Ejemplo n.º 17
0
def clean_app(app_name):
    app = App.get_by_name(app_name)
    if not app:
        print 'app %s not found' % app_name
        return

    containers = app.list_containers(limit=None)
    version_dict = {}
    for c in containers:
        if not c:
            continue
        version_dict.setdefault((c.version, c.host), []).append(c)
    for (version, host), cs in version_dict.iteritems():
        cids = [c.id for c in cs]
        task_props = {'container_ids': cids}
        task = Task.create(TASK_REMOVE, version, host, task_props)
        remove_containers.apply_async(args=(task.id, cids, False),
                                      task_id='task:%s' % task.id)
        print task
    print 'done, waiting...'
Ejemplo n.º 18
0
def clean_app(app_name):
    app = App.get_by_name(app_name)
    if not app:
        print 'app %s not found' % app_name
        return

    containers = app.list_containers(limit=None)
    version_dict = {}
    for c in containers:
        if not c:
            continue
        version_dict.setdefault((c.version, c.host), []).append(c)
    for (version, host), cs in version_dict.iteritems():
        cids = [c.id for c in cs]
        task_props = {'container_ids': cids}
        task = Task.create(TASK_REMOVE, version, host, task_props)
        remove_containers.apply_async(
            args=(task.id, cids, False), task_id='task:%s' % task.id
        )
        print task
    print 'done, waiting...'
Ejemplo n.º 19
0
def get_app(name):
    app = App.get_by_name(name)
    if not app:
        raise EruAbortException(consts.HTTP_NOT_FOUND, 'App %s not found' % name)
    return app
Ejemplo n.º 20
0
def list_app_versions(name):
    app = App.get_by_name(name)
    if not app:
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'App %s not found, version list ignored' % name)
    return {'r': 0, 'msg': 'ok', 'versions': app.list_versions(g.start, g.limit)}
Ejemplo n.º 21
0
def list_app_tasks(name):
    app = App.get_by_name(name)
    if not app:
        raise EruAbortException(code.HTTP_BAD_REQUEST, 'App %s not found, container list ignored' % name)
    return {'r': 0, 'msg': 'ok', 'tasks': app.list_tasks(g.start, g.limit)}
Ejemplo n.º 22
0
def list_app_versions(name):
    app = App.get_by_name(name)
    if not app:
        raise EruAbortException(consts.HTTP_BAD_REQUEST, "App %s not found, version list ignored" % name)
    return {"r": 0, "msg": "ok", "versions": app.list_versions(g.start, g.limit)}
Ejemplo n.º 23
0
def _get_app_by_name(name):
    app = App.get_by_name(name)
    if not app:
        abort(404, 'App %s not found' % name)
    return app
Ejemplo n.º 24
0
def list_app_env(name):
    app = App.get_by_name(name)
    if not app:
        raise EruAbortException(consts.HTTP_BAD_REQUEST)
    return {"r": 0, "msg": "ok", "data": app.list_resource_config()}
Ejemplo n.º 25
0
def list_app_env(name):
    app = App.get_by_name(name)
    if not app:
        raise EruAbortException(consts.HTTP_BAD_REQUEST)
    return {'r': 0, 'msg': 'ok', 'data': app.list_resource_config()}
Ejemplo n.º 26
0
Archivo: app.py Proyecto: CMGS/eru-core
def _get_app_by_name(name):
    app = App.get_by_name(name)
    if not app:
        abort(404, 'App %s not found' % name)
    return app