def rm_containers(): cids = request.get_json()['cids'] if not all(len(cid) >= 7 for cid in cids): abort(400, 'must given at least 7 chars for container_id') version_dict = {} for cid in cids: container = Container.get_by_container_id(cid) if not container: continue version_dict.setdefault((container.version, container.host), []).append(container) ts, watch_keys = [], [] for (version, host), containers in version_dict.iteritems(): cids = [c.id for c in containers] task = Task.create(consts.TASK_REMOVE, version, host, {'container_ids': cids}) all_host_cids = [c.id for c in Container.get_multi_by_host(host) if c and c.version_id == version.id] need_to_delete_image = set(cids) == set(all_host_cids) remove_containers.apply_async( args=(task.id, cids, need_to_delete_image), task_id='task:%d' % task.id ) ts.append(task.id) watch_keys.append(task.result_key) return {'r': 0, 'msg': 'ok', 'tasks': ts, 'watch_keys': watch_keys}
def fix_core(host): containers = Container.get_multi_by_host(host) # 没有的话, 直接销毁重建 if not containers: rds.delete(host._cores_key) _create_cores_on_host(host, host.ncore) return data = {str(i): host.core_share for i in xrange(host.ncore)} for c in containers: cores = c.cores nshare = int(cores.get("nshare", "0")) for e in cores.get("full", []): e.remain = host.core_share data.pop(e.label) for s in cores.get("part", []): s.remain = host.core_share - nshare data[s.label] -= nshare c.cores = cores rds.delete(host._cores_key) if data: rds.zadd(host._cores_key, **data) print "done", host
def rm_containers(): cids = request.get_json()['cids'] if not all(len(cid) >= 7 for cid in cids): abort(400, 'must given at least 7 chars for container_id') version_dict = {} for cid in cids: container = Container.get_by_container_id(cid) if not container: continue version_dict.setdefault((container.version, container.host), []).append(container) task_ids, watch_keys = [], [] for (version, host), containers in version_dict.iteritems(): cids = [c.id for c in containers] task = Task.create(TASK_REMOVE, version, host, {'container_ids': cids}) all_host_cids = [c.id for c in Container.get_multi_by_host(host) if c and c.version_id == version.id] need_to_delete_image = set(cids) == set(all_host_cids) remove_containers.apply_async( args=(task.id, cids, need_to_delete_image), task_id='task:%d' % task.id ) task_ids.append(task.id) watch_keys.append(task.result_key) return {'tasks': task_ids, 'watch_keys': watch_keys}
def fix_core(host): containers = Container.get_multi_by_host(host) # 没有的话, 直接销毁重建 if not containers: _create_cores_on_host(host, host.ncore) return data = {str(i): host.core_share for i in xrange(host.ncore)} for c in containers: cores = c.cores nshare = int(cores.get('nshare', '0')) for e in cores.get('full', []): e.remain = host.core_share data.pop(e.label) for s in cores.get('part', []): s.remain = host.core_share - nshare data[s.label] -= nshare c.cores = cores rds.delete(host._cores_key) if data: rds.zadd(host._cores_key, **data) print 'done', host
def migrate_container_set(host): containers = Container.get_multi_by_host(host) for c in containers: add_container_for_agent(c)