~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/volume/manager.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
from nova import log as logging
45
45
from nova import manager
46
46
from nova.openstack.common import cfg
 
47
from nova.openstack.common import excutils
 
48
from nova.openstack.common import importutils
47
49
from nova import rpc
48
50
from nova import utils
 
51
from nova.volume import utils as volume_utils
49
52
from nova.volume import volume_types
50
53
 
51
54
 
76
79
        """Load the driver from the one specified in args, or from flags."""
77
80
        if not volume_driver:
78
81
            volume_driver = FLAGS.volume_driver
79
 
        self.driver = utils.import_object(volume_driver)
 
82
        self.driver = importutils.import_object(volume_driver)
80
83
        super(VolumeManager, self).__init__(service_name='volume',
81
84
                                                    *args, **kwargs)
82
85
        # NOTE(vish): Implementation specific db handling is done
104
107
        """Creates and exports the volume."""
105
108
        context = context.elevated()
106
109
        volume_ref = self.db.volume_get(context, volume_id)
 
110
        self._notify_about_volume_usage(context, volume_ref, "create.start")
107
111
        LOG.info(_("volume %s: creating"), volume_ref['name'])
108
112
 
109
113
        self.db.volume_update(context,
133
137
            if model_update:
134
138
                self.db.volume_update(context, volume_ref['id'], model_update)
135
139
        except Exception:
136
 
            with utils.save_and_reraise_exception():
 
140
            with excutils.save_and_reraise_exception():
137
141
                self.db.volume_update(context,
138
142
                                      volume_ref['id'], {'status': 'error'})
139
143
 
143
147
                                                 'launched_at': now})
144
148
        LOG.debug(_("volume %s: created successfully"), volume_ref['name'])
145
149
        self._reset_stats()
 
150
        self._notify_about_volume_usage(context, volume_ref, "create.end")
146
151
        return volume_id
147
152
 
148
153
    def delete_volume(self, context, volume_id):
150
155
        context = context.elevated()
151
156
        volume_ref = self.db.volume_get(context, volume_id)
152
157
        if volume_ref['attach_status'] == "attached":
153
 
            raise exception.Error(_("Volume is still attached"))
 
158
            raise exception.NovaException(_("Volume is still attached"))
154
159
        if volume_ref['host'] != self.host:
155
 
            raise exception.Error(_("Volume is not local to this node"))
 
160
            msg = _("Volume is not local to this node")
 
161
            raise exception.NovaException(msg)
156
162
 
 
163
        self._notify_about_volume_usage(context, volume_ref, "delete.start")
157
164
        self._reset_stats()
158
165
        try:
159
166
            LOG.debug(_("volume %s: removing export"), volume_ref['name'])
167
174
                                  {'status': 'available'})
168
175
            return True
169
176
        except Exception:
170
 
            with utils.save_and_reraise_exception():
 
177
            with excutils.save_and_reraise_exception():
171
178
                self.db.volume_update(context,
172
179
                                      volume_ref['id'],
173
180
                                      {'status': 'error_deleting'})
174
181
 
175
182
        self.db.volume_destroy(context, volume_id)
176
183
        LOG.debug(_("volume %s: deleted successfully"), volume_ref['name'])
 
184
        self._notify_about_volume_usage(context, volume_ref, "delete.end")
177
185
        return True
178
186
 
179
187
    def create_snapshot(self, context, volume_id, snapshot_id):
191
199
                                        model_update)
192
200
 
193
201
        except Exception:
194
 
            with utils.save_and_reraise_exception():
 
202
            with excutils.save_and_reraise_exception():
195
203
                self.db.snapshot_update(context,
196
204
                                        snapshot_ref['id'],
197
205
                                        {'status': 'error'})
217
225
                                    {'status': 'available'})
218
226
            return True
219
227
        except Exception:
220
 
            with utils.save_and_reraise_exception():
 
228
            with excutils.save_and_reraise_exception():
221
229
                self.db.snapshot_update(context,
222
230
                                        snapshot_ref['id'],
223
231
                                        {'status': 'error_deleting'})
226
234
        LOG.debug(_("snapshot %s: deleted successfully"), snapshot_ref['name'])
227
235
        return True
228
236
 
229
 
    def attach_volume(self, context, volume_id, instance_id, mountpoint):
 
237
    def attach_volume(self, context, volume_id, instance_uuid, mountpoint):
230
238
        """Updates db to show volume is attached"""
231
239
        # TODO(vish): refactor this into a more general "reserve"
 
240
        if not utils.is_uuid_like(instance_uuid):
 
241
            raise exception.InvalidUUID(instance_uuid)
 
242
 
232
243
        self.db.volume_attached(context,
233
244
                                volume_id,
234
 
                                instance_id,
 
245
                                instance_uuid,
235
246
                                mountpoint)
236
247
 
237
248
    def detach_volume(self, context, volume_id):
290
301
    def check_for_export(self, context, instance_id):
291
302
        """Make sure whether volume is exported."""
292
303
        instance_ref = self.db.instance_get(context, instance_id)
293
 
        for volume in instance_ref['volumes']:
 
304
        volumes = self.db.volume_get_all_by_instance_uuid(context,
 
305
                                                          instance_ref['uuid'])
 
306
 
 
307
        for volume in volumes:
294
308
            self.driver.check_for_export(context, volume['id'])
295
309
 
296
310
    def _volume_stats_changed(self, stat1, stat2):
328
342
    def notification(self, context, event):
329
343
        LOG.info(_("Notification {%s} received"), event)
330
344
        self._reset_stats()
 
345
 
 
346
    def _notify_about_volume_usage(self, context, volume, event_suffix,
 
347
                                     extra_usage_info=None):
 
348
        volume_utils.notify_about_volume_usage(
 
349
                context, volume, event_suffix,
 
350
                extra_usage_info=extra_usage_info, host=self.host)