Add API for getting Cinder Extensions

Adding API services for getting cinder extensions

Change-Id: Ib4b757637b6f97349c92580f3bfaa89d4c61df67
Partially-Implements: blueprint cinder-extensions.service
This commit is contained in:
Rajat Vig 2015-10-08 13:42:59 -07:00
parent 1f29e5cd67
commit 20bacf9545
4 changed files with 110 additions and 12 deletions

View File

@ -73,3 +73,31 @@ class VolumeSnapshots(generic.View):
search_opts=rest_utils.parse_filters_kwargs(request)[0]
)
return {'items': [u.to_dict() for u in result]}
@urls.register
class Extensions(generic.View):
"""API for cinder extensions.
"""
url_regex = r'cinder/extensions/$'
@rest_utils.ajax()
def get(self, request):
"""Get a list of extensions.
The listing result is an object with property "items". Each item is
an extension.
Example GET:
http://localhost/api/cinder/extensions
"""
result = api.cinder.list_extensions(request)
return {'items': [{
'alias': e.alias,
'description': e.description,
'links': e.links,
'name': e.name,
'namespace': e.namespace,
'updated': e.updated
} for e in result]}

View File

@ -33,7 +33,8 @@
function cinderAPI(apiService, toastService) {
var service = {
getVolumes: getVolumes,
getVolumeSnapshots: getVolumeSnapshots
getVolumeSnapshots: getVolumeSnapshots,
getExtensions: getExtensions
};
return service;
@ -92,5 +93,37 @@
});
}
// Cinder Extensions
/**
* @name horizon.app.core.openstack-service-api.cinder.getExtensions
* @description
* Returns a list of enabled extensions.
*
* The listing result is an object with property "items". Each item is
* an extension.
* @example
* The following is an example response:
*
* {
* "items": [
* {
* "alias": "NMN",
* "description": "Multiple network support.",
* "links": [],
* "name": "Multinic",
* "namespace": "http://docs.openstack.org/compute/ext/multinic/api/v1.1",
* "updated": "2011-06-09T00:00:00Z"
* }
* ]
* }
*/
function getExtensions(config) {
return apiService.get('/api/cinder/extensions/', config)
.error(function () {
toastService.add('error', gettext('Unable to retrieve the extensions.'));
});
}
}
}());

View File

@ -40,31 +40,47 @@
});
var tests = [
{ func: 'getVolumes',
{
func: 'getVolumes',
method: 'get',
path: '/api/cinder/volumes/',
data: { params: 'config' },
error: 'Unable to retrieve the volumes.',
testInput: [ 'config' ] },
{ func: 'getVolumes',
testInput: [ 'config' ]
},
{
func: 'getVolumes',
method: 'get',
path: '/api/cinder/volumes/',
data: {},
error: 'Unable to retrieve the volumes.' },
{ func: 'getVolumeSnapshots',
error: 'Unable to retrieve the volumes.'
},
{
'func': 'getExtensions',
'method': 'get',
'path': '/api/cinder/extensions/',
'data': 'config',
'error': 'Unable to retrieve the extensions.',
'testInput': [
'config'
]
},
{
func: 'getVolumeSnapshots',
method: 'get',
path: '/api/cinder/volumesnapshots/',
data: {},
error: 'Unable to retrieve the volume snapshots.' },
{ func: 'getVolumeSnapshots',
error: 'Unable to retrieve the volume snapshots.'
},
{
func: 'getVolumeSnapshots',
method: 'get',
path: '/api/cinder/volumesnapshots/',
data: { params: 'config' },
error: 'Unable to retrieve the volume snapshots.',
testInput: [ 'config' ] } ] ;
testInput: [ 'config' ]
}
];
// Iterate through the defined tests and apply as Jasmine specs.
angular.forEach(tests, function(params) {

View File

@ -13,6 +13,8 @@
# limitations under the License.
import mock
from django.conf import settings
from openstack_dashboard.api.rest import cinder
from openstack_dashboard.test import helpers as test
@ -77,3 +79,22 @@ class CinderRestTestCase(test.TestCase):
{"items": [{"id": "one"}, {"id": "two"}]})
cc.volume_snapshot_list.assert_called_once_with(request,
search_opts=filters)
#
# Extensions
#
@mock.patch.object(cinder.api, 'cinder')
@mock.patch.object(settings,
'OPENSTACK_CINDER_EXTENSIONS_BLACKLIST', ['baz'])
def _test_extension_list(self, cc):
request = self.mock_rest_request()
cc.list_extensions.return_value = [
mock.Mock(**{'to_dict.return_value': {'name': 'foo'}}),
mock.Mock(**{'to_dict.return_value': {'name': 'bar'}}),
mock.Mock(**{'to_dict.return_value': {'name': 'baz'}}),
]
response = cinder.Extensions().get(request)
self.assertStatusCode(response, 200)
self.assertEqual(response.content,
'{"items": [{"name": "foo"}, {"name": "bar"}]}')
cc.list_extensions.assert_called_once_with(request)