def _clean_volume_attachment(context, id): attachments = ( db.volume_attachment_get_all_by_volume_id(context, id)) for attachment in attachments: db.volume_detached(context.elevated(), id, attachment.id) db.volume_admin_metadata_delete(context.elevated(), id, 'attached_mode')
def _clean_volume_attachment(context, id): attachments = ( db.volume_attachment_get_all_by_volume_id(context, id)) for attachment in attachments: db.volume_detached(context, id, attachment.id) db.volume_admin_metadata_delete(context, id, 'attached_mode')
def delete_all(self, vol_id): """ Delete the admin_metadata created for given volume. :param vol_id: OpenStack Volume ID. """ admin_context = context.get_admin_context() admin_meta = self.get_all(vol_id) for key in admin_meta.keys(): db.volume_admin_metadata_delete(admin_context, vol_id, key)
def finish_detach(self, attachment_id): with self.obj_as_admin(): volume_updates, attachment_updates = ( db.volume_detached(self._context, self.id, attachment_id)) db.volume_admin_metadata_delete(self._context, self.id, 'attached_mode') self.admin_metadata.pop('attached_mode', None) # Remove attachment in volume only when this field is loaded. if attachment_updates and self.obj_attr_is_set('volume_attachment'): for i, attachment in enumerate(self.volume_attachment): if attachment.id == attachment_id: del self.volume_attachment.objects[i] break self.update(volume_updates) self.obj_reset_changes( list(volume_updates.keys()) + ['volume_attachment', 'admin_metadata'])