summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-11-28 22:55:01 +0000
committerGerrit Code Review <review@openstack.org>2012-11-28 22:55:01 +0000
commit0c618982f790cca34729ef3fcd001e566a15de8d (patch)
treeedf6bd49e73402fd37f21090ff00c5084ab23172
parentaaa1c3145a39e7b850edebcc8262b5da751fb8af (diff)
parent8c7fe145a76793c42786d9baaea63301c3dd5b6e (diff)
downloadnova-0c618982f790cca34729ef3fcd001e566a15de8d.tar.gz
nova-0c618982f790cca34729ef3fcd001e566a15de8d.tar.xz
nova-0c618982f790cca34729ef3fcd001e566a15de8d.zip
Merge "Include 'hosts' and 'metadetails' in aggregate."
-rw-r--r--nova/compute/api.py9
-rw-r--r--nova/db/sqlalchemy/api.py26
-rw-r--r--nova/db/sqlalchemy/models.py3
3 files changed, 31 insertions, 7 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index c937b7cf5..79db499bd 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -2159,7 +2159,11 @@ class AggregateAPI(base.Base):
values = {"name": aggregate_name,
"availability_zone": availability_zone}
aggregate = self.db.aggregate_create(context, values)
- return dict(aggregate.iteritems())
+ aggregate = self._get_aggregate_info(context, aggregate)
+ # To maintain the same API result as before.
+ del aggregate['hosts']
+ del aggregate['metadata']
+ return aggregate
else:
raise exception.InvalidAggregateAction(action='create_aggregate',
aggregate_id="'N/A'",
@@ -2236,6 +2240,9 @@ class AggregateAPI(base.Base):
metadata = self.db.aggregate_metadata_get(context, aggregate.id)
hosts = self.db.aggregate_host_get_all(context, aggregate.id)
result = dict(aggregate.iteritems())
+ # metadetails was not originally included here. We need to pull it
+ # back out to maintain API stability.
+ del result['metadetails']
result["metadata"] = metadata
result["hosts"] = hosts
return result
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index ba7c6bacf..c4558a84c 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -4173,10 +4173,20 @@ def s3_image_create(context, image_uuid):
####################
-def _aggregate_get_query(context, model_class, id_field, id,
+def _aggregate_get_query(context, model_class, id_field=None, id=None,
session=None, read_deleted=None):
- return model_query(context, model_class, session=session,
- read_deleted=read_deleted).filter(id_field == id)
+ columns_to_join = {models.Aggregate: ['_hosts', '_metadata']}
+
+ query = model_query(context, model_class, session=session,
+ read_deleted=read_deleted)
+
+ for c in columns_to_join.get(model_class, []):
+ query = query.options(joinedload(c))
+
+ if id and id_field:
+ query = query.filter(id_field == id)
+
+ return query
@require_admin_context
@@ -4192,6 +4202,10 @@ def aggregate_create(context, values, metadata=None):
aggregate = models.Aggregate()
aggregate.update(values)
aggregate.save(session=session)
+ # We don't want these to be lazy loaded later. We know there is
+ # nothing here since we just created this aggregate.
+ aggregate._hosts = []
+ aggregate._metadata = []
else:
raise exception.AggregateNameExists(aggregate_name=values['name'])
if metadata:
@@ -4214,8 +4228,8 @@ def aggregate_get(context, aggregate_id):
@require_admin_context
def aggregate_get_by_host(context, host, key=None):
- query = model_query(context, models.Aggregate).join(
- "_hosts").filter(models.AggregateHost.host == host)
+ query = _aggregate_get_query(context, models.Aggregate,
+ models.AggregateHost.host, host)
if key:
query = query.join("_metadata").filter(
@@ -4287,7 +4301,7 @@ def aggregate_delete(context, aggregate_id):
@require_admin_context
def aggregate_get_all(context):
- return model_query(context, models.Aggregate).all()
+ return _aggregate_get_query(context, models.Aggregate).all()
@require_admin_context
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index 48caaf18d..a09517b67 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -900,6 +900,9 @@ class Aggregate(BASE, NovaBase):
'Aggregate.deleted == False)',
backref='aggregates')
+ def _extra_keys(self):
+ return ['hosts', 'metadetails']
+
@property
def hosts(self):
return [h.host for h in self._hosts]