Source code for openstack_dashboard.api.rest.cinder
# Copyright 2015 IBM Corp.
#
# 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.
"""API over the cinder service.
"""
from django.views import generic
from openstack_dashboard import api
from openstack_dashboard.api.rest import utils as rest_utils
from openstack_dashboard.api.rest import urls
CLIENT_KEYWORDS = {'marker', 'sort_dir', 'paginate'}
@urls.register
[docs]class Volumes(generic.View):
"""API for cinder volumes.
"""
url_regex = r'cinder/volumes/$'
@rest_utils.ajax()
[docs] def get(self, request):
"""Get a detailed list of volumes associated with the current user's
project.
Example GET:
http://localhost/api/cinder/volumes?paginate=true&sort_dir=asc #flake8: noqa
If invoked as an admin, you may set the GET parameter "all_projects"
to 'true' to return details for all projects.
The following get parameters may be passed in the GET
:param search_opts includes options such as name, status, bootable
:param paginate: If true will perform pagination based on settings.
:param marker: Specifies the namespace of the last-seen image.
The typical pattern of limit and marker is to make an
initial limited request and then to use the last
namespace from the response as the marker parameter
in a subsequent limited request. With paginate, limit
is automatically set.
:param sort_dir: The sort direction ('asc' or 'desc').
The listing result is an object with property "items".
"""
if request.GET.get('all_projects') == 'true':
result, has_more, has_prev = api.cinder.volume_list_paged(
request,
{'all_tenants': 1}
)
else:
search_opts, kwargs = rest_utils.parse_filters_kwargs(request, CLIENT_KEYWORDS)
result, has_more, has_prev = api.cinder.volume_list_paged(
request,
search_opts=search_opts, **kwargs
)
return {
'items': [u.to_dict() for u in result],
'has_more_data': has_more,
'has_prev_data': has_prev
}
@urls.register
[docs]class VolumeSnapshots(generic.View):
"""API for cinder volume snapshots.
"""
url_regex = r'cinder/volumesnapshots/$'
@rest_utils.ajax()
[docs] def get(self, request):
"""Get a detailed list of volume snapshots associated with the current
user's project.
The listing result is an object with property "items".
"""
result = api.cinder.volume_snapshot_list(
request,
search_opts=rest_utils.parse_filters_kwargs(request)[0]
)
return {'items': [u.to_dict() for u in result]}