26
26
from nova.api.openstack import wsgi
27
27
from nova.api.openstack import xmlutil
28
from nova.compute import task_states
28
29
from nova.compute import vm_states
29
from nova.compute import task_states
30
30
from nova import flags
31
31
from nova import log as logging
32
32
from nova.network import model as network_model
194
194
for i, item in enumerate(items):
195
if item['id'] == marker or item.get('uuid') == marker:
195
if 'flavorid' in item:
196
if item['flavorid'] == marker:
199
elif item['id'] == marker or item.get('uuid') == marker:
196
200
start_index = i + 1
198
202
if start_index < 0:
275
279
raise webob.exc.HTTPRequestEntityTooLarge(explanation=expl,
276
280
headers={'Retry-After': 0})
282
# check the key length.
283
if isinstance(metadata, dict):
284
for key, value in metadata.iteritems():
286
expl = _("Image metadata key cannot be blank")
287
raise webob.exc.HTTPBadRequest(explanation=expl)
289
expl = _("Image metadata key too long")
290
raise webob.exc.HTTPBadRequest(explanation=expl)
292
expl = _("Invalid image metadata")
293
raise webob.exc.HTTPBadRequest(explanation=expl)
279
296
def dict_to_query_str(params):
280
297
# TODO(throughnothing): we should just use urllib.urlencode instead of this
425
442
class ViewBuilder(object):
426
443
"""Model API responses as dictionaries."""
428
_collection_name = None
430
def _get_links(self, request, identifier):
445
def _get_links(self, request, identifier, collection_name):
433
"href": self._get_href_link(request, identifier),
448
"href": self._get_href_link(request, identifier, collection_name),
436
451
"rel": "bookmark",
437
"href": self._get_bookmark_link(request, identifier),
452
"href": self._get_bookmark_link(request,
440
def _get_next_link(self, request, identifier):
457
def _get_next_link(self, request, identifier, collection_name):
441
458
"""Return href string with proper limit and marker params."""
442
459
params = request.params.copy()
443
460
params["marker"] = identifier
445
462
FLAGS.osapi_compute_link_prefix)
446
463
url = os.path.join(prefix,
447
464
request.environ["nova.context"].project_id,
448
self._collection_name)
449
466
return "%s?%s" % (url, dict_to_query_str(params))
451
def _get_href_link(self, request, identifier):
468
def _get_href_link(self, request, identifier, collection_name):
452
469
"""Return an href string pointing to this object."""
453
470
prefix = self._update_link_prefix(request.application_url,
454
471
FLAGS.osapi_compute_link_prefix)
455
472
return os.path.join(prefix,
456
473
request.environ["nova.context"].project_id,
457
self._collection_name,
460
def _get_bookmark_link(self, request, identifier):
477
def _get_bookmark_link(self, request, identifier, collection_name):
461
478
"""Create a URL that refers to a specific resource."""
462
479
base_url = remove_version_from_href(request.application_url)
463
480
base_url = self._update_link_prefix(base_url,
464
481
FLAGS.osapi_compute_link_prefix)
465
482
return os.path.join(base_url,
466
483
request.environ["nova.context"].project_id,
467
self._collection_name,
470
def _get_collection_links(self, request, items, id_key="uuid"):
487
def _get_collection_links(self,
471
492
"""Retrieve 'next' link, if applicable."""
473
494
limit = int(request.params.get("limit", 0))
475
496
last_item = items[-1]
476
497
if id_key in last_item:
477
498
last_item_id = last_item[id_key]
499
elif 'id' in last_item:
500
last_item_id = last_item["id"]
479
last_item_id = last_item["id"]
502
last_item_id = last_item["flavorid"]
482
"href": self._get_next_link(request, last_item_id),
505
"href": self._get_next_link(request,