From 82afe7ad5eac668aaefc79e16bbf2226eddde97d Mon Sep 17 00:00:00 2001 From: "Kevin L. Mitchell" Date: Wed, 25 Jul 2012 15:31:11 -0500 Subject: Inject instance metadata into xenstore When using Xenserver, inject instance metadata into the xenstore, for the use of the instance. Implements blueprint xenstore-metadata. Change-Id: I88a59f1b783eaaaef6ba5efd8bd448aece2f869c --- nova/compute/api.py | 10 +++++++++- nova/compute/manager.py | 12 +++++++++++- nova/compute/rpcapi.py | 7 +++++++ 3 files changed, 27 insertions(+), 2 deletions(-) (limited to 'nova/compute') diff --git a/nova/compute/api.py b/nova/compute/api.py index eb23a2412..e5b6fb1b3 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1595,6 +1595,9 @@ class API(base.Base): def delete_instance_metadata(self, context, instance, key): """Delete the given metadata item from an instance.""" self.db.instance_metadata_delete(context, instance['uuid'], key) + self.compute_rpcapi.change_instance_metadata(context, + instance=instance, + diff={key: ['-']}) @wrap_check_policy def update_instance_metadata(self, context, instance, @@ -1605,15 +1608,20 @@ class API(base.Base): `metadata` argument will be deleted. """ + orig = self.get_instance_metadata(context, instance) if delete: _metadata = metadata else: - _metadata = self.get_instance_metadata(context, instance) + _metadata = orig.copy() _metadata.update(metadata) self._check_metadata_properties_quota(context, _metadata) self.db.instance_metadata_update(context, instance['uuid'], _metadata, True) + diff = utils.diff_dict(orig, _metadata) + self.compute_rpcapi.change_instance_metadata(context, + instance=instance, + diff=diff) return _metadata def get_instance_faults(self, context, instances): diff --git a/nova/compute/manager.py b/nova/compute/manager.py index ecebf2d9c..e19a4ec90 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -235,7 +235,7 @@ def _get_additional_capabilities(): class ComputeManager(manager.SchedulerDependentManager): """Manages the running instances from creation to destruction.""" - RPC_API_VERSION = '1.2' + RPC_API_VERSION = '1.3' def __init__(self, compute_driver=None, *args, **kwargs): """Load configuration options and connect to the hypervisor.""" @@ -1324,6 +1324,16 @@ class ComputeManager(manager.SchedulerDependentManager): task_state=None, power_state=current_power_state) + @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) + @checks_instance_lock + @wrap_instance_fault + def change_instance_metadata(self, context, instance_uuid, diff): + """Update the metadata published to the instance.""" + instance_ref = self.db.instance_get_by_uuid(context, instance_uuid) + LOG.debug(_("Changing instance metadata according to %(diff)r") % + locals(), instance=instance_ref) + self.driver.change_instance_metadata(context, instance_ref, diff) + @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock @wrap_instance_fault diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py index 332b8153e..e637c9f64 100644 --- a/nova/compute/rpcapi.py +++ b/nova/compute/rpcapi.py @@ -57,6 +57,7 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): 1.0 - Initial version. 1.1 - Adds get_host_uptime() 1.2 - Adds check_can_live_migrate_[destination|source] + 1.3 - Adds change_instance_metadata() ''' BASE_RPC_API_VERSION = '1.0' @@ -375,6 +376,12 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy): instance_uuid=instance['uuid']), topic=_compute_topic(self.topic, ctxt, None, instance)) + def change_instance_metadata(self, ctxt, instance, diff): + self.cast(ctxt, self.make_msg('change_instance_metadata', + instance_uuid=instance['uuid'], diff=diff), + topic=_compute_topic(self.topic, ctxt, None, instance), + version='1.3') + class SecurityGroupAPI(nova.openstack.common.rpc.proxy.RpcProxy): '''Client side of the security group rpc API. -- cgit