2
* Copyright 2015, Hewlett-Packard Development Company, L.P.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
20
.module('horizon.app.core.openstack-service-api')
21
.factory('horizon.app.core.openstack-service-api.glance', GlanceAPI);
24
'horizon.framework.util.http.service',
25
'horizon.framework.widgets.toast.service'
30
* @name horizon.app.core.openstack-service-api.glance
31
* @description Provides direct pass through to Glance with NO abstraction.
33
function GlanceAPI(apiService, toastService) {
36
getImageProps: getImageProps,
37
editImageProps: editImageProps,
39
getNamespaces: getNamespaces
49
* @name horizon.app.core.openstack-service-api.glance.getImage
51
* Get a single image by ID
53
* Specifies the id of the image to request.
55
function getImage(id) {
56
return apiService.get('/api/glance/images/' + id)
58
toastService.add('error', gettext('Unable to retrieve the image.'));
63
* @name horizon.app.core.openstack-service-api.glance.getImageProps
65
* Get an image custom properties by image ID
66
* @param {string} id Specifies the id of the image to request.
68
function getImageProps(id) {
69
return apiService.get('/api/glance/images/' + id + '/properties/')
71
toastService.add('error', gettext('Unable to retrieve the image custom properties.'));
76
* @name horizon.app.core.openstack-service-api.glance.editImageProps
78
* Update an image custom properties by image ID
79
* @param {string} id Specifies the id of the image to request.
80
* @param {object} updated New metadata definitions.
81
* @param {[]} removed Names of removed metadata definitions.
83
function editImageProps(id, updated, removed) {
84
return apiService.patch(
85
'/api/glance/images/' + id + '/properties/',
92
toastService.add('error', gettext('Unable to edit the image custom properties.'));
97
* @name horizon.app.core.openstack-service-api.glance.getImages
99
* Get a list of images.
101
* The listing result is an object with property "items". Each item is
104
* @param {Object} params
105
* Query parameters. Optional.
107
* @param {boolean} params.paginate
108
* True to paginate automatically.
110
* @param {string} params.marker
111
* Specifies the image of the last-seen image.
113
* The typical pattern of limit and marker is to make an
114
* initial limited request and then to use the last
115
* image from the response as the marker parameter
116
* in a subsequent limited request. With paginate, limit
117
* is automatically set.
119
* @param {string} params.sort_dir
120
* The sort direction ('asc' or 'desc').
122
* @param {string} params.sort_key
123
* The field to sort on (for example, 'created_at').
124
* Default is created_at.
126
* @param {string} params.other
127
* Any additional request parameters will be passed through the API as
128
* filters. For example "name" : "fedora" would filter on the fedora name.
130
function getImages(params) {
131
var config = (params) ? { 'params' : params} : {};
132
return apiService.get('/api/glance/images/', config)
134
toastService.add('error', gettext('Unable to retrieve the images.'));
138
// Metadata Definitions - Namespaces
141
* @name horizon.app.core.openstack-service-api.glance.getNamespaces
143
* Get a list of metadata definition namespaces.
145
* http://docs.openstack.org/developer/glance/metadefs-concepts.html
147
* The listing result is an object with property "items". Each item is
151
* Get a list of namespaces.
153
* The listing result is an object with property "items". Each item is
156
* @param {Object} params
157
* Query parameters. Optional.
159
* @param {string} params.resource_type
160
* Namespace resource type.
162
* @param {boolean} params.paginate
163
* True to paginate automatically.
165
* @param {string} params.marker
166
* Specifies the namespace of the last-seen namespace.
168
* The typical pattern of limit and marker is to make an
169
* initial limited request and then to use the last
170
* namespace from the response as the marker parameter
171
* in a subsequent limited request. With paginate, limit
172
* is automatically set.
174
* @param {string} params.sort_dir
175
* The sort direction ('asc' or 'desc').
177
* @param {string} params.sort_key
178
* The field to sort on (for example, 'created_at').
179
* Default is namespace.
181
* @param {string} params.other
182
* Any additional request parameters will be passed through the API as
185
* @param {boolean} suppressError
186
* If passed in, this will not show the default error handling
187
* (horizon alert). The glance API may not have metadata definitions
190
function getNamespaces(params, suppressError) {
191
var config = (params) ? {'params' : params} : {};
194
var promise = apiService.get('/api/glance/metadefs/namespaces/', config);
196
return suppressError ? promise : promise.error(function() {
197
toastService.add('error', gettext('Unable to retrieve the namespaces.'));