本文整理汇总了Python中eru.models.Group类的典型用法代码示例。如果您正苦于以下问题:Python Group类的具体用法?Python Group怎么用?Python Group使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Group类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list_group_pod
def list_group_pod(id_or_name):
if id_or_name.isdigit():
group = Group.get(int(id_or_name))
else:
group = Group.get_by_name(id_or_name)
if not group:
abort(404, 'Group %s not found' % id_or_name)
return group.list_pods(g.start, g.limit)
示例2: list_group_pod
def list_group_pod(id_or_name):
if id_or_name.isdigit():
group = Group.get(int(id_or_name))
else:
group = Group.get_by_name(id_or_name)
if not group:
raise EruAbortException(consts.HTTP_NOT_FOUND, 'Group %s not found' % id_or_name)
return group.list_pods(g.start, g.limit)
示例3: 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
示例4: _create_data
def _create_data(core_share, max_share_core, host_count):
group = Group.create('group', 'group')
pod = Pod.create('pod', 'pod', core_share, max_share_core)
for _ in range(host_count):
host = Host.create(pod, random_ipv4(), random_string(), random_uuid(), 16, 4096)
host.assigned_to_group(group)
return group, pod
示例5: create_group
def create_group():
data = request.get_json()
if not Group.create(data['name'], data.get('description', '')):
abort(400, 'Group create failed')
current_app.logger.info('Group create succeeded (name=%s, desc=%s)',
data['name'], data.get('description', ''))
return 201, {'r': 0, 'msg': consts.OK}
示例6: create_group
def create_group():
data = request.get_json()
if not Group.create(data['name'], data.get('description', '')):
raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Group create failed')
current_app.logger.info('Group create succeeded (name=%s, desc=%s)',
data['name'], data.get('description', ''))
return consts.HTTP_CREATED, {'r':0, 'msg': consts.OK}
示例7: assign_pod_to_group
def assign_pod_to_group(pod_name):
data = request.get_json()
group = Group.get_by_name(data['group_name'])
pod = Pod.get_by_name(pod_name)
if not group or not pod:
raise EruAbortException(code.HTTP_BAD_REQUEST)
if not pod.assigned_to_group(group):
raise EruAbortException(code.HTTP_BAD_REQUEST)
return {'r':0, 'msg': code.OK}
示例8: 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
示例9: group_max_containers
def group_max_containers(group_name):
pod_name = request.args.get('pod_name', type=str, default='')
cores_per_container = request.args.get('ncore', type=int, default=1)
group = Group.get_by_name(group_name)
if not group:
raise EruAbortException(code.HTTP_BAD_REQUEST)
pod = Pod.get_by_name(pod_name)
if not pod:
raise EruAbortException(code.HTTP_BAD_REQUEST)
return {'r':0, 'msg': code.OK, 'data': group.get_max_containers(pod, cores_per_container)}
示例10: assign_pod_to_group
def assign_pod_to_group(pod_name):
data = request.get_json()
group = Group.get_by_name(data['group_name'])
pod = Pod.get_by_name(pod_name)
if not group or not pod:
raise EruAbortException(consts.HTTP_BAD_REQUEST, 'No group/pod found')
if not pod.assigned_to_group(group):
raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Assign failed')
current_app.logger.info('Pod (name=%s) assigned to group (name=%s)',
pod_name, data['group_name'])
return {'r':0, 'msg': consts.OK}
示例11: assign_pod_to_group
def assign_pod_to_group(pod_name):
data = request.get_json()
group = Group.get_by_name(data['group_name'])
pod = Pod.get_by_name(pod_name)
if not group or not pod:
abort(404, 'No group/pod found')
if not pod.assigned_to_group(group):
abort(400, 'Assign failed')
current_app.logger.info('Pod (name=%s) assigned to group (name=%s)',
pod_name, data['group_name'])
return {'r':0, 'msg': consts.OK}
示例12: group_max_containers
def group_max_containers(group_name):
pod_name = request.args.get('pod_name', default='')
core_require = request.args.get('ncore', type=float, default=1)
group = Group.get_by_name(group_name)
if not group:
abort(400, 'No group found')
pod = Pod.get_by_name(pod_name)
if not pod:
abort(400, 'No pod found')
ncore, nshare = pod.get_core_allocation(core_require)
return {'r':0, 'msg': consts.OK, 'data': get_max_container_count(group, pod, ncore, nshare)}
示例13: test_get_max_container_count_single_host
def test_get_max_container_count_single_host(test_db):
group = Group.create('group', 'group')
pod = Pod.create('pod', 'pod', 10, -1)
host = Host.create(pod, random_ipv4(), random_string(), random_uuid(), 64, 4096)
host.assigned_to_group(group)
assert get_max_container_count(group, pod, ncore=1, nshare=0) == 64
assert get_max_container_count(group, pod, ncore=2, nshare=0) == 32
assert get_max_container_count(group, pod, ncore=3, nshare=0) == 21
assert get_max_container_count(group, pod, ncore=4, nshare=0) == 16
assert get_max_container_count(group, pod, ncore=5, nshare=0) == 12
assert get_max_container_count(group, pod, ncore=1, nshare=5) == 42
assert get_max_container_count(group, pod, ncore=2, nshare=5) == 25
示例14: assign_host_to_group
def assign_host_to_group(addr):
data = request.get_json()
group = Group.get_by_name(data['group_name'])
if not group:
raise EruAbortException(code.HTTP_BAD_REQUEST)
host = Host.get_by_addr(addr)
if not host:
raise EruAbortException(code.HTTP_BAD_REQUEST)
if not host.assigned_to_group(group):
raise EruAbortException(code.HTTP_BAD_REQUEST)
return {'r':0, 'msg': code.OK}
示例15: test_occupy_and_release_cores
def test_occupy_and_release_cores(test_db):
g = Group.create('group', 'group')
p = Pod.create('pod', 'pod', 10, -1)
host = Host.create(p, random_ipv4(), random_string(), random_uuid(), 200, 0)
assert p.assigned_to_group(g)
assert host.assigned_to_group(g)
for core in host.cores:
assert core.host_id == host.id
assert core.remain == 10
cores = {
'full': host.cores[:100],
'part': host.cores[100:],
}
host.occupy_cores(cores, 5)
for core in host.cores[:100]:
assert core.remain == 0
for core in host.cores[100:]:
assert core.remain == 5
host.release_cores(cores, 5)
for core in host.cores:
assert core.remain == 10
host.occupy_cores(cores, 8)
for core in host.cores[:100]:
assert core.remain == 0
for core in host.cores[100:]:
assert core.remain == 2
host.release_cores(cores, 8)
for core in host.cores:
assert core.remain == 10
cores = {
'full': host.cores[:50],
'part': host.cores[50:100],
}
host.occupy_cores(cores, 8)
for core in host.cores[:50]:
assert core.remain == 0
for core in host.cores[50:100]:
assert core.remain == 2
host.release_cores(cores, 8)
for core in host.cores:
assert core.remain == 10