def r_delete(ids): ret = dict() ret['state'] = ji.Common.exchange_state(20000) config = Config() config.id = 1 config.get() # 取全部活着的 hosts available_hosts = Host.get_available_hosts(nonrandom=None) if available_hosts.__len__() == 0: ret['state'] = ji.Common.exchange_state(50351) return ret chosen_host = available_hosts[0] node_id = chosen_host['node_id'] os_template_image = OSTemplateImage() # TODO: 加入对,是否有被 Guest 引用的判断 for _id in ids.split(','): os_template_image.id = _id os_template_image.get() for _id in ids.split(','): os_template_image.id = _id os_template_image.get() # 暂时不支持从计算节点上,删除公共镜像 if os_template_image.kind == OSTemplateImageKind.public.value: os_template_image.delete() continue elif os_template_image.kind == OSTemplateImageKind.custom.value: os_template_image.progress = 254 message = { '_object': 'os_template_image', 'action': 'delete', 'storage_mode': config.storage_mode, 'dfs_volume': config.dfs_volume, 'template_path': os_template_image.path, # uuid 这里没有实际意义,仅仅是为了迁就 JimV-C 的个命令格式 'uuid': None, 'node_id': node_id, 'os_template_image_id': os_template_image.id, 'passback_parameters': {'id': os_template_image.id} } Utils.emit_instruction(message=json.dumps(message)) os_template_image.update() return ret
def r_update(_id): os_template_image = OSTemplateImage() args_rules = [ Rules.ID.value ] if 'label' in request.json: args_rules.append( Rules.LABEL.value, ) if 'description' in request.json: args_rules.append( Rules.DESCRIPTION.value, ) if 'path' in request.json: args_rules.append( Rules.PATH.value, ) if 'active' in request.json: args_rules.append( Rules.ACTIVE.value, ) if 'logo' in request.json: args_rules.append( Rules.LOGO.value, ) if 'os_template_profile_id' in request.json: args_rules.append( Rules.OS_TEMPLATE_PROFILE_ID_EXT.value, ) if 'kind' in request.json: args_rules.append( Rules.OS_TEMPLATE_IMAGE_KIND.value, ) if args_rules.__len__() < 2: ret = dict() ret['state'] = ji.Common.exchange_state(20000) return ret request.json['id'] = _id try: ji.Check.previewing(args_rules, request.json) os_template_image.id = request.json.get('id') os_template_image.get() os_template_image.label = request.json.get('label', os_template_image.label) os_template_image.description = request.json.get('description', os_template_image.description) os_template_image.path = request.json.get('path', os_template_image.path) os_template_image.active = request.json.get('active', os_template_image.active) os_template_image.logo = request.json.get('logo', os_template_image.logo) os_template_image.os_template_profile_id = \ request.json.get('os_template_profile_id', os_template_image.os_template_profile_id) os_template_image.kind = request.json.get('kind', os_template_image.kind) os_template_image.update() os_template_image.get() ret = dict() ret['state'] = ji.Common.exchange_state(20000) ret['data'] = os_template_image.__dict__ return ret except ji.PreviewingError, e: return json.loads(e.message)