~ubuntu-branches/ubuntu/vivid/manila/vivid-proposed

« back to all changes in this revision

Viewing changes to manila/api/v1/share_snapshots.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-01-15 11:55:33 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20150115115533-yshssd76s2uj3ybx
Tags: 2015.1~b1-0ubuntu1
* New upstream release:
  - d/control: Add new dependencies.
  - Install any new binaries and configuration to common package.
* d/watch: Update to use tarballs.openstack.org.
* d/control,compat: Bump debhelper compat level to 9.
* d/control: Bumped Standards-Version to 3.9.6, no changes.
* Systemd enablement:
  - d/rules,control: Enable use of dh-systemd and openstack-pkg-tools.
  - d/*.init.in: Write templates for generation of init, service and
    upstart configurations.
  - d/*.upstart: Drop in preference to above.
* d/*.logrotate: Move to single logrotate configuration in common package.
* d/rules: Ensure unit test suite failure fails package build.
* d/p/pep-0476.patch: Deal with SSL certification chain verification unit
  test failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
"""The share snapshots api."""
17
17
 
 
18
import six
18
19
import webob
19
20
from webob import exc
20
21
 
23
24
from manila.api.views import share_snapshots as snapshot_views
24
25
from manila.api import xmlutil
25
26
from manila import exception
 
27
from manila.i18n import _LI
26
28
from manila.openstack.common import log as logging
27
29
from manila import share
28
30
 
80
82
        """Delete a snapshot."""
81
83
        context = req.environ['manila.context']
82
84
 
83
 
        LOG.audit(_("Delete snapshot with id: %s"), id, context=context)
 
85
        LOG.info(_LI("Delete snapshot with id: %s"), id, context=context)
84
86
 
85
87
        try:
86
88
            snapshot = self.share_api.get_snapshot(context, id)
106
108
        search_opts = {}
107
109
        search_opts.update(req.GET)
108
110
 
109
 
        # NOTE(rushiagr): v2 API allows name instead of display_name
 
111
        # Remove keys that are not related to share attrs
 
112
        search_opts.pop('limit', None)
 
113
        search_opts.pop('offset', None)
 
114
        sort_key = search_opts.pop('sort_key', 'created_at')
 
115
        sort_dir = search_opts.pop('sort_dir', 'desc')
 
116
 
 
117
        # NOTE(vponomaryov): Manila stores in DB key 'display_name', but
 
118
        # allows to use both keys 'name' and 'display_name'. It is leftover
 
119
        # from Cinder v1 and v2 APIs.
110
120
        if 'name' in search_opts:
111
 
            search_opts['display_name'] = search_opts['name']
112
 
            del search_opts['name']
 
121
            search_opts['display_name'] = search_opts.pop('name')
113
122
 
114
123
        common.remove_invalid_options(context, search_opts,
115
124
                                      self._get_snapshots_search_options())
116
125
 
117
 
        snapshots = self.share_api.get_all_snapshots(context,
118
 
                                                     search_opts=search_opts)
 
126
        snapshots = self.share_api.get_all_snapshots(
 
127
            context,
 
128
            search_opts=search_opts,
 
129
            sort_key=sort_key,
 
130
            sort_dir=sort_dir,
 
131
        )
119
132
        limited_list = common.limited(snapshots, req)
120
133
        if is_detail:
121
134
            snapshots = self._view_builder.detail_list(req, limited_list)
125
138
 
126
139
    def _get_snapshots_search_options(self):
127
140
        """Return share search options allowed by non-admin."""
128
 
        return ('name', 'status', 'share_id')
 
141
        return ('display_name', 'name', 'status', 'share_id', 'size')
129
142
 
130
143
    @wsgi.serializers(xml=SnapshotTemplate)
131
144
    def update(self, req, id, body):
168
181
 
169
182
        share_id = snapshot['share_id']
170
183
        share = self.share_api.get(context, share_id)
171
 
        msg = _("Create snapshot from share %s")
172
 
        LOG.audit(msg, share_id, context=context)
 
184
        LOG.info(_LI("Create snapshot from share %s"),
 
185
                 share_id, context=context)
173
186
 
174
187
        # NOTE(rushiagr): v2 API allows name instead of display_name
175
188
        if 'name' in snapshot:
187
200
            share,
188
201
            snapshot.get('display_name'),
189
202
            snapshot.get('display_description'))
190
 
        return self._view_builder.summary(req, dict(new_snapshot.iteritems()))
 
203
        return self._view_builder.detail(
 
204
            req, dict(six.iteritems(new_snapshot)))
191
205
 
192
206
 
193
207
def create_resource():