Coverage for manila/api/v2/share_snapshot_instances.py: 100%
49 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# Copyright 2016 Huawei Inc.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
16from webob import exc
18from manila.api.openstack import wsgi
19from manila.api.views import share_snapshot_instances as instance_view
20from manila import db
21from manila import exception
22from manila.i18n import _
23from manila import share
26class ShareSnapshotInstancesController(wsgi.Controller,
27 wsgi.AdminActionsMixin):
28 """The share snapshot instances API controller for the OpenStack API."""
30 resource_name = 'share_snapshot_instance'
31 _view_builder_class = instance_view.ViewBuilder
33 def __init__(self):
34 self.share_api = share.API()
35 super(ShareSnapshotInstancesController, self).__init__()
37 @wsgi.Controller.api_version('2.19')
38 @wsgi.Controller.authorize
39 def show(self, req, id):
40 context = req.environ['manila.context']
41 try:
42 snapshot_instance = db.share_snapshot_instance_get(
43 context, id)
44 except exception.ShareSnapshotInstanceNotFound:
45 msg = (_("Snapshot instance %s not found.") % id)
46 raise exc.HTTPNotFound(explanation=msg)
47 return self._view_builder.detail(req, snapshot_instance)
49 @wsgi.Controller.api_version('2.19')
50 @wsgi.Controller.authorize
51 def index(self, req):
52 """Return a summary list of snapshot instances."""
53 return self._get_instances(req)
55 @wsgi.Controller.api_version('2.19')
56 @wsgi.Controller.authorize
57 def detail(self, req):
58 """Returns a detailed list of snapshot instances."""
59 return self._get_instances(req, is_detail=True)
61 def _get_instances(self, req, is_detail=False):
62 """Returns list of snapshot instances."""
63 context = req.environ['manila.context']
64 snapshot_id = req.params.get('snapshot_id')
66 instances = db.share_snapshot_instance_get_all_with_filters(
67 context, {'snapshot_ids': snapshot_id})
69 if is_detail:
70 instances = self._view_builder.detail_list(req, instances)
71 else:
72 instances = self._view_builder.summary_list(req, instances)
73 return instances
75 @wsgi.Controller.api_version('2.19')
76 @wsgi.action('reset_status')
77 def reset_status(self, req, id, body):
78 """Reset the 'status' attribute in the database."""
79 return self._reset_status(req, id, body)
81 def _update(self, *args, **kwargs):
82 db.share_snapshot_instance_update(*args, **kwargs)
84 def _get(self, *args, **kwargs):
85 db.share_snapshot_instance_get(*args, **kwargs)
88def create_resource():
89 return wsgi.Resource(ShareSnapshotInstancesController())