MasterofProject

Design and implementation of OpenStack (five) API RESTful and WSGI

label OpenstackAPIDesign
389 people read comment(0) Collection report
Classification:

In a blog post we mentioned openstack each item within the service process is through the message bus communication of, and through a restful API to communicate between the various projects, in this blog, we detailed discuss openstack each project communication.

One, what is RESTful

RESTful is one of the most popular Internet software architecture. REST (State Transfer Representational, state transfer), if one of the principles of the REST architecture, it is called the RESTful architecture.

The core concept of RESTful architecture is the "resources", in the RESTful world, all things on the network is a resource, such as a text, a picture can be seen as a resource. Each resource corresponds to a specific URI (uniform resource locator) and use it for marking.

Each resource has a variety of forms, we access the process, is called the URI of resources, access to the process of its different forms of expression. That is to say, the server to save the resources in a variety of forms, the client can use HTTP several basic operations, including HTTP get, post, put, and the server resources "transformation", which is why it is called the "representational state transfer".

OpenStack each project has provided the RESTful architecture API as an external interface, that is to say, OpenStack defines a lot of resources, and to achieve a variety of operating functions for these resources. API OpenStack service process to receive the client's HTTP request, a so-called "routing" module will request the URL into the corresponding resources, and route to the appropriate operating function.

Write the picture here.

We take the list Nova command as an example to look at the specific process.

1, the first client to use HTTP to send a request, that is to call the list Nova command.

2, Rails is the OpenStack used by the routing module, after receiving the HTTP request, the request will be assigned to the corresponding Controller, and bind to a action.

3, each Controller corresponds to a RESTful resource, representing the collection of the operation of the resource, which contains a lot of Action. Because Rails specifies the action to execute the index, so the Controller calls the index function.

Two, what is WSGI

Restful just design style instead of the standard, and WSGI (web server gateway interface, Web Server Gateway Interface) is in the python language defined by the web server and web applications or between the framework between the universal interface standard.

WSGI is a bridge, one end of the bridge called the server or network side, the other end is called the application side or the end of the framework, the role of WSGI is to convert between the agreement.

WSGI Web component is divided into three categories: Web server (Server WSGI), Web middleware (Middleware WSGI) and Web applications (Application WSGI).

Server HTTP receives the Web request, package a series of environment variables, according to the WSGI interface standard call registered Application WSGI, and finally will respond to the client.

Application WSGI is a Python object that can be called, it accepts two arguments, usually environ and start_response. For example:

Def Application(environ, start_response):
Start_response (OK''200([.'Content-Type','text/plain')])
    Yield World\n''Hello

Environ parameter points to a python dictionary and requirements which contains at least some defined in CGI environment variables have WSGI defined by the environment variable, WSGI application can get all the information corresponding to the request and the execution context from the environ.

The parameter start_response points to a callback function, which is responsible for executing the client's request and returns the result. When there is a request, Server WSGI will be ready for environ and start_response parameters, and then call Application WSGI to obtain the corresponding request response.

WSGI middleware at the same time to achieve the server and the application of the API, so you can play a coordinating role between the two ends. From the server looks, the middleware is a WSGI application; from the application side looks, the middleware is a WSGI server. WSGI middleware can route the HTTP request of the client to different application objects, and then return the results to the client. We can understand the WSGI middleware as the server and the application side of the interaction of a layer of packaging, through the different middleware packaging, they have different functions.

Three, Paste and Webob

Paste and Webob are two components that are closely related to OpenStack.

Paste:

OpenStack using Deploy Paste components to complete the WSGI server and the application of the construction, each project source code etc directory has a Paste configuration file, such as nova, as shown below.

Write the picture here.

Paste configuration file is divided into a section, each type:name in the format of the section name, specific reference source code can refer to the official website. The main purpose of using Deploy Paste is to generate a Application WSGI from the configuration file, with the configuration file, just use the following call mode:

Wsgi_app = loadapp ('config/path/To/config.ini')

Webob:

Webob through the WSGI request and response to package to simplify the preparation of WSGI applications. Webob in two of the most important objects, one is webob.Request, the WSGI request for the environ parameters of the package, one is webob.Response, contains all elements of the standard WSGI response. Look at an example:

Original WSGI format:

App_iter=Myfunc (environ, start_response)

After using the webob package:

Def Myfunc(req):
    ReturnWebob.Response (There''hey)

Resp = myfunc (req)
top
Zero
step on
Zero
Guess you're looking for
View comments
* the above user comments only represent their personal views, does not represent the views or position of the CSDN website
    personal data
    • visit61159 times
    • Integral:Two thousand and five
    • Grade
    • Rank:11816th name
    • original91
    • Reproduced:9
    • Translation:0
    • Comments:64
    Blog column
    Latest comments