libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vd...@apache.org
Subject [2/4] libcloud git commit: [LIBCLOUD-1014] Accept metadata when create a snapshot
Date Fri, 26 Oct 2018 16:46:47 GMT
[LIBCLOUD-1014] Accept metadata when create a snapshot


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

Branch: refs/heads/trunk
Commit: 51b6609f8d34d9fe73134fdc76aa968cd1210425
Parents: 2dcf434
Author: elesbom <rafael.goncalves@corp.globo.com>
Authored: Mon Sep 24 13:18:42 2018 -0300
Committer: Rick van de Loo <rickvandeloo@gmail.com>
Committed: Fri Oct 26 18:43:27 2018 +0200

----------------------------------------------------------------------
 libcloud/compute/drivers/ec2.py   | 14 +++++++++++---
 libcloud/test/compute/test_ec2.py |  8 ++++++++
 2 files changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/51b6609f/libcloud/compute/drivers/ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py
index 00e3829..badb97c 100644
--- a/libcloud/compute/drivers/ec2.py
+++ b/libcloud/compute/drivers/ec2.py
@@ -2132,7 +2132,7 @@ class BaseEC2NodeDriver(NodeDriver):
         response = self.connection.request(self.path, params=params).object
         return self._get_boolean(response)
 
-    def create_volume_snapshot(self, volume, name=None):
+    def create_volume_snapshot(self, volume, name=None, ex_metadata=None):
         """
         Create snapshot from volume
 
@@ -2142,6 +2142,10 @@ class BaseEC2NodeDriver(NodeDriver):
         :param      name: Name of snapshot (optional)
         :type       name: ``str``
 
+        :keyword    ex_metadata: The Key/Value metadata to associate
+                                 with a snapshot (optional)
+        :type       ex_metadata: ``dict``
+
         :rtype: :class:`VolumeSnapshot`
         """
         params = {
@@ -2153,11 +2157,15 @@ class BaseEC2NodeDriver(NodeDriver):
             params.update({
                 'Description': name,
             })
+        if ex_metadata is None:
+            ex_metadata = {}
+
         response = self.connection.request(self.path, params=params).object
         snapshot = self._to_snapshot(response, name)
 
-        if name and self.ex_create_tags(snapshot, {'Name': name}):
-            snapshot.extra['tags']['Name'] = name
+        ex_metadata.update(**{'Name': name} if name else {})
+        if self.ex_create_tags(snapshot, ex_metadata):
+            snapshot.extra['tags'] = ex_metadata
 
         return snapshot
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/51b6609f/libcloud/test/compute/test_ec2.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py
index 2fb93cd..430718a 100644
--- a/libcloud/test/compute/test_ec2.py
+++ b/libcloud/test/compute/test_ec2.py
@@ -933,6 +933,14 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin):
         # 2013-08-15T16:22:30.000Z
         self.assertEqual(datetime(2013, 8, 15, 16, 22, 30, tzinfo=UTC), snap.created)
 
+    def test_create_volume_snapshot_with_tags(self):
+        vol = StorageVolume(id='vol-4282672b', name='test',
+                            state=StorageVolumeState.AVAILABLE,
+                            size=10, driver=self.driver)
+        snap = self.driver.create_volume_snapshot(
+            vol, 'Test snapshot', ex_metadata={'my_tag': 'test'})
+        self.assertEqual('test', snap.extra['tags']['my_tag'])
+
     def test_list_snapshots(self):
         snaps = self.driver.list_snapshots()
 


Mime
View raw message