~ubuntu-branches/ubuntu/wily/horizon/wily-proposed

« back to all changes in this revision

Viewing changes to openstack_dashboard/static/app/core/openstack-service-api/glance.service.js

  • Committer: Package Import Robot
  • Author(s): Corey Bryant
  • Date: 2015-09-08 15:52:37 UTC
  • mfrom: (0.20.1) (0.19.3)
  • Revision ID: package-import@ubuntu.com-20150908155237-7muid4idbm4qdelw
Tags: 2:8.0.0~b3-0ubuntu1
* New upstream milestone for OpenStack Liberty.
* d/control: Align (build-)depends with upstream.
* d/p/ubuntu_settings.patch: Rebased.
* d/p/embedded-xstatic.patch: Rebased.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2015, Hewlett-Packard Development Company, L.P.
 
3
 *
 
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
 
7
 *
 
8
 *    http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
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.
 
15
 */
 
16
(function () {
 
17
  'use strict';
 
18
 
 
19
  angular
 
20
    .module('horizon.app.core.openstack-service-api')
 
21
    .factory('horizon.app.core.openstack-service-api.glance', GlanceAPI);
 
22
 
 
23
  GlanceAPI.$inject = [
 
24
    'horizon.framework.util.http.service',
 
25
    'horizon.framework.widgets.toast.service'
 
26
  ];
 
27
 
 
28
  /**
 
29
   * @ngdoc service
 
30
   * @name horizon.app.core.openstack-service-api.glance
 
31
   * @description Provides direct pass through to Glance with NO abstraction.
 
32
   */
 
33
  function GlanceAPI(apiService, toastService) {
 
34
    var service = {
 
35
      getImage: getImage,
 
36
      getImageProps: getImageProps,
 
37
      editImageProps: editImageProps,
 
38
      getImages: getImages,
 
39
      getNamespaces: getNamespaces
 
40
    };
 
41
 
 
42
    return service;
 
43
 
 
44
    ///////////////
 
45
 
 
46
    // Images
 
47
 
 
48
    /**
 
49
     * @name horizon.app.core.openstack-service-api.glance.getImage
 
50
     * @description
 
51
     * Get a single image by ID
 
52
     * @param {string} id
 
53
     * Specifies the id of the image to request.
 
54
     */
 
55
    function getImage(id) {
 
56
      return apiService.get('/api/glance/images/' + id)
 
57
        .error(function () {
 
58
          toastService.add('error', gettext('Unable to retrieve the image.'));
 
59
        });
 
60
    }
 
61
 
 
62
    /**
 
63
     * @name horizon.app.core.openstack-service-api.glance.getImageProps
 
64
     * @description
 
65
     * Get an image custom properties by image ID
 
66
     * @param {string} id Specifies the id of the image to request.
 
67
     */
 
68
    function getImageProps(id) {
 
69
      return apiService.get('/api/glance/images/' + id + '/properties/')
 
70
        .error(function () {
 
71
          toastService.add('error', gettext('Unable to retrieve the image custom properties.'));
 
72
        });
 
73
    }
 
74
 
 
75
    /**
 
76
     * @name horizon.app.core.openstack-service-api.glance.editImageProps
 
77
     * @description
 
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.
 
82
     */
 
83
    function editImageProps(id, updated, removed) {
 
84
      return apiService.patch(
 
85
        '/api/glance/images/' + id + '/properties/',
 
86
        {
 
87
          updated: updated,
 
88
          removed: removed
 
89
        }
 
90
      )
 
91
      .error(function () {
 
92
        toastService.add('error', gettext('Unable to edit the image custom properties.'));
 
93
      });
 
94
    }
 
95
 
 
96
    /**
 
97
     * @name horizon.app.core.openstack-service-api.glance.getImages
 
98
     * @description
 
99
     * Get a list of images.
 
100
     *
 
101
     * The listing result is an object with property "items". Each item is
 
102
     * an image.
 
103
     *
 
104
     * @param {Object} params
 
105
     * Query parameters. Optional.
 
106
     *
 
107
     * @param {boolean} params.paginate
 
108
     * True to paginate automatically.
 
109
     *
 
110
     * @param {string} params.marker
 
111
     * Specifies the image of the last-seen image.
 
112
     *
 
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.
 
118
     *
 
119
     * @param {string} params.sort_dir
 
120
     * The sort direction ('asc' or 'desc').
 
121
     *
 
122
     * @param {string} params.sort_key
 
123
     *   The field to sort on (for example, 'created_at').
 
124
     *   Default is created_at.
 
125
     *
 
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.
 
129
     */
 
130
    function getImages(params) {
 
131
      var config = (params) ? { 'params' : params} : {};
 
132
      return apiService.get('/api/glance/images/', config)
 
133
        .error(function () {
 
134
          toastService.add('error', gettext('Unable to retrieve the images.'));
 
135
        });
 
136
    }
 
137
 
 
138
    // Metadata Definitions - Namespaces
 
139
 
 
140
    /**
 
141
     * @name horizon.app.core.openstack-service-api.glance.getNamespaces
 
142
     * @description
 
143
     * Get a list of metadata definition namespaces.
 
144
     *
 
145
     * http://docs.openstack.org/developer/glance/metadefs-concepts.html
 
146
     *
 
147
     * The listing result is an object with property "items". Each item is
 
148
     * an namespace.
 
149
     *
 
150
     * @description
 
151
     * Get a list of namespaces.
 
152
     *
 
153
     * The listing result is an object with property "items". Each item is
 
154
     * a namespace.
 
155
     *
 
156
     * @param {Object} params
 
157
     * Query parameters. Optional.
 
158
     *
 
159
     * @param {string} params.resource_type
 
160
     * Namespace resource type.
 
161
     *
 
162
     * @param {boolean} params.paginate
 
163
     * True to paginate automatically.
 
164
     *
 
165
     * @param {string} params.marker
 
166
     * Specifies the namespace of the last-seen namespace.
 
167
     *
 
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.
 
173
     *
 
174
     * @param {string} params.sort_dir
 
175
     * The sort direction ('asc' or 'desc').
 
176
     *
 
177
     * @param {string} params.sort_key
 
178
     *   The field to sort on (for example, 'created_at').
 
179
     *   Default is namespace.
 
180
     *
 
181
     * @param {string} params.other
 
182
     * Any additional request parameters will be passed through the API as
 
183
     * filters.
 
184
     *
 
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
 
188
     * enabled.
 
189
     */
 
190
    function getNamespaces(params, suppressError) {
 
191
      var config = (params) ? {'params' : params} : {};
 
192
      config.cache = true;
 
193
 
 
194
      var promise = apiService.get('/api/glance/metadefs/namespaces/', config);
 
195
 
 
196
      return suppressError ? promise : promise.error(function() {
 
197
          toastService.add('error', gettext('Unable to retrieve the namespaces.'));
 
198
        });
 
199
    }
 
200
 
 
201
  }
 
202
}());