~hudson-openstack/nova/trunk

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Rick Harris
  • Date: 2011-09-22 16:42:20 UTC
  • mfrom: (1590.1.11 flavor_min_filter)
  • Revision ID: tarmac-20110922164220-ndscikwberuj3c7f
This patch adds flavor filtering, specifically the ability to flavor on minRam, minDisk, or both, per the 1.1 OSAPI spec.

In addition, this patch refactors instance_type_get_all to return a *list* of instance_types instead of a *dict*. This makes it more consistent with the rest of the DB API.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
    def _get_flavors(self, req, is_detail=True):
45
45
        """Helper function that returns a list of flavor dicts."""
 
46
        filters = {}
 
47
        if 'minRam' in req.params:
 
48
            try:
 
49
                filters['min_memory_mb'] = int(req.params['minRam'])
 
50
            except ValueError:
 
51
                pass  # ignore bogus values per spec
 
52
 
 
53
        if 'minDisk' in req.params:
 
54
            try:
 
55
                filters['min_local_gb'] = int(req.params['minDisk'])
 
56
            except ValueError:
 
57
                pass  # ignore bogus values per spec
 
58
 
46
59
        ctxt = req.environ['nova.context']
47
 
        flavors = db.api.instance_type_get_all(ctxt)
 
60
        inst_types = db.api.instance_type_get_all(ctxt, filters=filters)
48
61
        builder = self._get_view_builder(req)
49
 
        items = [builder.build(flavor, is_detail=is_detail)
50
 
                 for flavor in flavors.values()]
 
62
        items = [builder.build(inst_type, is_detail=is_detail)
 
63
                 for inst_type in inst_types]
51
64
        return items
52
65
 
53
66
    def show(self, req, id):