当前位置: 首页>>代码示例>>Python>>正文


Python models.App类代码示例

本文整理汇总了Python中eru.models.App的典型用法代码示例。如果您正苦于以下问题:Python App类的具体用法?Python App怎么用?Python App使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了App类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: list_app_env

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()}
开发者ID:lcsandy,项目名称:eru-core,代码行数:7,代码来源:app.py

示例2: create_local_test_data

def create_local_test_data(private=False):
    appyaml = {
        'appname': 'blueberry',
        'entrypoints': {
            'web': {
                'cmd': 'python app.py',
                'ports': ['5000/tcp'],
            },
            'daemon': {
                'cmd': 'python daemon.py',
            },
            'service': {
                'cmd': 'python service.py'
            },
        },
        'build': 'pip install -r ./requirements.txt',
    }
    app = App.get_or_create('blueberry', 'http://git.hunantv.com/tonic/blueberry.git', 'token')
    version = app.add_version('abe23812aeb50a17a2509c02a28423462161d306')
    appconfig = version.appconfig
    appconfig.update(**appyaml)
    appconfig.save()

    group = Group.create('group', 'group')
    pod = Pod.create('pod', 'pod')
    pod.assigned_to_group(group)

    c = docker.Client(**kwargs_from_env(assert_hostname=False))
    r = c.info()
    host = Host.create(pod, '192.168.59.103:2376', r['Name'], r['ID'], r['NCPU'], r['MemTotal'])

    if private:
        host.assigned_to_group(group)

    return app, version, group, pod, host
开发者ID:lcsandy,项目名称:eru-core,代码行数:35,代码来源:prepare.py

示例3: alloc_resource

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)
开发者ID:pugong,项目名称:eru-core,代码行数:25,代码来源:app.py

示例4: register_app_version

def register_app_version():
    data = request.get_json()
    version = data['version']

    appyaml = data['appyaml']
    if isinstance(appyaml, basestring):
        try:
            appyaml = yaml.load(appyaml)
        except yaml.error.YAMLError:
            abort(400, 'Error in app.yaml')

    try:
        verify_appconfig(appyaml)
    except (ValueError, KeyError) as e:
        abort(400, e.message)

    name = appyaml['appname']

    app = App.get_or_create(name, data['git'])

    v = app.add_version(version)
    if not v:
        _log.error('Version create failed. (name=%s, version=%s)', name, version[:7])
        abort(400, 'Version %s create failed' % version[:7])

    appconfig = v.appconfig
    appconfig.update(**appyaml)
    appconfig.save()

    _log.info('App-Version created. (name=%s, version=%s)', name, version[:7])
    return 201, DEFAULT_RETURN_VALUE
开发者ID:timfeirg,项目名称:eru-core,代码行数:31,代码来源:app.py

示例5: list_app_containers

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}
开发者ID:lcsandy,项目名称:eru-core,代码行数:7,代码来源:app.py

示例6: get_app_env

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()}
开发者ID:DoubleSpout,项目名称:eru-core,代码行数:7,代码来源:app.py

示例7: test_container_release_cores

def test_container_release_cores(test_db):
    a = App.get_or_create('app', 'http://git.hunantv.com/group/app.git')
    v = a.add_version(random_sha1())
    p = Pod.create('pod', 'pod', 10, -1)
    host = Host.create(p, random_ipv4(), random_string(), random_uuid(), 200, 0)

    for core in host.cores:
        assert core.host_id == host.id
        assert core.remain == 10

    containers = []
    
    cores = sorted(host.cores, key=operator.attrgetter('label'))
    for fcores, pcores in zip(chunked(cores[:100], 10), chunked(cores[100:], 10)):
        used_cores = {'full': fcores, 'part': pcores}
        host.occupy_cores(used_cores, 5)
        c = Container.create(random_sha1(), host, v, random_string(), 'entrypoint', used_cores, 'env', nshare=5)
        containers.append(c)

    cores = sorted(host.cores, key=operator.attrgetter('label'))
    for fcores, pcores in zip(chunked(cores[:100], 10), chunked(cores[100:], 10)):
        for core in fcores:
            assert core.remain == 0
        for core in pcores:
            assert core.remain == 5

    for c in containers:
        c.delete()

    cores = sorted(host.cores, key=operator.attrgetter('label'))
    for fcores, pcores in zip(chunked(cores[:100], 10), chunked(cores[100:], 10)):
        for core in fcores:
            assert core.remain == 10
        for core in pcores:
            assert core.remain == 10
开发者ID:timfeirg,项目名称:eru-core,代码行数:35,代码来源:test_models.py

示例8: register_app_version

def register_app_version():
    data = request.get_json()
    version = data['version']

    appyaml = data['appyaml']
    try:
        verify_appconfig(appyaml)
    except (ValueError, KeyError) as e:
        raise EruAbortException(consts.HTTP_BAD_REQUEST, e.message)

    name = appyaml['appname']

    app = App.get_or_create(name, data['git'], data['token'])
    if not app:
        current_app.logger.error('App create failed. (name=%s, version=%s)', name, version[:7])
        raise EruAbortException(consts.HTTP_BAD_REQUEST,
                'App %s create failed, maybe token duplicated' % name)

    v = app.add_version(version)
    if not v:
        current_app.logger.error('Version create failed. (name=%s, version=%s)', name, version[:7])
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Version %s create failed' % version[:7])

    appconfig = v.appconfig
    appconfig.update(**appyaml)
    appconfig.save()
    current_app.logger.info('App-Version created. (name=%s, version=%s)', name, version[:7])
    return {'r': 0, 'msg': 'ok'}
开发者ID:sdgdsffdsfff,项目名称:eru-core,代码行数:28,代码来源:app.py

示例9: list_version_tasks

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)}
开发者ID:sdgdsffdsfff,项目名称:eru-core,代码行数:8,代码来源:app.py

示例10: list_version_containers

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)}
开发者ID:mackjoner,项目名称:eru-core,代码行数:9,代码来源:app.py

示例11: get_version

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
开发者ID:sdgdsffdsfff,项目名称:eru-core,代码行数:9,代码来源:app.py

示例12: _get_app_and_version

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
开发者ID:timfeirg,项目名称:eru-core,代码行数:9,代码来源:deploy.py

示例13: set_app_env

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'}
开发者ID:lcsandy,项目名称:eru-core,代码行数:12,代码来源:app.py

示例14: test_container_transform

def test_container_transform(test_db):
    a = App.get_or_create('app', 'http://git.hunantv.com/group/app.git', '')
    assert a is not None

    v = a.add_version(random_sha1())
    v2 = a.add_version(random_sha1())
    assert v is not None
    assert v.app.id == a.id
    assert v.name == a.name
    assert len(v.containers.all()) == 0
    assert len(v.tasks.all()) == 0

    g = Group.create('group', 'group')
    p = Pod.create('pod', 'pod')
    assert p.assigned_to_group(g)
    hosts = [Host.create(p, random_ipv4(), random_string(prefix='host'),
        random_uuid(), 4, 4096) for i in range(6)]

    for host in hosts[:3]:
        host.assigned_to_group(g)

    assert g.get_max_containers(p, 3, 0) == 3
    host_cores = g.get_free_cores(p, 3, 3, 0)
    assert len(host_cores) == 3

    containers = []
    for (host, count), cores in host_cores.iteritems():
        cores_per_container = len(cores) / count
        for i in range(count):
            cid = random_sha1()
            used_cores = {'full': cores['full'][i*cores_per_container:(i+1)*cores_per_container]}
            c = Container.create(cid, host, v, random_string(), 'entrypoint', used_cores, 'env')
            assert c is not None
            containers.append(c)
        host.occupy_cores(cores, 0)

    for host in g.private_hosts.all():
        assert len(host.get_free_cores()[0]) == 1
        assert len(host.containers.all()) == 1
        assert host.count == 1

    assert len(containers) == 3
    assert len(v.containers.all()) == 3

    cids = [c.container_id for c in containers]
    for c in containers:
        host = c.host
        cid = c.container_id
        c.transform(v2, random_sha1(), random_string())
        assert c.container_id != cid

    new_cids = [c.container_id for c in containers]
    assert new_cids != cids
开发者ID:lcsandy,项目名称:eru-core,代码行数:53,代码来源:test_models.py

示例15: set_app_env

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"}
开发者ID:DoubleSpout,项目名称:eru-core,代码行数:14,代码来源:app.py


注:本文中的eru.models.App类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。