~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/api/openstack/common.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
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
192
192
    if marker:
193
193
        start_index = -1
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:
 
197
                    start_index = i + 1
 
198
                    break
 
199
            elif item['id'] == marker or item.get('uuid') == marker:
196
200
                start_index = i + 1
197
201
                break
198
202
        if start_index < 0:
265
269
        return '2'
266
270
 
267
271
 
268
 
def check_img_metadata_quota_limit(context, metadata):
 
272
def check_img_metadata_properties_quota(context, metadata):
269
273
    if metadata is None:
270
274
        return
271
275
    num_metadata = len(metadata)
275
279
        raise webob.exc.HTTPRequestEntityTooLarge(explanation=expl,
276
280
                                                headers={'Retry-After': 0})
277
281
 
 
282
    #  check the key length.
 
283
    if isinstance(metadata, dict):
 
284
        for key, value in metadata.iteritems():
 
285
            if len(key) == 0:
 
286
                expl = _("Image metadata key cannot be blank")
 
287
                raise webob.exc.HTTPBadRequest(explanation=expl)
 
288
            if len(key) > 255:
 
289
                expl = _("Image metadata key too long")
 
290
                raise webob.exc.HTTPBadRequest(explanation=expl)
 
291
    else:
 
292
        expl = _("Invalid image metadata")
 
293
        raise webob.exc.HTTPBadRequest(explanation=expl)
 
294
 
278
295
 
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."""
427
444
 
428
 
    _collection_name = None
429
 
 
430
 
    def _get_links(self, request, identifier):
 
445
    def _get_links(self, request, identifier, collection_name):
431
446
        return [{
432
447
            "rel": "self",
433
 
            "href": self._get_href_link(request, identifier),
 
448
            "href": self._get_href_link(request, identifier, collection_name),
434
449
        },
435
450
        {
436
451
            "rel": "bookmark",
437
 
            "href": self._get_bookmark_link(request, identifier),
 
452
            "href": self._get_bookmark_link(request,
 
453
                                            identifier,
 
454
                                            collection_name),
438
455
        }]
439
456
 
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)
 
465
                           collection_name)
449
466
        return "%s?%s" % (url, dict_to_query_str(params))
450
467
 
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,
 
474
                            collection_name,
458
475
                            str(identifier))
459
476
 
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,
 
484
                            collection_name,
468
485
                            str(identifier))
469
486
 
470
 
    def _get_collection_links(self, request, items, id_key="uuid"):
 
487
    def _get_collection_links(self,
 
488
                              request,
 
489
                              items,
 
490
                              collection_name,
 
491
                              id_key="uuid"):
471
492
        """Retrieve 'next' link, if applicable."""
472
493
        links = []
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"]
478
501
            else:
479
 
                last_item_id = last_item["id"]
 
502
                last_item_id = last_item["flavorid"]
480
503
            links.append({
481
504
                "rel": "next",
482
 
                "href": self._get_next_link(request, last_item_id),
 
505
                "href": self._get_next_link(request,
 
506
                                            last_item_id,
 
507
                                            collection_name),
483
508
            })
484
509
        return links
485
510