From 147dac80b9b1b5cab69dc4c7d997de6e93fc11f0 Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Wed, 9 May 2018 23:21:08 +0000 Subject: [PATCH] Add snapshots to minimum driver interface Snapshot functionality was excluded from the base volume driver functionality while issues were being worked on with NFS based drivers. Those have since been resolved and we should now include the snapshot calls in the base interface for volume backend drivers. Change-Id: Ic7d6ca1de84d36f54a00e3afe3647865d6edd211 --- cinder/interface/volume_driver.py | 28 +++++++++ cinder/interface/volume_snapshot_driver.py | 70 ---------------------- cinder/interface/volume_snapshot_revert.py | 38 ++++++++++++ doc/source/contributor/drivers.rst | 24 ++++---- 4 files changed, 76 insertions(+), 84 deletions(-) delete mode 100644 cinder/interface/volume_snapshot_driver.py create mode 100644 cinder/interface/volume_snapshot_revert.py diff --git a/cinder/interface/volume_driver.py b/cinder/interface/volume_driver.py index 0ce663c3657..9c40f302538 100644 --- a/cinder/interface/volume_driver.py +++ b/cinder/interface/volume_driver.py @@ -256,3 +256,31 @@ class VolumeDriverCore(base.CinderInterface): :param volume: The volume to extend. :param new_size: The new desired size of the volume. """ + + def create_snapshot(self, snapshot): + """Creates a snapshot. + + :param snapshot: Information for the snapshot to be created. + """ + + def delete_snapshot(self, snapshot): + """Deletes a snapshot. + + :param snapshot: The snapshot to delete. + """ + + def create_volume_from_snapshot(self, volume, snapshot): + """Creates a volume from a snapshot. + + If volume_type extra specs includes 'replication: True' + the driver needs to create a volume replica (secondary), + and setup replication between the newly created volume and + the secondary volume. + + An optional larger size for the new snapshot can be specified. Drivers + should check this value and create or expand the new volume to match. + + :param volume: The volume to be created. + :param snapshot: The snapshot from which to create the volume. + :returns: A dict of database updates for the new volume. + """ diff --git a/cinder/interface/volume_snapshot_driver.py b/cinder/interface/volume_snapshot_driver.py deleted file mode 100644 index 9c500cc115e..00000000000 --- a/cinder/interface/volume_snapshot_driver.py +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright 2016 Dell Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# - -""" -Snapshot capable volume driver interface. -""" - -from cinder.interface import base - - -class VolumeSnapshotDriver(base.CinderInterface): - """Interface for drivers that support snapshots. - - TODO(smcginnis) Merge into VolumeDriverBase once NFS driver supports - snapshots. - """ - - def create_snapshot(self, snapshot): - """Creates a snapshot. - - :param snapshot: Information for the snapshot to be created. - """ - - def delete_snapshot(self, snapshot): - """Deletes a snapshot. - - :param snapshot: The snapshot to delete. - """ - - def create_volume_from_snapshot(self, volume, snapshot): - """Creates a volume from a snapshot. - - If volume_type extra specs includes 'replication: True' - the driver needs to create a volume replica (secondary), - and setup replication between the newly created volume and - the secondary volume. - - An optional larger size for the new snapshot can be specified. Drivers - should check this value and create or expand the new volume to match. - - :param volume: The volume to be created. - :param snapshot: The snapshot from which to create the volume. - :returns: A dict of database updates for the new volume. - """ - - def revert_to_snapshot(self, context, volume, snapshot): - """Revert volume to snapshot. - - Note: the revert process should not change the volume's - current size, that means if the driver shrank - the volume during the process, it should extend the - volume internally. - - :param context: the context of the caller. - :param volume: The volume to be reverted. - :param snapshot: The snapshot used for reverting. - """ diff --git a/cinder/interface/volume_snapshot_revert.py b/cinder/interface/volume_snapshot_revert.py new file mode 100644 index 00000000000..bcca2a88edf --- /dev/null +++ b/cinder/interface/volume_snapshot_revert.py @@ -0,0 +1,38 @@ +# Copyright 2018 Huawei +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +""" +Revert to snapshot capable volume driver interface. +""" + +from cinder.interface import base + + +class VolumeSnapshotRevertDriver(base.CinderInterface): + """Interface for drivers that support revert to snapshot.""" + + def revert_to_snapshot(self, context, volume, snapshot): + """Revert volume to snapshot. + + Note: the revert process should not change the volume's + current size, that means if the driver shrank + the volume during the process, it should extend the + volume internally. + + :param context: the context of the caller. + :param volume: The volume to be reverted. + :param snapshot: The snapshot used for reverting. + """ diff --git a/doc/source/contributor/drivers.rst b/doc/source/contributor/drivers.rst index df280f38d7d..dbb1ec12e40 100644 --- a/doc/source/contributor/drivers.rst +++ b/doc/source/contributor/drivers.rst @@ -125,20 +125,6 @@ in order to be an official Cinder volume driver. :members: :noindex: -Snapshot Interface -`````````````````` -Another required interface for a volume driver to be fully compatible is the -ability to create and manage snapshots. Due to legacy constraints, this -interface is not included in the base driver interface above. - -Work is being done to address those legacy issues. Once that is complete, this -interface will be merged with the base driver interface. - -.. automodule:: cinder.interface.volume_snapshot_driver - :members: - :noindex: - - Manage/Unmanage Support ``````````````````````` An optional feature a volume backend can support is the ability to manage @@ -186,3 +172,13 @@ need the volume consistency groups interface listed above. :members: :noindex: +Revert To Snapshot +`````````````````` +Some storage backends support the ability to revert a volume to the last +snapshot. To support snapshot revert, the following interface must be +implemented by the driver. + +.. automodule:: cinder.interface.volume_snapshot_revert + :members: + :noindex: +