From: Mathieu Gagné Date: Mon, 7 Oct 2013 20:16:13 +0000 (-0400) Subject: Add attach/detach notifications X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=598bc3a9909537a61641ad8bb5023e06353469a7;p=openstack-build%2Fcinder-build.git Add attach/detach notifications Add the following notifications: - attach.start - attach.end - detach.start - detach.end Blueprint: attachment-notifications Change-Id: I4a4b123468c139bc2bcd948a1e7438c3830b5e42 --- diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 866bca042..5371f858c 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -988,6 +988,7 @@ def volume_attached(context, volume_id, instance_uuid, host_name, mountpoint): volume_ref['instance_uuid'] = instance_uuid volume_ref['attached_host'] = host_name volume_ref.save(session=session) + return volume_ref @require_context diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index fcfd80dc8..e881170fc 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -483,6 +483,8 @@ class VolumeManager(manager.SchedulerDependentManager): # TODO(jdg): attach_time column is currently varchar # we should update this to a date-time object # also consider adding detach_time? + self._notify_about_volume_usage(context, volume, + "attach.start") self.db.volume_update(context, volume_id, {"instance_uuid": instance_uuid, "attached_host": host_name, @@ -519,11 +521,12 @@ class VolumeManager(manager.SchedulerDependentManager): self.db.volume_update(context, volume_id, {'status': 'error_attaching'}) - self.db.volume_attached(context.elevated(), - volume_id, - instance_uuid, - host_name_sanitized, - mountpoint) + volume = self.db.volume_attached(context.elevated(), + volume_id, + instance_uuid, + host_name_sanitized, + mountpoint) + self._notify_about_volume_usage(context, volume, "attach.end") return do_attach() @utils.require_driver_initialized @@ -533,6 +536,7 @@ class VolumeManager(manager.SchedulerDependentManager): # TODO(sleepsonthefloor): Is this 'elevated' appropriate? volume = self.db.volume_get(context, volume_id) + self._notify_about_volume_usage(context, volume, "detach.start") try: self.driver.detach_volume(context, volume) except Exception: @@ -550,6 +554,7 @@ class VolumeManager(manager.SchedulerDependentManager): if (volume['provider_location'] and volume['name'] not in volume['provider_location']): self.driver.ensure_export(context, volume) + self._notify_about_volume_usage(context, volume, "detach.end") @utils.require_driver_initialized def copy_volume_to_image(self, context, volume_id, image_meta):