Make compute_api use Aggregate objects
This makes the compute_api's AggregateAPI use the new Aggregate object for its work. Related to blueprint compute-api-objects Change-Id: I97419bfe6c605306bd64f9aa4fce9657509df260
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
|
||||
"""The Aggregate admin API extension."""
|
||||
|
||||
import datetime
|
||||
|
||||
from webob import exc
|
||||
|
||||
from nova.api.openstack import extensions
|
||||
@@ -53,7 +55,8 @@ class AggregateController(object):
|
||||
context = _get_context(req)
|
||||
authorize(context)
|
||||
aggregates = self.api.get_aggregate_list(context)
|
||||
return {'aggregates': aggregates}
|
||||
return {'aggregates': [self._marshall_aggregate(a)['aggregate']
|
||||
for a in aggregates]}
|
||||
|
||||
def create(self, req, body):
|
||||
"""Creates an aggregate, given its name and availability_zone."""
|
||||
@@ -214,7 +217,13 @@ class AggregateController(object):
|
||||
return self._marshall_aggregate(aggregate)
|
||||
|
||||
def _marshall_aggregate(self, aggregate):
|
||||
return {"aggregate": aggregate}
|
||||
_aggregate = {}
|
||||
for key, value in aggregate.items():
|
||||
# NOTE(danms): The original API specified non-TZ-aware timestamps
|
||||
if isinstance(value, datetime.datetime):
|
||||
value = value.replace(tzinfo=None)
|
||||
_aggregate[key] = value
|
||||
return {"aggregate": _aggregate}
|
||||
|
||||
|
||||
class Aggregates(extensions.ExtensionDescriptor):
|
||||
|
@@ -15,6 +15,8 @@
|
||||
|
||||
"""The Aggregate admin API extension."""
|
||||
|
||||
import datetime
|
||||
|
||||
from webob import exc
|
||||
|
||||
from nova.api.openstack import extensions
|
||||
@@ -58,7 +60,8 @@ class AggregateController(wsgi.Controller):
|
||||
context = _get_context(req)
|
||||
authorize(context)
|
||||
aggregates = self.api.get_aggregate_list(context)
|
||||
return {'aggregates': aggregates}
|
||||
return {'aggregates': [self._marshall_aggregate(a)['aggregate']
|
||||
for a in aggregates]}
|
||||
|
||||
@wsgi.response(201)
|
||||
def create(self, req, body):
|
||||
@@ -210,7 +213,13 @@ class AggregateController(wsgi.Controller):
|
||||
return self._marshall_aggregate(aggregate)
|
||||
|
||||
def _marshall_aggregate(self, aggregate):
|
||||
return {"aggregate": aggregate}
|
||||
_aggregate = {}
|
||||
for key, value in aggregate.items():
|
||||
# NOTE(danms): The original API specified non-TZ-aware timestamps
|
||||
if isinstance(value, datetime.datetime):
|
||||
value = value.replace(tzinfo=None)
|
||||
_aggregate[key] = value
|
||||
return {"aggregate": _aggregate}
|
||||
|
||||
|
||||
class Aggregates(extensions.V3APIExtensionBase):
|
||||
|
@@ -306,6 +306,7 @@ class AggregateTestCase(test.TestCase):
|
||||
self.assertEqual("1", aggregate, "aggregate")
|
||||
self.assertEqual("host1", host, "host")
|
||||
stub_remove_host_from_aggregate.called = True
|
||||
return {}
|
||||
self.stubs.Set(self.controller.api,
|
||||
"remove_host_from_aggregate",
|
||||
stub_remove_host_from_aggregate)
|
||||
|
@@ -289,6 +289,7 @@ class AggregateTestCase(test.TestCase):
|
||||
self.assertEqual("1", aggregate, "aggregate")
|
||||
self.assertEqual("host1", host, "host")
|
||||
stub_remove_host_from_aggregate.called = True
|
||||
return {}
|
||||
self.stubs.Set(self.controller.api,
|
||||
"remove_host_from_aggregate",
|
||||
stub_remove_host_from_aggregate)
|
||||
|
Reference in New Issue
Block a user