[openstack-dev] Writing extensions to Nova API

Trinath Somanchi trinath.somanchi at gmail.com
Mon Sep 24 15:16:55 UTC 2012


Hi Kevin-

Thanks for the reply,

I have a doubt here,

[1] What are these member_actions and controller_actions

I have written the extension, for listing the servers based on the
Metadata.

I have written a client, which sends the URL,
GET http://10.232.90.82:8774/v2/e216fcb54dc944a8ab16e4e3252996
43/servers/metadetail?instance_metadata.key=Server+
Group&instance_metadata.value=DOM1

Also, after writing the extension in nova api, I get the following debug
logs which confirm that, the extension is flawless.

INFO nova.api.openstack.wsgi [-]  Trinath LOG [ControllerMetaClass ::
__new__] CLS_dict  =>  {'__module__':
'nova.api.openstack.compute.contrib.server_groupby_metadata',
*'wsgi_extensions':
[('metadetail', None)],* 'metadetail': <function metadetail at 0x3828f50>,
'__init__': <function __init__ at 0x3828ed8>, 'wsgi_actions': {}}
 DEBUG nova.api.openstack [-]   _setup_ext_routes() ==> {'member':
{'metadetail': 'GET'}, 'controller': <nova.api.openstack.wsgi.Resource
object at 0x4a33d90>, 'collection': {'metadetail': 'GET'}} from (pid=29146)
_setup_ext_routes
/usr/lib/python2.7/dist-packages/nova/api/openstack/__init__.py:118
2012-09-24 12:34:22 DEBUG nova.api.openstack [-]ProjectMapper :: resource
:: Member Name = OS-SRVR-GRPBY-METADATA, Collection Name =
OS-SRVR-GRPBY-METADATA, kwargs = {'member': {'metadetail': 'GET'},
'controller': <nova.api.openstack.wsgi.Resource object at 0x4a33d90>,
'collection': {'metadetail': 'GET'}, 'path_prefix': '{project_id}/'} from
(pid=29146) resource
/usr/lib/python2.7/dist-packages/nova/api/openstack/__init__.py:74


When I run the client program, I see the following info in the logs,

DEBUG nova.api.openstack.wsgi [req-320da182-509c-4a42-811a-16fdb42c9d2d
9e4a57c9e6a944de9404b963f260b464 e216fcb54dc944a8ab16e4e325299643] WSGI ::
request_environment :: {'HTTP_X_TENANT_NAME': u'admin', 'routes.route':
<routes.route.Route object at 0x4644e50>, 'HTTP_X_ROLE': u'admin',
'SCRIPT_NAME': '/v2', 'webob.adhoc_attrs': {'response': <Response at
0x51e8d50 200 OK>}, 'REQUEST_METHOD': 'GET', 'PATH_INFO':
'/e216fcb54dc944a8ab16e4e325299643/servers/metadetail', 'SERVER_PROTOCOL':
'HTTP/1.0', 'QUERY_STRING':
'instance_metadata.key=Server+Group&instance_metadata.value=DOM1',
'HTTP_X_USER_ID': u'9e4a57c9e6a944de9404b963f260b464', 'HTTP_X_AUTH_TOKEN':
'9c9e3f0b06854befa3fa60914b6ab302', 'HTTP_USER_AGENT': 'python-novaclient',
'eventlet.posthooks': [], 'SERVER_NAME': '10.232.90.82', 'REMOTE_ADDR':
'10.232.90.82', 'eventlet.input': <eventlet.wsgi.Input object at
0x5325510>, 'HTTP_X_IDENTITY_STATUS': 'Confirmed', 'wsgi.url_scheme':
'http', 'wsgiorg.routing_args': (<routes.util.URLGenerator object at
0x36f64d0>, {*'action': u'show'*, 'controller':
<nova.api.openstack.wsgi.Resource object at 0x4644750>, 'project_id':
u'e216fcb54dc944a8ab16e4e325299643', 'id': u'metadetail'}), 'SERVER_PORT':
'8774', 'HTTP_X_ROLES': u'admin', 'HTTP_X_TENANT_ID':
u'e216fcb54dc944a8ab16e4e325299643', 'HTTP_X_USER': u'admin',
'nova.context': <nova.context.RequestContext object at 0x5325650>,
'wsgi.input': <eventlet.wsgi.Input object at 0x5325510>, 'HTTP_HOST': '
10.232.90.82:8774', 'HTTP_X_AUTH_PROJECT_ID': 'admin', 'wsgi.multithread':
True, 'routes.url': <routes.util.URLGenerator object at 0x36f64d0>,
'HTTP_ACCEPT': 'application/json', 'wsgi.version': (1, 0), 'HTTP_X_TENANT':
u'admin', 'GATEWAY_INTERFACE': 'CGI/1.1', 'wsgi.run_once': False,
'wsgi.errors': <open file '<stderr>', mode 'w' at 0x7f6f11540270>,
'wsgi.multiprocess': False, 'HTTP_X_USER_NAME': u'admin', 'CONTENT_TYPE':
'text/plain', 'nova.limits': [{'regex': '.*', 'resetTime': 1348470337,
'URI': '*', 'value': 10, 'verb': 'POST', 'remaining': 10, 'unit':
'MINUTE'}, {'regex': '^/servers', 'resetTime': 1348470337, 'URI':
'*/servers', 'value': 50, 'verb': 'POST', 'remaining': 50, 'unit': 'DAY'},
{'regex': '.*', 'resetTime': 1348470337, 'URI': '*', 'value': 10, 'verb':
'PUT', 'remaining': 10, 'unit': 'MINUTE'}, {'regex': '.*changes-since.*',
'resetTime': 1348470337, 'URI': '*changes-since*', 'value': 3, 'verb':
'GET', 'remaining': 3, 'unit': 'MINUTE'}, {'regex': '.*', 'resetTime':
1348470337, 'URI': '*', 'value': 100, 'verb': 'DELETE', 'remaining': 100,
'unit': 'MINUTE'}], 'HTTP_ACCEPT_ENCODING': 'gzip, deflate',
'nova.best_content_type': 'application/json'} from (pid=29146)
get_action_args
/usr/lib/python2.7/dist-packages/nova/api/openstack/wsgi.py:681

Here, The URI, /server/metadetail? is not being mapped to the method
"metadetail()" method present in the   extension.

Also, its that, the WSGI is mapping, the URI to "show" method rather than
the "metadetail" method.
 'wsgiorg.routing_args': (<routes.util.URLGenerator object at 0x36f64d0>, {'
*action': u'show',* 'controller': <nova.api.openstack.wsgi.Resource object
at 0x4644750>, 'project_id': u'e216fcb54dc944a8ab16e4e325299643', 'id':
u'metadetail'})

Please guide me on how to fix the issue such that the URL with
"/server/metadetail" is mapped to the "metadetail" method in the new
extension.

Kindly, please help me in this regard.

--
Trinath


On Mon, Sep 24, 2012 at 8:30 PM, Kevin L. Mitchell <
kevin.mitchell at rackspace.com> wrote:

> On Fri, 2012-09-21 at 08:46 +0530, Trinath Somanchi wrote:
> > I understand that the extension extend the behavior of an existing
> > expert class.
> >
> > But I have a doubt, How the extension based definitions/methods are
> > mapped to the URI ?
>
> You might want to take a look at nova/api/openstack/compute/contrib for
> existing extensions, to get an idea of how extensions are structured.
> In short, there are two major types of extensions: ControllerExtension,
> which extends existing "expert" controllers, and ResourceExtension,
> which adds a brand new URI endpoint.
>
> For the ControllerExtension, you specify the short name of the resource
> you're extending; for instance, to extend the behavior
> of /v2/<tenant-id>/servers/detail, you would use 'servers'.  You'll have
> to dig through the code a bit to verify the short names of the
> controllers.  As an example of this, check out admin_actions.py.
>
> For the ResourceExtension, you specify the endpoint name and an optional
> parent.  The underlying Routes package sets up the mapping between
> URI/HTTP method and the controller method name, and it is possible to
> add methods using the member_actions and collection_actions arguments.
> As an example of this, check out quotas.py.
> --
> Kevin L. Mitchell <kevin.mitchell at rackspace.com>
>
>
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>



-- 
Regards,
----------------------------------------------
Trinath Somanchi,
+91 9866 235 130
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20120924/47b5aa80/attachment.html>


More information about the OpenStack-dev mailing list