小菜openstack nova 源码学习之 force_down

今天学习下,L版新增apiforce_down

nova.api.openstack.compute:_forced_down

def _forced_down(self, body, context):

   """Set or unset forced_down flag for the service"""

   //前面都是一系列的赋值

   try:

      forced_down = body["forced_down"]

   except KeyError:

   msg = _('Missing forced_down field')

   raise webob.exc.HTTPBadRequest(explanation=msg)


   host = body['host']

   binary = body['binary']


ret_value = {'service': {'host': host,

              'binary': binary,

              'forced_down': forced_down}}

//调用 _update处理

self._update(context, host, binary, {"forced_down":forced_down})

    return ret_value

//当前py文件下找到该函数

def _update(self, context, host, binary, payload):

 """Do the actual PUT/update"""

  try:

   //继续调用host_api service_update

     self.host_api.service_update(context, host, binary, payload)

     except exception.HostBinaryNotFound as exc:

     raise webob.exc.HTTPNotFound(explanation=exc.format_message())

//进入nova.compute.api:HOSTAPI

def service_update(self,context, host_name, binary, params_to_update):

//继续转移

return self._service_update(context,host_name, binary,

                           params_to_update)

//进入_service_update函数

def _service_update(self,context, host_name, binary, params_to_update):

"""Performsthe actual service update operation."""

   service= objects.Service.get_by_args(context, host_name, binary)

   service.update(params_to_update)

   service.save()

   return service

//上面的service是从 get_by_args返回的数据,进去看看

def get_by_args(cls, context, host, binary):

  db_service= db.service_get_by_host_and_binary(context, host, binary)

  return cls._from_db_object(context, cls(), db_service)

//继续

  def _from_db_object(context, service, db_service):

  //最终返回的就是传过来的参数 service ,而这个参数就是 cls(),确实没有想明白这个是什么,突然冒出来了,返回service,继续执行后面的         service.update更新数据, service.save保存


还望大神指点 上述的 update save 跑到哪里去了

service.update(params_to_update)

service.save()

今天先写到这里,等我用rdo搭建一个L版的,调试跟踪下代码,看看具体流程,这样只是看源码,太多地方看不懂了




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值