For quite some time, OpenStack services have wanted to be able to send messages to API end users (by user I do not mean the operator, but the user that is interacting with the client). This patch implements basic user messages with the following APIs. GET /messages GET /messages/<message_id> DELETE /messages/<message_id> Implements the basic /messages resource and tempest tests The patch is aligned with related cinder patch where possible: I8a635a07ed6ff93ccb71df8c404c927d1ecef005 DocImpact APIImpact Needed-By: I5ffb840a271c518f62ee1accfd8e20a97f45594d Needed-By: I9ce096eebda3249687268e361b7141dea4032b57 Needed-By: Ic7d25a144905a39c56ababe8bd666b01bc0d0aef Partially-implements: blueprint user-messages Co-Authored-By: Jan Provaznik <jprovazn@redhat.com> Change-Id: Ia0cc524e0bfb2ca5e495e575e17e9911c746690b
69 lines
2.8 KiB
Python
69 lines
2.8 KiB
Python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
|
|
from manila.api import common
|
|
from manila.message import message_field
|
|
|
|
|
|
class ViewBuilder(common.ViewBuilder):
|
|
"""Model a server API response as a python dictionary."""
|
|
|
|
_collection_name = "messages"
|
|
|
|
def index(self, request, messages):
|
|
"""Show a list of messages."""
|
|
return self._list_view(self.detail, request, messages)
|
|
|
|
def detail(self, request, message):
|
|
"""Detailed view of a single message."""
|
|
message_ref = {
|
|
'id': message.get('id'),
|
|
'project_id': message.get('project_id'),
|
|
'action_id': message.get('action_id'),
|
|
'detail_id': message.get('detail_id'),
|
|
'message_level': message.get('message_level'),
|
|
'created_at': message.get('created_at'),
|
|
'expires_at': message.get('expires_at'),
|
|
'request_id': message.get('request_id'),
|
|
'links': self._get_links(request, message['id']),
|
|
'resource_type': message.get('resource_type'),
|
|
'resource_id': message.get('resource_id'),
|
|
'user_message': "%s: %s" % (
|
|
message_field.translate_action(message.get('action_id')),
|
|
message_field.translate_detail(message.get('detail_id'))),
|
|
}
|
|
|
|
return {'message': message_ref}
|
|
|
|
def _list_view(self, func, request, messages, coll_name=_collection_name):
|
|
"""Provide a view for a list of messages.
|
|
|
|
:param func: Function used to format the message data
|
|
:param request: API request
|
|
:param messages: List of messages in dictionary format
|
|
:param coll_name: Name of collection, used to generate the next link
|
|
for a pagination query
|
|
:returns: message data in dictionary format
|
|
"""
|
|
messages_list = [func(request, message)['message']
|
|
for message in messages]
|
|
messages_links = self._get_collection_links(request,
|
|
messages,
|
|
coll_name)
|
|
messages_dict = dict({"messages": messages_list})
|
|
|
|
if messages_links:
|
|
messages_dict['messages_links'] = messages_links
|
|
|
|
return messages_dict
|