Repository: libcloud
Updated Branches:
  refs/heads/trunk 37c147b7f -> b81ede37f


Document functions and update signature

- Document create_volume_snapshot arguments properly
- Document destroy_volume_snapshot arguments properly
- Update signature to match all existing implementations
  - name should be optional

closes #478


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/b81ede37
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/b81ede37
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/b81ede37

Branch: refs/heads/trunk
Commit: b81ede37f3c05cdbd97d66b007ba6ec06cd2ee05
Parents: 37c147b
Author: Allard Hoeve <[email protected]>
Authored: Fri Mar 6 15:38:28 2015 +0100
Committer: Allard Hoeve <[email protected]>
Committed: Fri Mar 27 11:59:18 2015 +0100

----------------------------------------------------------------------
 CHANGES.rst                             |  7 ++++
 docs/upgrade_notes.rst                  | 10 ++++++
 libcloud/compute/base.py                | 11 +++++-
 libcloud/compute/drivers/cloudstack.py  | 14 +++-----
 libcloud/compute/drivers/ec2.py         |  5 +--
 libcloud/compute/drivers/openstack.py   | 54 ++++++++++++++++++++++------
 libcloud/test/compute/test_openstack.py | 24 ++++++++++++-
 7 files changed, 101 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/b81ede37/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index 0282bc7..bd839d5 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -25,10 +25,17 @@ Compute
   (GITHUB-479)
   [Allard Hoeve]
 
+- OpenStack driver: deprecated ex_create_snapshot and ex_delete_snapshot in 
+  favor of create_volume_snapshot and destroy_volume_snapshot. Updated base 
+  driver method create_storage_volume argument name to be optional.
+  (GITHUB-478)
+  [Allard Hoeve]
+
 - Add support for creating volumes based on snapshots to EC2 and OS drivers.
   Also modify signature of base NodeDriver.create_volume to reflect the fact
   that all drivers expect a StorageSnapshot object as the snapshot argument.
   (GITHUB-467, LIBCLOUD-672)
+  [Allard Hoeve]
 
 - VolumeSnapshots now have a `created` attribute that is a `datetime`
   field showing the creation datetime of the snapshot. The field in

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b81ede37/docs/upgrade_notes.rst
----------------------------------------------------------------------
diff --git a/docs/upgrade_notes.rst b/docs/upgrade_notes.rst
index 1a29bc4..6b8bce2 100644
--- a/docs/upgrade_notes.rst
+++ b/docs/upgrade_notes.rst
@@ -20,6 +20,16 @@ Development
   VolumeSnapshot.extra containing the original string is maintained, so
   this is a backwards-compatible change.
 
+* The OpenStack compute driver methods ex_create_snapshot and
+  ex_delete_snapshot are now deprecated by the standard methods
+  create_volume_snapshot and destroy_volume_snapshot. You should update your
+  code.
+
+* The compute base driver now considers the name argument to
+  create_volume_snapshot to be optional. All official implementations of this
+  methods already considered it optional. You should update any custom
+  drivers if they rely on the name being mandatory.
+
 Libcloud 0.16.0
 ---------------
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b81ede37/libcloud/compute/base.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/base.py b/libcloud/compute/base.py
index f15f477..d0c8399 100644
--- a/libcloud/compute/base.py
+++ b/libcloud/compute/base.py
@@ -1016,10 +1016,16 @@ class NodeDriver(BaseDriver):
         raise NotImplementedError(
             'create_volume not implemented for this driver')
 
-    def create_volume_snapshot(self, volume, name):
+    def create_volume_snapshot(self, volume, name=None):
         """
         Creates a snapshot of the storage volume.
 
+        :param volume: The StorageVolume to create a VolumeSnapshot from
+        :type volume: :class:`.VolumeSnapshot`
+
+        :param name: Name of created snapshot (optional)
+        :type name: `str`
+
         :rtype: :class:`VolumeSnapshot`
         """
         raise NotImplementedError(
@@ -1071,6 +1077,9 @@ class NodeDriver(BaseDriver):
         """
         Destroys a snapshot.
 
+        :param snapshot: The snapshot to delete
+        :type snapshot: :class:`VolumeSnapshot`
+
         :rtype: :class:`bool`
         """
         raise NotImplementedError(

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b81ede37/libcloud/compute/drivers/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/cloudstack.py 
b/libcloud/compute/drivers/cloudstack.py
index 7028477..22762b3 100644
--- a/libcloud/compute/drivers/cloudstack.py
+++ b/libcloud/compute/drivers/cloudstack.py
@@ -3577,13 +3577,17 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, 
NodeDriver):
             list_snapshots.append(self._to_snapshot(snap))
         return list_snapshots
 
-    def create_volume_snapshot(self, volume):
+    def create_volume_snapshot(self, volume, name=None):
         """
         Create snapshot from volume
 
         :param      volume: Instance of ``StorageVolume``
         :type       volume: ``StorageVolume``
 
+        :param      name: The name of the snapshot is disregarded
+                          by CloudStack drivers
+        :type       name: `str`
+
         :rtype: :class:`VolumeSnapshot`
         """
         snapshot = self._async_request(command='createSnapshot',
@@ -3592,14 +3596,6 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, 
NodeDriver):
         return self._to_snapshot(snapshot['snapshot'])
 
     def destroy_volume_snapshot(self, snapshot):
-        """
-        Destroy snapshot
-
-        :param      snapshot: Instance of ``VolumeSnapshot``
-        :type       volume: ``VolumeSnapshot``
-
-        :rtype: ``bool``
-        """
         self._async_request(command='deleteSnapshot',
                             params={'id': snapshot.id},
                             method='GET')

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b81ede37/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index b127890..b43aa88 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -2422,7 +2422,7 @@ class BaseEC2NodeDriver(NodeDriver):
         :param      volume: Instance of ``StorageVolume``
         :type       volume: ``StorageVolume``
 
-        :param      name: Name of snapshot
+        :param      name: Name of snapshot (optional)
         :type       name: ``str``
 
         :rtype: :class:`VolumeSnapshot`
@@ -3445,7 +3445,8 @@ class BaseEC2NodeDriver(NodeDriver):
         Create tags for a resource (Node or StorageVolume).
 
         :param resource: Resource to be tagged
-        :type resource: :class:`Node` or :class:`StorageVolume`
+        :type resource: :class:`Node` or :class:`StorageVolume` or
+                        :class:`VolumeSnapshot`
 
         :param tags: A dictionary or other mapping of strings to strings,
                      associating tag names with tag values.

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b81ede37/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py 
b/libcloud/compute/drivers/openstack.py
index 9377656..df32d2b 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -1615,6 +1615,41 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
         return [snapshot for snapshot in self.ex_list_snapshots()
                 if snapshot.extra['volume_id'] == volume.id]
 
+    def create_volume_snapshot(self, volume, name=None, ex_description=None,
+                               ex_force=True):
+        """
+        Create snapshot from volume
+
+        :param volume: Instance of `StorageVolume`
+        :type  volume: `StorageVolume`
+
+        :param name: Name of snapshot (optional)
+        :type  name: `str`
+
+        :param ex_description: Description of the snapshot (optional)
+        :type  ex_description: `str`
+
+        :param ex_force: Specifies if we create a snapshot that is not in
+                         state `available`. For example `in-use`. Defaults
+                         to True. (optional)
+        :type  ex_force: `bool`
+
+        :rtype: :class:`VolumeSnapshot`
+        """
+        data = {'snapshot': {'display_name': name,
+                             'display_description': ex_description,
+                             'volume_id': volume.id,
+                             'force': ex_force}}
+
+        return self._to_snapshot(self.connection.request('/os-snapshots',
+                                                         method='POST',
+                                                         data=data).object)
+
+    def destroy_volume_snapshot(self, snapshot):
+        resp = self.connection.request('/os-snapshots/%s' % snapshot.id,
+                                       method='DELETE')
+        return resp.status == httplib.NO_CONTENT
+
     def ex_create_snapshot(self, volume, name, description=None, force=False):
         """
         Create a snapshot based off of a volume.
@@ -1633,14 +1668,11 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
 
         :rtype:     :class:`VolumeSnapshot`
         """
-        data = {'snapshot': {'display_name': name,
-                             'display_description': description,
-                             'volume_id': volume.id,
-                             'force': force}}
-
-        return self._to_snapshot(self.connection.request('/os-snapshots',
-                                                         method='POST',
-                                                         data=data).object)
+        warnings.warn('This method has been deprecated in favor of the '
+                      'create_volume_snapshot method')
+        return self.create_volume_snapshot(volume, name,
+                                           ex_description=description,
+                                           ex_force=force)
 
     def ex_delete_snapshot(self, snapshot):
         """
@@ -1651,9 +1683,9 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
 
         :rtype:     ``bool``
         """
-        resp = self.connection.request('/os-snapshots/%s' % snapshot.id,
-                                       method='DELETE')
-        return resp.status == httplib.NO_CONTENT
+        warnings.warn('This method has been deprecated in favor of the '
+                      'destroy_volume_snapshot method')
+        return self.destroy_volume_snapshot(snapshot)
 
     def _to_security_group_rules(self, obj):
         return [self._to_security_group_rule(security_group_rule) for

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b81ede37/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py 
b/libcloud/test/compute/test_openstack.py
index 3017e82..f3524ec 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -1433,6 +1433,18 @@ class OpenStack_1_1_Tests(unittest.TestCase, 
TestCaseMixin):
         self.assertEqual(len(snapshots), 1)
         self.assertEqual(snapshots[0].id, 
'4fbbdccf-e058-6502-8844-6feeffdf4cb5')
 
+    def test_create_volume_snapshot(self):
+        volume = self.driver.list_volumes()[0]
+        if self.driver_type.type == 'rackspace':
+            self.conn_classes[0].type = 'RACKSPACE'
+            self.conn_classes[1].type = 'RACKSPACE'
+
+        ret = self.driver.create_volume_snapshot(volume,
+                                                 'Test Volume',
+                                                 ex_description='This is a 
test',
+                                                 ex_force=True)
+        self.assertEqual(ret.id, '3fbbcccf-d058-4502-8844-6feeffdf4cb5')
+
     def test_ex_create_snapshot(self):
         volume = self.driver.list_volumes()[0]
         if self.driver_type.type == 'rackspace':
@@ -1441,9 +1453,19 @@ class OpenStack_1_1_Tests(unittest.TestCase, 
TestCaseMixin):
 
         ret = self.driver.ex_create_snapshot(volume,
                                              'Test Volume',
-                                             'This is a test')
+                                             description='This is a test',
+                                             force=True)
         self.assertEqual(ret.id, '3fbbcccf-d058-4502-8844-6feeffdf4cb5')
 
+    def test_destroy_volume_snapshot(self):
+        if self.driver_type.type == 'rackspace':
+            self.conn_classes[0].type = 'RACKSPACE'
+            self.conn_classes[1].type = 'RACKSPACE'
+
+        snapshot = self.driver.ex_list_snapshots()[0]
+        ret = self.driver.destroy_volume_snapshot(snapshot)
+        self.assertTrue(ret)
+
     def test_ex_delete_snapshot(self):
         if self.driver_type.type == 'rackspace':
             self.conn_classes[0].type = 'RACKSPACE'

Reply via email to