在E:\nova\nova\api\openstack\compute\admin_actions.py 路径下定义了admin的网络的api接口
class AdminActionsController(wsgi.Controller):
def __init__(self, *args, **kwargs):
super(AdminActionsController, self).__init__(*args, **kwargs)
self.compute_api = compute.API()
@wsgi.response(202)
@extensions.expected_errors((404, 409))
@wsgi.action('resetNetwork')
def _reset_network(self, req, id, body):
"""Permit admins to reset networking on a server."""
context = req.environ['nova.context']
context.can(aa_policies.POLICY_ROOT % 'reset_network')
instance = common.get_instance(self.compute_api, context, id)
try:
self.compute_api.reset_network(context, instance)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())
例如这里定义的resetNetwork。可见最终调用common得到网络对应的instance,然后调用compute的reset_network 函数来reset这个instance对应的网络
这里的common赋值为:from nova.api.openstack import common
E:\nova\nova\api\openstack\common.py
def get_instance(compute_api, context, instance_id, expected_attrs=None):
"""Fetch an instance from the compute API, handling error checking."""
try:
return compute_api.get(context, instance_id,
expected_attrs=expected_attrs)
except exception.InstanceNotFound as e:
raise exc.HTTPNotFound(explanation=e.format_message())
可见还是调用computer的get函数得到instance.
nova中的API中的AdminActionsController入口
最新推荐文章于 2022-05-17 09:31:02 发布