summaryrefslogtreecommitdiffstats
path: root/nova/compute
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2012-03-10 13:12:27 -0500
committerRussell Bryant <rbryant@redhat.com>2012-03-13 11:26:39 -0400
commita3a7464a8de96e219f40049fdd03b41cb8eb65ca (patch)
tree319c92c4db3b0275841541f21874b9b1007efbc6 /nova/compute
parent777852191aa9bad3297ab3fe48701e8ec5266d17 (diff)
Sort results from describe_instances in EC2 API.
Fix bug 827619. This bug pointed out that EC2 sorts the results of of describe_instances by the launch time. Make our implementation of the EC2 API behave the same way. Previously, instances coming out of the db API were sorted by the key we wanted, but in the opposite order. You can now specify both a sort key and order. The behavior is the same by default, but the EC2 API sets the parameter to do an ascending sort. Change-Id: Ifd0bc79ad4c4c8c45809dbb1ac2dadf8abcfd4c3
Diffstat (limited to 'nova/compute')
-rw-r--r--nova/compute/api.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 71d7627d5..79e490395 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -1028,7 +1028,8 @@ class API(base.Base):
inst['name'] = instance['name']
return inst
- def get_all(self, context, search_opts=None):
+ def get_all(self, context, search_opts=None, sort_key='created_at',
+ sort_dir='desc'):
"""Get all instances filtered by one of the given parameters.
If there is no filter and the context is an admin, it will retrieve
@@ -1036,6 +1037,10 @@ class API(base.Base):
Deleted instances will be returned by default, unless there is a
search option that says otherwise.
+
+ The results will be returned sorted in the order specified by the
+ 'sort_dir' parameter using the key specified in the 'sort_key'
+ parameter.
"""
#TODO(bcwaldon): determine the best argument for target here
@@ -1101,7 +1106,8 @@ class API(base.Base):
except ValueError:
return []
- inst_models = self._get_instances_by_filters(context, filters)
+ inst_models = self._get_instances_by_filters(context, filters,
+ sort_key, sort_dir)
# Convert the models to dictionaries
instances = []
@@ -1113,7 +1119,7 @@ class API(base.Base):
return instances
- def _get_instances_by_filters(self, context, filters):
+ def _get_instances_by_filters(self, context, filters, sort_key, sort_dir):
if 'ip6' in filters or 'ip' in filters:
res = self.network_api.get_instance_uuids_by_ip_filter(context,
filters)
@@ -1122,7 +1128,8 @@ class API(base.Base):
uuids = set([r['instance_uuid'] for r in res])
filters['uuid'] = uuids
- return self.db.instance_get_all_by_filters(context, filters)
+ return self.db.instance_get_all_by_filters(context, filters, sort_key,
+ sort_dir)
@wrap_check_policy
@check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.SHUTOFF])