REST API to Get a Volume and Volume Type(s)
It also adds the ability to get default volume type. Change-Id: I01596032eed82b37eb8a0e4a279f9e683f4ecbd4 Partially-Implements: blueprint angularize-images-table
This commit is contained in:
parent
2c9c7ed43c
commit
1265bd6a5d
|
@ -55,6 +55,68 @@ class Volumes(generic.View):
|
|||
return {'items': [u.to_dict() for u in result]}
|
||||
|
||||
|
||||
@urls.register
|
||||
class Volume(generic.View):
|
||||
"""API for cinder volume.
|
||||
"""
|
||||
url_regex = r'cinder/volumes/(?P<volume_id>[^/]+)/$'
|
||||
|
||||
@rest_utils.ajax()
|
||||
def get(self, request, volume_id):
|
||||
"""Get a single volume's details with the volume id.
|
||||
|
||||
The following get parameters may be passed in the GET
|
||||
|
||||
:param volume_id the id of the volume
|
||||
|
||||
The result is a volume object.
|
||||
"""
|
||||
return api.cinder.volume_get(request, volume_id).to_dict()
|
||||
|
||||
|
||||
@urls.register
|
||||
class VolumeTypes(generic.View):
|
||||
"""API for volume types.
|
||||
"""
|
||||
url_regex = r'cinder/volumetypes/$'
|
||||
|
||||
@rest_utils.ajax()
|
||||
def get(self, request):
|
||||
"""Get a list of volume types.
|
||||
|
||||
The listing result is an object with the property "items".
|
||||
"""
|
||||
result = api.cinder.volume_type_list(request)
|
||||
return {'items': [api.cinder.VolumeType(u).to_dict() for u in result]}
|
||||
|
||||
|
||||
@urls.register
|
||||
class VolumeType(generic.View):
|
||||
"""API for getting a volume type.
|
||||
"""
|
||||
url_regex = r'cinder/volumetypes/(?P<volumetype_id>[^/]+)/$'
|
||||
|
||||
@rest_utils.ajax()
|
||||
def get(self, request, volumetype_id):
|
||||
"""Get a single volume type details with the volume type id.
|
||||
|
||||
The following get parameters may be passed in the GET
|
||||
|
||||
:param volumetype_id the id of the volume type
|
||||
|
||||
If 'default' is passed as the volumetype_id then
|
||||
it returns the default volumetype
|
||||
|
||||
The result is a volume type object.
|
||||
"""
|
||||
if volumetype_id == 'default':
|
||||
volumetype = api.cinder.volume_type_default(request)
|
||||
else:
|
||||
volumetype = api.cinder.volume_type_get(request, volumetype_id)
|
||||
|
||||
return api.cinder.VolumeType(volumetype).to_dict()
|
||||
|
||||
|
||||
@urls.register
|
||||
class VolumeSnapshots(generic.View):
|
||||
"""API for cinder volume snapshots.
|
||||
|
|
|
@ -33,6 +33,10 @@
|
|||
function cinderAPI(apiService, toastService) {
|
||||
var service = {
|
||||
getVolumes: getVolumes,
|
||||
getVolume: getVolume,
|
||||
getVolumeTypes: getVolumeTypes,
|
||||
getVolumeType: getVolumeType,
|
||||
getDefaultVolumeType: getDefaultVolumeType,
|
||||
getVolumeSnapshots: getVolumeSnapshots,
|
||||
getExtensions: getExtensions
|
||||
};
|
||||
|
@ -66,6 +70,69 @@
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @name horizon.app.core.openstack-service-api.cinder.getVolume
|
||||
* @description
|
||||
* Get a single Volume by ID.
|
||||
*
|
||||
* @param {string} id
|
||||
* Specifies the id of the Volume to request.
|
||||
*
|
||||
*/
|
||||
function getVolume(id) {
|
||||
return apiService.get('/api/cinder/volumes/' + id)
|
||||
.error(function () {
|
||||
toastService.add('error', gettext('Unable to retrieve the volume.'));
|
||||
});
|
||||
}
|
||||
|
||||
// Volume Types
|
||||
|
||||
/**
|
||||
* @name horizon.app.core.openstack-service-api.cinder.getVolumeTypes
|
||||
* @description
|
||||
* Get a list of volume types.
|
||||
*
|
||||
* The listing result is an object with property "items." Each item is
|
||||
* a volume type.
|
||||
*
|
||||
*/
|
||||
function getVolumeTypes() {
|
||||
return apiService.get('/api/cinder/volumetypes/')
|
||||
.error(function () {
|
||||
toastService.add('error', gettext('Unable to retrieve the volume types.'));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @name horizon.app.core.openstack-service-api.cinder.getVolumeType
|
||||
* @description
|
||||
* Get a single Volume Type by ID.
|
||||
*
|
||||
* @param {string} id
|
||||
* Specifies the id of the Volume Type to request.
|
||||
*
|
||||
*/
|
||||
function getVolumeType(id) {
|
||||
return apiService.get('/api/cinder/volumetypes/' + id)
|
||||
.error(function () {
|
||||
toastService.add('error', gettext('Unable to retrieve the volume type.'));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @name horizon.app.core.openstack-service-api.cinder.getDefaultVolumeType
|
||||
* @description
|
||||
* Get the default Volume Type
|
||||
*
|
||||
*/
|
||||
function getDefaultVolumeType() {
|
||||
return apiService.get('/api/cinder/volumetypes/default')
|
||||
.error(function () {
|
||||
toastService.add('error', gettext('Unable to retrieve the default volume type.'));
|
||||
});
|
||||
}
|
||||
|
||||
// Volume Snapshots
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,6 +55,34 @@
|
|||
data: {},
|
||||
error: 'Unable to retrieve the volumes.'
|
||||
},
|
||||
{
|
||||
func: 'getVolume',
|
||||
method: 'get',
|
||||
path: '/api/cinder/volumes/1',
|
||||
error: 'Unable to retrieve the volume.',
|
||||
testInput: [1]
|
||||
},
|
||||
{
|
||||
func: 'getVolumeTypes',
|
||||
method: 'get',
|
||||
path: '/api/cinder/volumetypes/',
|
||||
error: 'Unable to retrieve the volume types.',
|
||||
testInput: []
|
||||
},
|
||||
{
|
||||
func: 'getVolumeType',
|
||||
method: 'get',
|
||||
path: '/api/cinder/volumetypes/1',
|
||||
error: 'Unable to retrieve the volume type.',
|
||||
testInput: [1]
|
||||
},
|
||||
{
|
||||
func: 'getDefaultVolumeType',
|
||||
method: 'get',
|
||||
path: '/api/cinder/volumetypes/default',
|
||||
error: 'Unable to retrieve the default volume type.',
|
||||
testInput: []
|
||||
},
|
||||
{
|
||||
'func': 'getExtensions',
|
||||
'method': 'get',
|
||||
|
|
|
@ -20,6 +20,10 @@ from openstack_dashboard.test import helpers as test
|
|||
|
||||
|
||||
class CinderRestTestCase(test.TestCase):
|
||||
|
||||
#
|
||||
# Volumes
|
||||
#
|
||||
def test_volumes_get(self):
|
||||
self._test_volumes_get(False, {})
|
||||
|
||||
|
@ -51,6 +55,58 @@ class CinderRestTestCase(test.TestCase):
|
|||
cc.volume_list.assert_called_once_with(request,
|
||||
search_opts=filters)
|
||||
|
||||
@mock.patch.object(cinder.api, 'cinder')
|
||||
def test_volume_get(self, cc):
|
||||
request = self.mock_rest_request(**{'GET': {}})
|
||||
cc.volume_get.return_value = mock.Mock(
|
||||
**{'to_dict.return_value': {'id': 'one'}})
|
||||
response = cinder.Volume().get(request, '1')
|
||||
self.assertStatusCode(response, 200)
|
||||
self.assertEqual(response.json, {"id": "one"})
|
||||
cc.volume_get.assert_called_once_with(request, '1')
|
||||
|
||||
#
|
||||
# Volume Types
|
||||
#
|
||||
@mock.patch.object(cinder.api, 'cinder')
|
||||
def test_volume_types_get(self, cc):
|
||||
request = self.mock_rest_request(**{'GET': {}})
|
||||
cc.VolumeType.return_value = mock.Mock(
|
||||
**{'to_dict.return_value': {'id': 'one'}})
|
||||
cc.volume_type_list.return_value = [{'id': 'one'}]
|
||||
response = cinder.VolumeTypes().get(request)
|
||||
self.assertStatusCode(response, 200)
|
||||
self.assertEqual(response.json, {"items": [{"id": "one"}]})
|
||||
cc.volume_type_list.assert_called_once_with(request)
|
||||
cc.VolumeType.assert_called_once_with({'id': 'one'})
|
||||
|
||||
@mock.patch.object(cinder.api, 'cinder')
|
||||
def test_volume_type_get(self, cc):
|
||||
request = self.mock_rest_request(**{'GET': {}})
|
||||
cc.volume_type_get.return_value = {'name': 'one'}
|
||||
cc.VolumeType.return_value = mock.Mock(
|
||||
**{'to_dict.return_value': {'id': 'one'}})
|
||||
response = cinder.VolumeType().get(request, '1')
|
||||
self.assertStatusCode(response, 200)
|
||||
self.assertEqual(response.json, {"id": "one"})
|
||||
cc.volume_type_get.assert_called_once_with(request, '1')
|
||||
cc.VolumeType.assert_called_once_with({'name': 'one'})
|
||||
|
||||
@mock.patch.object(cinder.api, 'cinder')
|
||||
def test_volume_type_get_default(self, cc):
|
||||
request = self.mock_rest_request(**{'GET': {}})
|
||||
cc.volume_type_default.return_value = {'name': 'one'}
|
||||
cc.VolumeType.return_value = mock.Mock(
|
||||
**{'to_dict.return_value': {'id': 'one'}})
|
||||
response = cinder.VolumeType().get(request, 'default')
|
||||
self.assertStatusCode(response, 200)
|
||||
self.assertEqual(response.json, {"id": "one"})
|
||||
cc.volume_type_default.assert_called_once_with(request)
|
||||
cc.VolumeType.assert_called_once_with({'name': 'one'})
|
||||
|
||||
#
|
||||
# Volume Snapshots
|
||||
#
|
||||
@mock.patch.object(cinder.api, 'cinder')
|
||||
def test_volume_snaps_get(self, cc):
|
||||
request = self.mock_rest_request(**{'GET': {}})
|
||||
|
|
Loading…
Reference in New Issue