Coverage for manila/api/views/resource_locks.py: 90%
17 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
14from manila.api import common
17class ViewBuilder(common.ViewBuilder):
18 """Model a resource lock API response as a python dictionary."""
20 _collection_name = "resource_locks"
22 def index(self, request, resource_locks, count=None):
23 """Show a list of resource locks."""
24 return self._list_view(self.detail,
25 request,
26 resource_locks,
27 count=count)
29 def detail(self, request, resource_lock):
30 """Detailed view of a single resource lock."""
31 lock_ref = {
32 'id': resource_lock.get('id'),
33 'user_id': resource_lock.get('user_id'),
34 'project_id': resource_lock.get('project_id'),
35 'lock_context': resource_lock.get('lock_context'),
36 'resource_type': resource_lock.get('resource_type'),
37 'resource_id': resource_lock.get('resource_id'),
38 'resource_action': resource_lock.get('resource_action'),
39 'lock_reason': resource_lock.get('lock_reason'),
40 'created_at': resource_lock.get('created_at'),
41 'updated_at': resource_lock.get('updated_at'),
42 'links': self._get_links(request, resource_lock['id']),
43 }
44 return {'resource_lock': lock_ref}
46 def _list_view(self, func, request, resource_locks,
47 coll_name=_collection_name, count=None):
48 """Provide a view for a list of resource_locks.
50 :param func: Function used to format the lock data
51 :param request: API request
52 :param resource_locks: List of locks in dictionary format
53 :param coll_name: Name of collection, used to generate the next link
54 for a pagination query
55 :returns: lock data in dictionary format
56 """
57 locks_list = [
58 func(request, lock)['resource_lock']
59 for lock in resource_locks
60 ]
61 locks_links = self._get_collection_links(request,
62 resource_locks,
63 coll_name)
64 locks_dict = dict({"resource_locks": locks_list})
66 if count: 66 ↛ 69line 66 didn't jump to line 69 because the condition on line 66 was always true
67 locks_dict['count'] = count
69 if locks_links: 69 ↛ 72line 69 didn't jump to line 72 because the condition on line 69 was always true
70 locks_dict['resource_locks_links'] = locks_links
72 return locks_dict