In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article shows you how to carry out openstack core routing and extension routing and the corresponding api function call process analysis, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.
The key points of this article are: splicing url from the novaclient layer, how to map to the underlying route, and how to find the api entry to execute the code according to the underlying route entry:
1. Start with the novaclient layer (create an instance as an example):
Vim / usr/lib/python2.6/site-packages/novaclient/v1_1/servers.py
Trace the _ boot method:
Continue to trace the _ create () method:
According to the code:
_ resp, body= self.api.client.post (url, body=body)
You can see that the url for creating an instance is: / server, where body is the parameter passed to the lower layer, such as the memory size and quantity of the virtual machine.
The way to send url is POST. The second step is to find the route map for the url corresponding to this post in the published route.
2. Print out all the route of nova layer:
Vim / usr/lib/python2.6/site-packages/nova/api/openstack/__init__.py
Find the corresponding routes whose url is server:
By analyzing the route mapping relationship of wsgi in the previous article, the corresponding code is the create () method of the controller: for details, please refer to the article: wsgi-restful-routes for details.
At this point, you have reached the underlying create () api call of the nova module.
3. In view of the fact that there are many types of openstack published routes: core route release and extended route release, we will explain this in detail next:
First, summarize the relationship between routes and controller in the above steps:
The first step is if the corresponding route is found, for example:
So how do you find the release file code for the route next?
There are two types of code that publishes route in the openstack framework:
The first core route release: (the top border of the Eclipse screenshot shows the corresponding file path)
When the core route is published, it automatically corresponds to the core operation of CURD (add, delete, query and modify) to the route, that is, create, delete, index, and show,update. (these are automatically generated by the route framework)
Note: take the servers release of our office as an example: create, delete, index, show,update these five methods have routes framework to automatically generate mapping relations. The detail method is a custom method. therefore
If you need a custom method, you can refer to the detail method here to add it.
The second type of extended routing publication:
How to add a custom route here, please refer to the article: add api process detail (os-networks) to openstack-wsgi 's route.
4. When the url sent by novaclient finds the corresponding route, then route will, according to the field of url and the sending method of url (eg:POST, GET, PUT, etc.), in the corresponding
Controller finds the corresponding method to execute:
To create a virtual machine routing example:
POST / {project_id} / servers
According to the correspondence of the following figure, the create () method in controller should be called here.
If the route is: GET / {project_id} / servers/1/my_edit
The my_edit () method in controller is called.
5. The next question is how to find the corresponding controller class according to route:
The controller class published by the first core route corresponds to the location:
Find the controller class of the corresponding controller=self.resources ['servers']:
The second extension route publishes the corresponding location of the controller class:
The extended routing controller under the other / usr/lib/python2.6/site-packages/nova/api/openstack/compute/contrib/ directory is in its own folder.
Take os-networks as an example:
Look for the corresponding NetworkController () class:
As long as the location of the controller is determined, you can know which function in the controller class will be called by the url mapped by route. The analysis of the api function call process corresponding to this route ends.
The above content is how to analyze the openstack core routing and extended routing and the corresponding api function call process. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.