Ask Your Question
0

can't understand quantum source code

asked 2012-10-17 02:59:00 -0500

I have a problem about quantum(F) source code. I have read the source code of quantum. But when I found ’APIRouter‘ according to ’api-paste.ini‘, I cannot understand how the ’APIRouter‘ deals with ‘environ’ that is from 'wsgi'. For example, when I send "GET /v2.0/networks/{network-id}" , will the ‘show(request, id)’ method of ‘quantum/api/v2/base.py’ be called? And where is the ‘network-id’ picked up from URI ? And where is the ‘request’ created? Thanks a lot.

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
0

answered 2012-10-23 13:48:53 -0500

Thanks yong sheng gong, that solved my question.

edit flag offensive delete link more
0

answered 2012-10-22 04:01:15 -0500

gongysh gravatar image

first {network_id} will be collected as id in wsgiorg.routing_args, and then it will be used as a parameter to call controller's method. The method name is defined by mapper according to the http method. The request is created in router module of python. quantum/api/v2/resource.py: @webob.dec.wsgify(RequestClass=Request) def resource(request): route_args = request.environ.get('wsgiorg.routing_args') if route_args: args = route_args[1].copy() else: args = {}

    # NOTE(jkoelker) by now the controller is already found, remove
    #                it from the args if it is in the matchdict
    args.pop('controller', None)
    fmt = args.pop('format', None)
    action = args.pop('action', None)

    content_type = format_types.get(fmt,
                                    request.best_match_content_type())
    deserializer = deserializers.get(content_type)
    serializer = serializers.get(content_type)

    try:
        if request.body:
            args['body'] = deserializer(request.body)

        method = getattr(controller, action)

        result = method(request=request, **args)
edit flag offensive delete link more

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2012-10-17 02:59:00 -0500

Seen: 42 times

Last updated: Oct 23 '12