diff options
| author | Rick Harris <rconradharris@gmail.com> | 2011-09-22 16:42:20 +0000 |
|---|---|---|
| committer | Tarmac <> | 2011-09-22 16:42:20 +0000 |
| commit | 853aad905531fbdf6d5ddce4bc26b3caeebbc49f (patch) | |
| tree | ee68427dd6123007ef6ca57fed367e5db32bc03c /nova/api | |
| parent | f81b8e1efe0fdce003078b1ae328c7bee18e875d (diff) | |
| parent | b1daaa0b216d341c69421e4d9666e73860eec68c (diff) | |
| download | nova-853aad905531fbdf6d5ddce4bc26b3caeebbc49f.tar.gz nova-853aad905531fbdf6d5ddce4bc26b3caeebbc49f.tar.xz nova-853aad905531fbdf6d5ddce4bc26b3caeebbc49f.zip | |
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.
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/ec2/admin.py | 5 | ||||
| -rw-r--r-- | nova/api/openstack/flavors.py | 19 |
2 files changed, 19 insertions, 5 deletions
diff --git a/nova/api/ec2/admin.py b/nova/api/ec2/admin.py index 75e029509..c1b1fa53a 100644 --- a/nova/api/ec2/admin.py +++ b/nova/api/ec2/admin.py @@ -126,8 +126,9 @@ class AdminController(object): def describe_instance_types(self, context, **_kwargs): """Returns all active instance types data (vcpus, memory, etc.)""" - return {'instanceTypeSet': [instance_dict(v) for v in - db.instance_type_get_all(context).values()]} + inst_types = db.instance_type_get_all(context) + inst_type_dicts = [instance_dict(i) for i in inst_types] + return {'instanceTypeSet': inst_type_dicts} def describe_user(self, _context, name, **_kwargs): """Returns user data, including access and secret keys.""" diff --git a/nova/api/openstack/flavors.py b/nova/api/openstack/flavors.py index 8a310c900..b9dd96f4e 100644 --- a/nova/api/openstack/flavors.py +++ b/nova/api/openstack/flavors.py @@ -43,11 +43,24 @@ class Controller(object): def _get_flavors(self, req, is_detail=True): """Helper function that returns a list of flavor dicts.""" + filters = {} + if 'minRam' in req.params: + try: + filters['min_memory_mb'] = int(req.params['minRam']) + except ValueError: + pass # ignore bogus values per spec + + if 'minDisk' in req.params: + try: + filters['min_local_gb'] = int(req.params['minDisk']) + except ValueError: + pass # ignore bogus values per spec + ctxt = req.environ['nova.context'] - flavors = db.api.instance_type_get_all(ctxt) + inst_types = db.api.instance_type_get_all(ctxt, filters=filters) builder = self._get_view_builder(req) - items = [builder.build(flavor, is_detail=is_detail) - for flavor in flavors.values()] + items = [builder.build(inst_type, is_detail=is_detail) + for inst_type in inst_types] return items def show(self, req, id): |
