Merge "Make aggregate methods use new-world objects"
This commit is contained in:
commit
9fb39ab5ea
|
@ -3200,8 +3200,7 @@ class AggregateAPI(base.Base):
|
|||
aggregate.add_host(context, host_name)
|
||||
#NOTE(jogo): Send message to host to support resource pools
|
||||
self.compute_rpcapi.add_aggregate_host(context,
|
||||
aggregate=obj_base.obj_to_primitive(aggregate),
|
||||
host_param=host_name, host=host_name)
|
||||
aggregate=aggregate, host_param=host_name, host=host_name)
|
||||
aggregate_payload.update({'name': aggregate['name']})
|
||||
compute_utils.notify_about_aggregate_update(context,
|
||||
"addhost.end",
|
||||
|
@ -3221,8 +3220,7 @@ class AggregateAPI(base.Base):
|
|||
aggregate = aggregate_obj.Aggregate.get_by_id(context, aggregate_id)
|
||||
aggregate.delete_host(host_name)
|
||||
self.compute_rpcapi.remove_aggregate_host(context,
|
||||
aggregate=obj_base.obj_to_primitive(aggregate),
|
||||
host_param=host_name, host=host_name)
|
||||
aggregate=aggregate, host_param=host_name, host=host_name)
|
||||
compute_utils.notify_about_aggregate_update(context,
|
||||
"removehost.end",
|
||||
aggregate_payload)
|
||||
|
|
|
@ -61,6 +61,7 @@ from nova import network
|
|||
from nova.network import model as network_model
|
||||
from nova.network.security_group import openstack_driver
|
||||
from nova import notifier
|
||||
from nova.objects import aggregate as aggregate_obj
|
||||
from nova.objects import base as obj_base
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova.objects import migration as migration_obj
|
||||
|
@ -355,6 +356,22 @@ def object_compat(function):
|
|||
return decorated_function
|
||||
|
||||
|
||||
# TODO(danms): Remove me after Icehouse
|
||||
def aggregate_object_compat(function):
|
||||
"""Wraps a method that expects a new-world aggregate."""
|
||||
|
||||
@functools.wraps(function)
|
||||
def decorated_function(self, context, *args, **kwargs):
|
||||
aggregate = kwargs.get('aggregate')
|
||||
if isinstance(aggregate, dict):
|
||||
aggregate = aggregate_obj.Aggregate._from_db_object(
|
||||
context.elevated(), aggregate_obj.Aggregate(),
|
||||
aggregate)
|
||||
kwargs['aggregate'] = aggregate
|
||||
return function(self, context, *args, **kwargs)
|
||||
return decorated_function
|
||||
|
||||
|
||||
def _get_image_meta(context, image_ref):
|
||||
image_service, image_id = glance.get_remote_image_service(context,
|
||||
image_ref)
|
||||
|
@ -419,7 +436,7 @@ class ComputeVirtAPI(virtapi.VirtAPI):
|
|||
class ComputeManager(manager.SchedulerDependentManager):
|
||||
"""Manages the running instances from creation to destruction."""
|
||||
|
||||
RPC_API_VERSION = '2.47'
|
||||
RPC_API_VERSION = '2.48'
|
||||
|
||||
def __init__(self, compute_driver=None, *args, **kwargs):
|
||||
"""Load configuration options and connect to the hypervisor."""
|
||||
|
@ -4991,12 +5008,16 @@ class ComputeManager(manager.SchedulerDependentManager):
|
|||
self._quota_rollback(context, reservations)
|
||||
self._set_instance_error_state(context, instance_uuid)
|
||||
|
||||
@aggregate_object_compat
|
||||
@wrap_exception()
|
||||
def add_aggregate_host(self, context, host, slave_info=None,
|
||||
aggregate=None, aggregate_id=None):
|
||||
"""Notify hypervisor of change (for hypervisor pools)."""
|
||||
if not aggregate:
|
||||
aggregate = self.conductor_api.aggregate_get(context, aggregate_id)
|
||||
aggregate_obj.Aggregate.get_by_id(context, aggregate_id)
|
||||
|
||||
# NOTE(danms): until the drivers support objects, use primitives
|
||||
aggregate = obj_base.obj_to_primitive(aggregate)
|
||||
|
||||
try:
|
||||
self.driver.add_to_aggregate(context, aggregate, host,
|
||||
|
@ -5011,12 +5032,16 @@ class ComputeManager(manager.SchedulerDependentManager):
|
|||
self.conductor_api.aggregate_host_delete,
|
||||
aggregate, host)
|
||||
|
||||
@aggregate_object_compat
|
||||
@wrap_exception()
|
||||
def remove_aggregate_host(self, context, host, slave_info=None,
|
||||
aggregate=None, aggregate_id=None):
|
||||
"""Removes a host from a physical hypervisor pool."""
|
||||
if not aggregate:
|
||||
aggregate = self.conductor_api.aggregate_get(context, aggregate_id)
|
||||
aggregate_obj.Aggregate.get_by_id(context, aggregate_id)
|
||||
|
||||
# NOTE(danms): until the drivers support objects, use primitives
|
||||
aggregate = obj_base.obj_to_primitive(aggregate)
|
||||
|
||||
try:
|
||||
self.driver.remove_from_aggregate(context, aggregate, host,
|
||||
|
|
|
@ -202,6 +202,8 @@ class ComputeAPI(rpcclient.RpcProxy):
|
|||
2.45 - Made resize_instance() take new-world objects
|
||||
2.46 - Made finish_resize() take new-world objects
|
||||
2.47 - Made finish_revert_resize() take new-world objects
|
||||
2.48 - Make add_aggregate_host() and remove_aggregate_host() take
|
||||
new-world objects
|
||||
'''
|
||||
|
||||
#
|
||||
|
@ -239,10 +241,14 @@ class ComputeAPI(rpcclient.RpcProxy):
|
|||
:param host: This is the host to send the message to.
|
||||
'''
|
||||
|
||||
aggregate_p = jsonutils.to_primitive(aggregate)
|
||||
cctxt = self.client.prepare(server=host, version='2.14')
|
||||
if self.client.can_send_version('2.48'):
|
||||
version = '2.48'
|
||||
else:
|
||||
version = '2.14'
|
||||
aggregate = jsonutils.to_primitive(aggregate)
|
||||
cctxt = self.client.prepare(server=host, version=version)
|
||||
cctxt.cast(ctxt, 'add_aggregate_host',
|
||||
aggregate=aggregate_p, host=host_param,
|
||||
aggregate=aggregate, host=host_param,
|
||||
slave_info=slave_info)
|
||||
|
||||
def add_fixed_ip_to_instance(self, ctxt, instance, network_id):
|
||||
|
@ -555,10 +561,14 @@ class ComputeAPI(rpcclient.RpcProxy):
|
|||
:param host: This is the host to send the message to.
|
||||
'''
|
||||
|
||||
aggregate_p = jsonutils.to_primitive(aggregate)
|
||||
cctxt = self.client.prepare(server=host, version='2.15')
|
||||
if self.client.can_send_version('2.48'):
|
||||
version = '2.48'
|
||||
else:
|
||||
version = '2.15'
|
||||
aggregate = jsonutils.to_primitive(aggregate)
|
||||
cctxt = self.client.prepare(server=host, version=version)
|
||||
cctxt.cast(ctxt, 'remove_aggregate_host',
|
||||
aggregate=aggregate_p, host=host_param,
|
||||
aggregate=aggregate, host=host_param,
|
||||
slave_info=slave_info)
|
||||
|
||||
def remove_fixed_ip_from_instance(self, ctxt, instance, address):
|
||||
|
|
|
@ -100,7 +100,7 @@ class ComputeRpcAPITestCase(test.TestCase):
|
|||
def test_add_aggregate_host(self):
|
||||
self._test_compute_api('add_aggregate_host', 'cast',
|
||||
aggregate={'id': 'fake_id'}, host_param='host', host='host',
|
||||
slave_info={}, version='2.14')
|
||||
slave_info={}, version='2.48')
|
||||
|
||||
def test_add_fixed_ip_to_instance(self):
|
||||
self._test_compute_api('add_fixed_ip_to_instance', 'cast',
|
||||
|
@ -303,7 +303,7 @@ class ComputeRpcAPITestCase(test.TestCase):
|
|||
def test_remove_aggregate_host(self):
|
||||
self._test_compute_api('remove_aggregate_host', 'cast',
|
||||
aggregate={'id': 'fake_id'}, host_param='host', host='host',
|
||||
slave_info={}, version='2.15')
|
||||
slave_info={}, version='2.48')
|
||||
|
||||
def test_remove_fixed_ip_from_instance(self):
|
||||
self._test_compute_api('remove_fixed_ip_from_instance', 'cast',
|
||||
|
|
Loading…
Reference in New Issue