nova update

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值