[Launch Instance Fix] Glance rest API fix
Adds support for resource_type, so retrieved namespaces will have properties with proper prefixes. Closes-Bug: 1439312 Change-Id: I4c2b450db8189c99624290a1d678fcaf509e1de6
This commit is contained in:
parent
b2fc84d7f6
commit
9579280bf5
@ -103,6 +103,9 @@ limitations under the License.
|
|||||||
* @param {Object} params
|
* @param {Object} params
|
||||||
* Query parameters. Optional.
|
* Query parameters. Optional.
|
||||||
*
|
*
|
||||||
|
* @param {string} params.resource_type
|
||||||
|
* Namespace resource type.
|
||||||
|
*
|
||||||
* @param {boolean} params.paginate
|
* @param {boolean} params.paginate
|
||||||
* True to paginate automatically.
|
* True to paginate automatically.
|
||||||
*
|
*
|
||||||
@ -134,20 +137,6 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @name hz.api.glanceAPI.getImages
|
|
||||||
* @description
|
|
||||||
* Get a specific namespace.
|
|
||||||
*
|
|
||||||
* http://docs.openstack.org/developer/glance/metadefs-concepts.html
|
|
||||||
*/
|
|
||||||
this.getNamespace = function(namespace) {
|
|
||||||
return apiService.get('/api/glance/metadefs/namespaces/' + namespace)
|
|
||||||
.error(function () {
|
|
||||||
horizon.alert('error', gettext('Unable to retrieve namespace.'));
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register it with the API module so that anybody using the
|
// Register it with the API module so that anybody using the
|
||||||
|
@ -199,6 +199,7 @@ class Namespace(BaseGlanceMetadefAPIResourceWrapper):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@memoized
|
||||||
def metadefs_namespace_get(request, namespace, resource_type=None, wrap=False):
|
def metadefs_namespace_get(request, namespace, resource_type=None, wrap=False):
|
||||||
namespace = glanceclient(request, '2').\
|
namespace = glanceclient(request, '2').\
|
||||||
metadefs_namespace.get(namespace, resource_type=resource_type)
|
metadefs_namespace.get(namespace, resource_type=resource_type)
|
||||||
@ -279,6 +280,18 @@ def metadefs_namespace_list(request,
|
|||||||
return namespaces, has_more_data, has_prev_data
|
return namespaces, has_more_data, has_prev_data
|
||||||
|
|
||||||
|
|
||||||
|
def metadefs_namespace_full_list(request, resource_type, filters={},
|
||||||
|
*args, **kwargs):
|
||||||
|
filters['resource_types'] = [resource_type]
|
||||||
|
namespaces, has_more_data, has_prev_data = metadefs_namespace_list(
|
||||||
|
request, filters, *args, **kwargs
|
||||||
|
)
|
||||||
|
return [
|
||||||
|
metadefs_namespace_get(request, x.namespace, resource_type)
|
||||||
|
for x in namespaces
|
||||||
|
], has_more_data, has_prev_data
|
||||||
|
|
||||||
|
|
||||||
def metadefs_namespace_create(request, namespace):
|
def metadefs_namespace_create(request, namespace):
|
||||||
return glanceclient(request, '2').metadefs_namespace.create(**namespace)
|
return glanceclient(request, '2').metadefs_namespace.create(**namespace)
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
"""API for the glance service.
|
"""API for the glance service.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from itertools import izip
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
|
|
||||||
from openstack_dashboard import api
|
from openstack_dashboard import api
|
||||||
@ -22,7 +23,7 @@ from openstack_dashboard.api.rest import utils as rest_utils
|
|||||||
from openstack_dashboard.api.rest import urls
|
from openstack_dashboard.api.rest import urls
|
||||||
|
|
||||||
|
|
||||||
CLIENT_KEYWORDS = {'marker', 'sort_dir', 'sort_key', 'paginate'}
|
CLIENT_KEYWORDS = {'resource_type', 'marker', 'sort_dir', 'sort_key', 'paginate'}
|
||||||
|
|
||||||
|
|
||||||
@urls.register
|
@urls.register
|
||||||
@ -88,26 +89,6 @@ class Images(generic.View):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@urls.register
|
|
||||||
class MetadefsNamespace(generic.View):
|
|
||||||
"""API for Glance Metadata Definitions.
|
|
||||||
|
|
||||||
http://docs.openstack.org/developer/glance/metadefs-concepts.html
|
|
||||||
"""
|
|
||||||
url_regex = r'glance/metadefs/namespaces/(?P<namespace>.+|default)$'
|
|
||||||
|
|
||||||
@rest_utils.ajax()
|
|
||||||
def get(self, request, namespace):
|
|
||||||
"""Get a specific metadata definition namespaces.
|
|
||||||
|
|
||||||
Returns the namespace. GET params are passed through.
|
|
||||||
|
|
||||||
Example GET:
|
|
||||||
http://localhost/api/glance/metadefs/namespaces/OS::Compute::Watchdog
|
|
||||||
"""
|
|
||||||
return api.glance.metadefs_namespace_get(request, namespace)
|
|
||||||
|
|
||||||
|
|
||||||
@urls.register
|
@urls.register
|
||||||
class MetadefsNamespaces(generic.View):
|
class MetadefsNamespaces(generic.View):
|
||||||
"""API for Single Glance Metadata Definitions.
|
"""API for Single Glance Metadata Definitions.
|
||||||
@ -129,6 +110,9 @@ class MetadefsNamespaces(generic.View):
|
|||||||
The following get parameters may be passed in the GET
|
The following get parameters may be passed in the GET
|
||||||
request:
|
request:
|
||||||
|
|
||||||
|
:param resource_type: Namespace resource type.
|
||||||
|
If specified returned namespace properties will have prefixes
|
||||||
|
proper for selected resource type.
|
||||||
:param paginate: If true will perform pagination based on settings.
|
:param paginate: If true will perform pagination based on settings.
|
||||||
:param marker: Specifies the namespace of the last-seen namespace.
|
:param marker: Specifies the namespace of the last-seen namespace.
|
||||||
The typical pattern of limit and marker is to make an
|
The typical pattern of limit and marker is to make an
|
||||||
@ -147,14 +131,11 @@ class MetadefsNamespaces(generic.View):
|
|||||||
filters.
|
filters.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
filters, kwargs = rest_utils.parse_filters_kwargs(request,
|
filters, kwargs = rest_utils.parse_filters_kwargs(
|
||||||
CLIENT_KEYWORDS)
|
request, CLIENT_KEYWORDS
|
||||||
|
)
|
||||||
|
|
||||||
namespaces, has_more, has_prev = api.glance.metadefs_namespace_list(
|
names = ('items', 'has_more_data', 'has_prev_data')
|
||||||
request, filters=filters, **kwargs)
|
return dict(izip(names, api.glance.metadefs_namespace_full_list(
|
||||||
|
request, filters=filters, **kwargs
|
||||||
return {
|
)))
|
||||||
'items': [n.to_dict() for n in namespaces],
|
|
||||||
'has_more_data': has_more,
|
|
||||||
'has_prev_data': has_prev,
|
|
||||||
}
|
|
||||||
|
@ -56,19 +56,18 @@ class ImagesRestTestCase(test.TestCase):
|
|||||||
@mock.patch.object(glance.api, 'glance')
|
@mock.patch.object(glance.api, 'glance')
|
||||||
def test_namespace_get_list(self, gc):
|
def test_namespace_get_list(self, gc):
|
||||||
request = self.mock_rest_request(**{'GET': {}})
|
request = self.mock_rest_request(**{'GET': {}})
|
||||||
gc.metadefs_namespace_list.return_value = ([
|
gc.metadefs_namespace_full_list.return_value = (
|
||||||
mock.Mock(**{'to_dict.return_value': {'namespace': '1'}}),
|
[{'namespace': '1'}, {'namespace': '2'}], False, False
|
||||||
mock.Mock(**{'to_dict.return_value': {'namespace': '2'}})
|
)
|
||||||
], False, False)
|
|
||||||
|
|
||||||
response = glance.MetadefsNamespaces().get(request)
|
response = glance.MetadefsNamespaces().get(request)
|
||||||
self.assertStatusCode(response, 200)
|
self.assertStatusCode(response, 200)
|
||||||
self.assertEqual(response.content,
|
self.assertEqual(response.content,
|
||||||
'{"items": [{"namespace": "1"}, {"namespace": "2"}]'
|
'{"items": [{"namespace": "1"}, {"namespace": "2"}]'
|
||||||
', "has_more_data": false, "has_prev_data": false}')
|
', "has_more_data": false, "has_prev_data": false}')
|
||||||
gc.metadefs_namespace_list.assert_called_once_with(request,
|
gc.metadefs_namespace_full_list.assert_called_once_with(
|
||||||
filters={},
|
request, filters={}
|
||||||
**{})
|
)
|
||||||
|
|
||||||
@mock.patch.object(glance.api, 'glance')
|
@mock.patch.object(glance.api, 'glance')
|
||||||
def test_namespace_get_list_kwargs_and_filters(self, gc):
|
def test_namespace_get_list_kwargs_and_filters(self, gc):
|
||||||
@ -81,28 +80,15 @@ class ImagesRestTestCase(test.TestCase):
|
|||||||
filters = {'resource_types': 'type'}
|
filters = {'resource_types': 'type'}
|
||||||
request = self.mock_rest_request(
|
request = self.mock_rest_request(
|
||||||
**{'GET': dict(kwargs, **filters)})
|
**{'GET': dict(kwargs, **filters)})
|
||||||
gc.metadefs_namespace_list.return_value = ([
|
gc.metadefs_namespace_full_list.return_value = (
|
||||||
mock.Mock(**{'to_dict.return_value': {'namespace': '1'}}),
|
[{'namespace': '1'}, {'namespace': '2'}], False, False
|
||||||
mock.Mock(**{'to_dict.return_value': {'namespace': '2'}})
|
)
|
||||||
], False, False)
|
|
||||||
|
|
||||||
response = glance.MetadefsNamespaces().get(request)
|
response = glance.MetadefsNamespaces().get(request)
|
||||||
self.assertStatusCode(response, 200)
|
self.assertStatusCode(response, 200)
|
||||||
self.assertEqual(response.content,
|
self.assertEqual(response.content,
|
||||||
'{"items": [{"namespace": "1"}, {"namespace": "2"}]'
|
'{"items": [{"namespace": "1"}, {"namespace": "2"}]'
|
||||||
', "has_more_data": false, "has_prev_data": false}')
|
', "has_more_data": false, "has_prev_data": false}')
|
||||||
gc.metadefs_namespace_list.assert_called_once_with(request,
|
gc.metadefs_namespace_full_list.assert_called_once_with(
|
||||||
filters=filters,
|
request, filters=filters, **kwargs
|
||||||
**kwargs)
|
)
|
||||||
|
|
||||||
@mock.patch.object(glance.api, 'glance')
|
|
||||||
def test_namespace_get_namespace(self, gc):
|
|
||||||
kwargs = {'resource_type': ['OS::Nova::Flavor']}
|
|
||||||
request = self.mock_rest_request(**{'GET': dict(kwargs)})
|
|
||||||
gc.metadefs_namespace_get.return_value\
|
|
||||||
.to_dict.return_value = {'namespace': '1'}
|
|
||||||
|
|
||||||
response = glance.MetadefsNamespace().get(request, "1")
|
|
||||||
self.assertStatusCode(response, 200)
|
|
||||||
gc.metadefs_namespace_get.assert_called_once_with(request,
|
|
||||||
"1")
|
|
||||||
|
Loading…
Reference in New Issue
Block a user