输入neutron router-update 参数执行后,neutron-server收到neutronclient发来的http请求后,根据路由映射选择相应的controller下的函数。
1.neutron/api/v2/base.py(493)update():所有的关于update操作都将在这处理
def update(self, request, id, body=None, **kwargs):
"""Updates the specified entity's attributes."""
parent_id = kwargs.get(self._parent_id_name)
try:
payload = body.copy()#body是请求部分,在这里body里包含了传过来的路由信息
except AttributeError:
msg = _("Invalid format: %s") % request.body
raise exceptions.BadRequest(resource='body', msg=msg)
payload['id'] = id#id是路由器的id
self._notifier.info(request.context,
self._resource + '.update.start', payload)
body = Controller.prepare_request_body(request.context, body, False,
self._resource, self._attr_info,
allow_bulk=self._allow_bulk)#路由信息
action = self._plugin_handlers[self.UPDATE]
# Load object to check authz
# but pass only attributes in the original body and required
# by the policy engine to the policy 'brain'
field_list = [name for (name, value) in self._attr_info.iteritems()
if (value.get('required_by_policy') or
value.get('primary_key') or
'default' not in value)] #field_list是orig_obj
policy.init()
orig_obj = self._item(request, id, field_list=field_list,
parent_id=parent_id)
orig_object_copy = copy.copy(orig_obj)
orig_obj.update(body[self._resource])
# Ensure policy engine is initialized
policy.init()orig_obj[const.ATTRIBUTES_TO_UPDATE] = body[self._resource].k