Revision cd2b0bf5

b/snf-cyclades-app/synnefo/api/flavors.py
70 70
    #                       unauthorized (401),
71 71
    #                       badRequest (400),
72 72
    #                       overLimit (413)
73
    
73

  
74 74
    log.debug('list_flavors detail=%s', detail)
75 75
    active_flavors = Flavor.objects.exclude(deleted=True)
76
    flavors = [flavor_to_dict(flavor, detail) for flavor in active_flavors]
77
    
76
    flavors = [flavor_to_dict(flavor, detail)\
77
               for flavor in active_flavors.order_by('id')]
78

  
78 79
    if request.serialization == 'xml':
79 80
        data = render_to_string('list_flavors.xml', {
80 81
            'flavors': flavors,
......
84 85

  
85 86
    return HttpResponse(data, status=200)
86 87

  
88

  
87 89
@util.api_method('GET')
88 90
def get_flavor_details(request, flavor_id):
89 91
    # Normal Response Codes: 200, 203
......
93 95
    #                       badRequest (400),
94 96
    #                       itemNotFound (404),
95 97
    #                       overLimit (413)
96
    
98

  
97 99
    log.debug('get_flavor_details %s', flavor_id)
98 100
    flavor = util.get_flavor(flavor_id, include_deleted=True)
99 101
    flavordict = flavor_to_dict(flavor, detail=True)
b/snf-cyclades-app/synnefo/api/images.py
1 1
# Copyright 2011-2012 GRNET S.A. All rights reserved.
2
# 
2
#
3 3
# Redistribution and use in source and binary forms, with or
4 4
# without modification, are permitted provided that the following
5 5
# conditions are met:
6
# 
6
#
7 7
#   1. Redistributions of source code must retain the above
8 8
#      copyright notice, this list of conditions and the following
9 9
#      disclaimer.
10
# 
10
#
11 11
#   2. Redistributions in binary form must reproduce the above
12 12
#      copyright notice, this list of conditions and the following
13 13
#      disclaimer in the documentation and/or other materials
14 14
#      provided with the distribution.
15
# 
15
#
16 16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
......
25 25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 27
# POSSIBILITY OF SUCH DAMAGE.
28
# 
28
#
29 29
# The views and conclusions contained in the software and
30 30
# documentation are those of the authors and should not be
31 31
# interpreted as representing official policies, either expressed
......
112 112
    #                       unauthorized (401),
113 113
    #                       badRequest (400),
114 114
    #                       overLimit (413)
115
    
115

  
116 116
    log.debug('list_images detail=%s', detail)
117 117
    backend = ImageBackend(request.user_uniq)
118
    
118

  
119 119
    since = isoparse(request.GET.get('changes-since'))
120 120
    if since:
121 121
        images = []
......
127 127
            return HttpResponse(status=304)
128 128
    else:
129 129
        images = backend.list()
130
    
130

  
131
    images = sorted(images, key=lambda x: x['id'])
131 132
    reply = [image_to_dict(image, detail) for image in images]
132
    
133

  
133 134
    if request.serialization == 'xml':
134 135
        data = render_to_string('list_images.xml',
135 136
                                dict(images=reply, detail=detail))
136 137
    else:
137 138
        data = json.dumps(dict(images={'values': reply}))
138
    
139

  
139 140
    return HttpResponse(data, status=200)
140 141

  
141 142

  
......
153 154
    #                       resizeNotAllowed (403),
154 155
    #                       backupOrResizeInProgress (409),
155 156
    #                       overLimit (413)
156
    
157

  
157 158
    raise ServiceUnavailable('Not supported.')
158 159

  
159 160

  
......
166 167
    #                       badRequest (400),
167 168
    #                       itemNotFound (404),
168 169
    #                       overLimit (413)
169
    
170

  
170 171
    log.debug('get_image_details %s', image_id)
171 172
    image = util.get_image(image_id, request.user_uniq)
172 173
    reply = image_to_dict(image)
173
    
174

  
174 175
    if request.serialization == 'xml':
175 176
        data = render_to_string('image.xml', dict(image=reply))
176 177
    else:
177 178
        data = json.dumps(dict(image=reply))
178
    
179

  
179 180
    return HttpResponse(data, status=200)
180 181

  
181 182

  
......
187 188
    #                       unauthorized (401),
188 189
    #                       itemNotFound (404),
189 190
    #                       overLimit (413)
190
    
191

  
191 192
    log.info('delete_image %s', image_id)
192 193
    backend = ImageBackend(request.user_uniq)
193 194
    backend.delete(image_id)
......
204 205
    #                       unauthorized (401),
205 206
    #                       badRequest (400),
206 207
    #                       overLimit (413)
207
    
208

  
208 209
    log.debug('list_image_metadata %s', image_id)
209 210
    image = util.get_image(image_id, request.user_uniq)
210 211
    metadata = image['properties']
......
221 222
    #                       buildInProgress (409),
222 223
    #                       badMediaType(415),
223 224
    #                       overLimit (413)
224
    
225

  
225 226
    req = util.get_request_dict(request)
226 227
    log.info('update_image_metadata %s %s', image_id, req)
227 228
    image = util.get_image(image_id, request.user_uniq)
......
230 231
        assert isinstance(metadata, dict)
231 232
    except (KeyError, AssertionError):
232 233
        raise BadRequest('Malformed request.')
233
    
234

  
234 235
    properties = image['properties']
235 236
    properties.update(metadata)
236
    
237

  
237 238
    backend = ImageBackend(request.user_uniq)
238 239
    backend.update(image_id, dict(properties=properties))
239 240
    backend.close()
240
    
241

  
241 242
    return util.render_metadata(request, properties, status=201)
242 243

  
243 244

  
......
250 251
    #                       itemNotFound (404),
251 252
    #                       badRequest (400),
252 253
    #                       overLimit (413)
253
    
254

  
254 255
    log.debug('get_image_metadata_item %s %s', image_id, key)
255 256
    image = util.get_image(image_id, request.user_uniq)
256 257
    val = image['properties'].get(key)
......
270 271
    #                       buildInProgress (409),
271 272
    #                       badMediaType(415),
272 273
    #                       overLimit (413)
273
    
274

  
274 275
    req = util.get_request_dict(request)
275 276
    log.info('create_image_metadata_item %s %s %s', image_id, key, req)
276 277
    try:
......
285 286
    image = util.get_image(image_id, request.user_uniq)
286 287
    properties = image['properties']
287 288
    properties[key] = val
288
    
289

  
289 290
    backend = ImageBackend(request.user_uniq)
290 291
    backend.update(image_id, dict(properties=properties))
291 292
    backend.close()
292
    
293

  
293 294
    return util.render_meta(request, {key: val}, status=201)
294 295

  
295 296

  
......
304 305
    #                       buildInProgress (409),
305 306
    #                       badMediaType(415),
306 307
    #                       overLimit (413),
307
    
308

  
308 309
    log.info('delete_image_metadata_item %s %s', image_id, key)
309 310
    image = util.get_image(image_id, request.user_uniq)
310 311
    properties = image['properties']
311 312
    properties.pop(key, None)
312
    
313

  
313 314
    backend = ImageBackend(request.user_uniq)
314 315
    backend.update(image_id, dict(properties=properties))
315 316
    backend.close()
316
    
317

  
317 318
    return HttpResponse(status=204)
b/snf-cyclades-app/synnefo/api/networks.py
96 96
        d['public'] = network.public
97 97

  
98 98
        attachments = [util.construct_nic_id(nic)
99
                       for nic in network.nics.filter(machine__userid=user_id)]
99
                       for nic in network.nics.filter(machine__userid=user_id)\
100
                                              .order_by('machine')]
100 101
        d['attachments'] = {'values': attachments}
101 102
    return d
102 103

  
......
131 132
        user_networks = user_networks.filter(deleted=False)
132 133

  
133 134
    networks = [network_to_dict(network, request.user_uniq, detail)
134
                for network in user_networks]
135
                for network in user_networks.order_by('id')]
135 136

  
136 137
    if request.serialization == 'xml':
137 138
        data = render_to_string('list_networks.xml', {
b/snf-cyclades-app/synnefo/api/servers.py
137 137
        if metadata:
138 138
            d['metadata'] = {'values': metadata}
139 139

  
140
        attachments = [nic_to_dict(nic) for nic in vm.nics.all()]
140
        attachments = [nic_to_dict(nic) for nic in vm.nics.order_by('index')]
141 141
        if attachments:
142 142
            d['attachments'] = {'values': attachments}
143 143

  
......
226 226
    else:
227 227
        user_vms = user_vms.filter(deleted=False)
228 228

  
229
    servers = [vm_to_dict(server, detail) for server in user_vms]
229
    servers = [vm_to_dict(server, detail)\
230
               for server in user_vms.order_by('id')]
230 231

  
231 232
    if request.serialization == 'xml':
232 233
        data = render_to_string('list_servers.xml', {

Also available in: Unified diff