nova update
来源:互联网 发布:推荐算法的评价指标 编辑:程序博客网 时间:2024/06/06 17:13
update的入口代码在nova/api/openstack/compute/servers.py,方法是update(),如下 def update(self, req, id, body): """Update server then pass on to version-specific controller.""" ctxt = req.environ['nova.context']//update_dict 表示要更新的字典 update_dict = {}//根据id找到要更新的instance instance = self._get_server(ctxt, req, id, is_detail=True)//判断是否有权限权限更新instance ctxt.can(server_policies.SERVERS % 'update', target={'user_id': instance.user_id, 'project_id': instance.project_id}) server = body['server']//更新display_name if 'name' in server: update_dict['display_name'] = common.normalize_name( server['name'])//更新description if 'description' in server: # This is allowed to be None (remove description) update_dict['display_description'] = server['description'] helpers.translate_attributes(helpers.UPDATE, server, update_dict) try: instance = self.compute_api.update_instance(ctxt, instance, update_dict) return self._view_builder.show(req, instance, extend_address=False) except exception.InstanceNotFound: msg = _("Instance could not be found") raise exc.HTTPNotFound(explanation=msg)在__init__ 函数中self.compute_api = compute.API(),因此这里就转到 def update_instance(self, context, instance, updates): """Updates a single Instance object with some updates dict. Returns the updated instance. """ //如果instance设置了id的话,则直接调用instance.update 来更新,最后调用instance.save()来保存更新。 if instance.obj_attr_is_set('id'): instance.update(updates) inst_map = self._get_instance_map_or_none(context, instance.uuid) if inst_map and (inst_map.cell_mapping is not None): with nova_context.target_cell(context, inst_map.cell_mapping): instance.save() else: # If inst_map.cell_mapping does not point at a cell then cell # migration has not happened yet. # TODO(alaski): Make this a failure case after we put in # a block that requires migrating to cellsv2. instance.save() else: //如果这个instance没有设置id的话,则从更具instance的uuid找到这个instance,同样通过instance.update(updates)更新后,通过build_req.save()来保存 try: build_req = objects.BuildRequest.get_by_instance_uuid( context, instance.uuid) instance = build_req.instance instance.update(updates) build_req.save() except exception.BuildRequestNotFound: return instance总结一下nova的update函数从nova/api/openstack/compute/servers.py 中开始到nova/compute/api.py中结束。看起来这个函数只会更新instance的display_name和description 这两个字符串
阅读全文
0 0
- nova update
- nova
- 【Nova】nova-conductor学习
- 【Nova】nova-consoleauth学习
- 【Nova】nova-cert学习
- update
- update
- update
- update
- update
- update
- update
- update
- update
- update
- update
- update
- Update()
- A Zealer:王自如
- springMVC ajax执行后端不报错 前端报state是404
- Windows 工作环境及常用工具
- noteBook2.7-C#基础第七天
- LINTCODE——创建最大数
- nova update
- 22.jvm参数优化
- 全排列问题
- cordova 安装、运行
- TDDL-剖析淘宝TDDL
- 阿里云带领云通信进入2.0时代
- MyEclipse创建多模块maven项
- 【转载】ubuntu临时修改ip地址
- 图像处理-线性空间滤波