本文整理汇总了Python中eru.models.Host.get_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Host.get_by_name方法的具体用法?Python Host.get_by_name怎么用?Python Host.get_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eru.models.Host
的用法示例。
在下文中一共展示了Host.get_by_name方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_host
# 需要导入模块: from eru.models import Host [as 别名]
# 或者: from eru.models.Host import get_by_name [as 别名]
def _get_host(id_or_name):
if id_or_name.isdigit():
host = Host.get(id_or_name)
else:
host = Host.get_by_name(id_or_name)
if not host:
abort(404, 'Host %s not found' % id_or_name)
return host
示例2: create_private
# 需要导入模块: from eru.models import Host [as 别名]
# 或者: from eru.models.Host import get_by_name [as 别名]
def create_private():
data = request.get_json()
pod, _, version = _get_instances(**data)
ncore, nshare = pod.get_core_allocation(float(data['ncore']))
ports = data.get('ports', [])
args = data.get('args', [])
strategy = data.get('strategy', 'average')
callback_url = data.get('callback_url', '')
if callback_url and not is_strict_url(callback_url):
abort(400, 'callback_url must start with http:// or https://')
ncontainer = int(data['ncontainer'])
if not ncontainer:
abort(400, 'ncontainer must be > 0')
networks = [ipam.get_pool(n) for n in data.get('networks', [])]
spec_ips = data.get('spec_ips', [])
appconfig = version.appconfig
entrypoint = data['entrypoint']
if entrypoint not in appconfig.entrypoints:
abort(400, 'Entrypoint %s not in app.yaml' % entrypoint)
hostname = data.get('hostname', '')
host = hostname and Host.get_by_name(hostname) or None
task_ids, watch_keys = [], []
host_cores = _get_strategy(strategy)(pod, ncontainer, ncore, nshare, host)
if not host_cores:
abort(400, 'Not enough core resources')
for (host, container_count), cores in host_cores.iteritems():
t = _create_task(
version,
host,
container_count,
cores,
nshare,
networks,
ports,
args,
spec_ips,
entrypoint,
data['env'],
image=data.get('image', ''),
callback_url=callback_url,
)
if not t:
continue
host.occupy_cores(cores, nshare)
task_ids.append(t.id)
watch_keys.append(t.result_key)
return {'tasks': task_ids, 'watch_keys': watch_keys}
示例3: create_private
# 需要导入模块: from eru.models import Host [as 别名]
# 或者: from eru.models.Host import get_by_name [as 别名]
def create_private(group_name, pod_name, appname):
"""ncore: 需要的核心数, 可以是小数, 例如1.5个"""
data = request.get_json()
if data.get('raw', ''):
vstr = consts.RAW_VERSION_PLACEHOLDER
else:
vstr = data['version']
group, pod, application, version = validate_instance(group_name,
pod_name, appname, vstr)
# TODO check if group has this pod
core_require = int(float(data['ncore']) * pod.core_share) # 是说一个容器要几个核...
ncore = core_require / pod.core_share
nshare = core_require % pod.core_share
ncontainer = int(data['ncontainer'])
networks = Network.get_multi(data.get('networks', []))
spec_ips = data.get('spec_ips', [])
appconfig = version.appconfig
# 指定的host, 如果没有则按照编排分配host
hostname = data.get('hostname', '')
host = hostname and Host.get_by_name(hostname) or None
if host and not (host.group_id == group.id and host.pod_id == pod.id):
current_app.logger.error('Host must belong to pod/group (hostname=%s, pod=%s, group=%s)',
host, pod_name, group_name)
raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Host must belong to this pod and group')
if not data['entrypoint'] in appconfig.entrypoints:
current_app.logger.error('Entrypoint not in app.yaml (entry=%s, name=%s, version=%s)',
data['entrypoint'], appname, version.short_sha)
raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Entrypoint %s not in app.yaml' % data['entrypoint'])
ts, keys = [], []
with rds.lock('%s:%s' % (group_name, pod_name)):
host_cores = group.get_free_cores(pod, ncontainer, ncore, nshare, spec_host=host)
if not host_cores:
current_app.logger.error('Not enough cores (name=%s, version=%s, ncore=%s)',
appname, version.short_sha, data['ncore'])
raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Not enough core resources')
for (host, container_count), cores in host_cores.iteritems():
t = _create_task(consts.TASK_CREATE, version, host, container_count,
cores, nshare, networks, spec_ips, data['entrypoint'], data['env'],
image=data.get('image', ''))
if not t:
continue
host.occupy_cores(cores, nshare)
ts.append(t.id)
keys.append(t.result_key)
return {'r': 0, 'msg': 'ok', 'tasks': ts, 'watch_keys': keys}
示例4: rm_containers
# 需要导入模块: from eru.models import Host [as 别名]
# 或者: from eru.models.Host import get_by_name [as 别名]
def rm_containers(group_name, pod_name, appname):
data = request.get_json()
group, pod, application, version = validate_instance(group_name,
pod_name, appname, data['version'])
host = Host.get_by_name(data['host'])
# 直接拿前ncontainer个吧, 反正他们都等价的
containers = host.get_containers_by_version(version)[:int(data['ncontainer'])]
try:
cids = [c.id for c in containers]
task_props = {'container_ids': cids}
task = Task.create(code.TASK_REMOVE, version, host, task_props)
remove_containers.apply_async(
args=(task.id, cids, False),
task_id='task:%d' % task.id
)
return {'r': 0, 'msg': 'ok', 'task': task.id, 'watch_key': task.result_key}
except Exception, e:
logger.exception(e)
return {'r': 1, 'msg': str(e), 'task': None, 'watch_key': None}
示例5: _get_host
# 需要导入模块: from eru.models import Host [as 别名]
# 或者: from eru.models.Host import get_by_name [as 别名]
def _get_host(id_or_name):
if id_or_name.isdigit():
return Host.get(id_or_name)
return Host.get_by_name(id_or_name)
示例6: create_private
# 需要导入模块: from eru.models import Host [as 别名]
# 或者: from eru.models.Host import get_by_name [as 别名]
def create_private(group_name, pod_name, appname):
data = request.get_json()
vstr = data['version']
group, pod, _, version = validate_instance(group_name, pod_name, appname, vstr)
# TODO check if group has this pod
ncore, nshare = pod.get_core_allocation(float(data['ncore']))
ports = data.get('ports', [])
args = data.get('args', [])
strategy = data.get('strategy', 'average')
callback_url = data.get('callback_url', '')
if callback_url and not is_strict_url(callback_url):
abort(400, 'callback_url must start with http:// or https://')
ncontainer = int(data['ncontainer'])
if not ncontainer:
abort(400, 'ncontainer must be > 0')
networks = Network.get_multi(data.get('networks', []))
spec_ips = data.get('spec_ips', [])
appconfig = version.appconfig
entrypoint = data['entrypoint']
if entrypoint not in appconfig.entrypoints:
abort(400, 'Entrypoint %s not in app.yaml' % entrypoint)
hostname = data.get('hostname', '')
host = hostname and Host.get_by_name(hostname) or None
if host and not (host.group_id == group.id and host.pod_id == pod.id):
abort(400, 'Host must belong to this pod and group')
ts, keys = [], []
with rds.lock('%s:%s' % (group_name, pod_name)):
host_cores = _get_strategy(strategy)(group, pod, ncontainer, ncore, nshare, host)
if not host_cores:
abort(400, 'Not enough core resources')
for (host, container_count), cores in host_cores.iteritems():
t = _create_task(
version,
host,
container_count,
cores,
nshare,
networks,
ports,
args,
spec_ips,
entrypoint,
data['env'],
image=data.get('image', ''),
callback_url=callback_url,
)
if not t:
continue
host.occupy_cores(cores, nshare)
ts.append(t.id)
keys.append(t.result_key)
return {'r': 0, 'msg': 'ok', 'tasks': ts, 'watch_keys': keys}
示例7: list_host_containers
# 需要导入模块: from eru.models import Host [as 别名]
# 或者: from eru.models.Host import get_by_name [as 别名]
def list_host_containers(host_name):
host = Host.get_by_name(host_name)
if not host:
raise EruAbortException(code.HTTP_NOT_FOUND, 'Host %s not found' % host_name)
containers = host.list_containers(g.start, g.limit)
return {'r': 0, 'msg': code.OK, 'containers': containers}
示例8: cure_host
# 需要导入模块: from eru.models import Host [as 别名]
# 或者: from eru.models.Host import get_by_name [as 别名]
def cure_host(host_name):
host = Host.get_by_name(host_name)
if host:
host.cure()
return {'r': 0, 'msg': code.OK}
示例9: kill_host
# 需要导入模块: from eru.models import Host [as 别名]
# 或者: from eru.models.Host import get_by_name [as 别名]
def kill_host(host_name):
host = Host.get_by_name(host_name)
if host:
host.kill()
return {'r': 0, 'msg': code.OK}
示例10: get_host_by_name
# 需要导入模块: from eru.models import Host [as 别名]
# 或者: from eru.models.Host import get_by_name [as 别名]
def get_host_by_name(host_name):
host = Host.get_by_name(host_name)
if not host:
raise EruAbortException(code.HTTP_NOT_FOUND, 'Host %s not found' % host_name)
return host
示例11: _get_host
# 需要导入模块: from eru.models import Host [as 别名]
# 或者: from eru.models.Host import get_by_name [as 别名]
def _get_host(id_or_name):
host = Host.get(id_or_name) or Host.get_by_name(id_or_name)
if not host:
abort(404, 'Host %s not found' % id_or_name)
return host
示例12: create_private
# 需要导入模块: from eru.models import Host [as 别名]
# 或者: from eru.models.Host import get_by_name [as 别名]
def create_private(group_name, pod_name, appname):
"""ncore: 需要的核心数, 可以是小数, 例如1.5个"""
data = request.get_json()
if data.get("raw", ""):
vstr = consts.RAW_VERSION_PLACEHOLDER
else:
vstr = data["version"]
group, pod, application, version = validate_instance(group_name, pod_name, appname, vstr)
# TODO check if group has this pod
core_require = int(float(data["ncore"]) * pod.core_share) # 是说一个容器要几个核...
ncore = core_require / pod.core_share
nshare = core_require % pod.core_share
ncontainer = int(data["ncontainer"])
networks = Network.get_multi(data.get("networks", []))
spec_ips = data.get("spec_ips", [])
appconfig = version.appconfig
# 指定的host, 如果没有则按照编排分配host
hostname = data.get("hostname", "")
host = hostname and Host.get_by_name(hostname) or None
if host and not (host.group_id == group.id and host.pod_id == pod.id):
current_app.logger.error(
"Host must belong to pod/group (hostname=%s, pod=%s, group=%s)", host, pod_name, group_name
)
raise EruAbortException(consts.HTTP_BAD_REQUEST, "Host must belong to this pod and group")
if not data["entrypoint"] in appconfig.entrypoints:
current_app.logger.error(
"Entrypoint not in app.yaml (entry=%s, name=%s, version=%s)", data["entrypoint"], appname, version.short_sha
)
raise EruAbortException(consts.HTTP_BAD_REQUEST, "Entrypoint %s not in app.yaml" % data["entrypoint"])
ts, keys = [], []
with rds.lock("%s:%s" % (group_name, pod_name)):
host_cores = group.get_free_cores(pod, ncontainer, ncore, nshare, spec_host=host)
if not host_cores:
current_app.logger.error(
"Not enough cores (name=%s, version=%s, ncore=%s)", appname, version.short_sha, data["ncore"]
)
raise EruAbortException(consts.HTTP_BAD_REQUEST, "Not enough core resources")
for (host, container_count), cores in host_cores.iteritems():
t = _create_task(
consts.TASK_CREATE,
version,
host,
container_count,
cores,
nshare,
networks,
spec_ips,
data["entrypoint"],
data["env"],
image=data.get("image", ""),
)
if not t:
continue
host.occupy_cores(cores, nshare)
ts.append(t.id)
keys.append(t.result_key)
return {"r": 0, "msg": "ok", "tasks": ts, "watch_keys": keys}
示例13: create_private
# 需要导入模块: from eru.models import Host [as 别名]
# 或者: from eru.models.Host import get_by_name [as 别名]
def create_private(group_name, pod_name, appname):
"""ncore: 需要的核心数, 可以是小数, 例如1.5个"""
data = request.get_json()
vstr = data['version']
group, pod, application, version = validate_instance(group_name,
pod_name, appname, vstr)
# TODO check if group has this pod
core_require = int(float(data['ncore']) * pod.core_share) # 是说一个容器要几个核...
ncore = core_require / pod.core_share
nshare = core_require % pod.core_share
ports = data.get('ports', [])
args = data.get('args', [])
ncontainer = int(data['ncontainer'])
networks = Network.get_multi(data.get('networks', []))
spec_ips = data.get('spec_ips', [])
entrypoint = data['entrypoint']
appconfig = version.appconfig
strategy = data.get('strategy', 'average')
# 指定的host, 如果没有则按照编排分配host
hostname = data.get('hostname', '')
host = hostname and Host.get_by_name(hostname) or None
if host and not (host.group_id == group.id and host.pod_id == pod.id):
current_app.logger.error('Host must belong to pod/group (hostname=%s, pod=%s, group=%s)',
host, pod_name, group_name)
raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Host must belong to this pod and group')
if not entrypoint in appconfig.entrypoints:
current_app.logger.error('Entrypoint not in app.yaml (entry=%s, name=%s, version=%s)',
entrypoint, appname, version.short_sha)
raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Entrypoint %s not in app.yaml' % entrypoint)
route = appconfig.entrypoints[entrypoint].get('network_route', '')
ts, keys = [], []
with rds.lock('%s:%s' % (group_name, pod_name)):
if strategy == 'average':
host_cores = average_schedule(group, pod, ncontainer, ncore, nshare, spec_host=host)
elif strategy == 'centralized':
host_cores = centralized_schedule(group, pod, ncontainer, ncore, nshare, spec_host=host)
else:
raise EruAbortException(consts.HTTP_BAD_REQUEST, 'strategy %s not supported' % strategy)
if not host_cores:
current_app.logger.error('Not enough cores (name=%s, version=%s, ncore=%s)',
appname, version.short_sha, data['ncore'])
raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Not enough core resources')
for (host, container_count), cores in host_cores.iteritems():
t = _create_task(
version,
host,
container_count,
cores,
nshare,
networks,
ports,
args,
spec_ips,
route,
data['entrypoint'],
data['env'],
image=data.get('image', ''),
)
if not t:
continue
host.occupy_cores(cores, nshare)
ts.append(t.id)
keys.append(t.result_key)
return {'r': 0, 'msg': 'ok', 'tasks': ts, 'watch_keys': keys}