From fdc92f66934e799138db35352c660dfc1133ad78 Mon Sep 17 00:00:00 2001 From: Sayan Chowdhury Date: Wed, 22 Feb 2017 17:17:45 +0530 Subject: [PATCH] Add method to modify snapshot attribute for EC2 Signed-off-by: Sayan Chowdhury --- libcloud/compute/drivers/ec2.py | 24 +++++++++++++++++++ .../ec2/modify_snapshot_attribute.xml | 4 ++++ libcloud/test/compute/test_ec2.py | 12 ++++++++++ 3 files changed, 40 insertions(+) create mode 100644 libcloud/test/compute/fixtures/ec2/modify_snapshot_attribute.xml diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py index 12e1e1ca98..26c28b2f62 100644 --- a/libcloud/compute/drivers/ec2.py +++ b/libcloud/compute/drivers/ec2.py @@ -4782,6 +4782,30 @@ def ex_modify_instance_attribute(self, node, attributes): return self._get_boolean(res) + def ex_modify_snapshot_attribute(self, snapshot, attributes): + """ + Modify Snapshot attributes. + + :param snapshot: VolumeSnapshot instance + :type snanpshot: :class:`VolumeSnapshot` + + :param attributes: Dictionary with snapshot attributes + :type attributes: ``dict`` + + :return: True on success, False otherwise. + :rtype: ``bool`` + """ + attributes = attributes or {} + attributes.update({'SnapshotId': snapshot.id}) + + params = {'Action': 'ModifySnapshotAttribute'} + params.update(attributes) + + res = self.connection.request(self.path, + params=params.copy()).object + + return self._get_boolean(res) + def ex_modify_image_attribute(self, image, attributes): """ Modify image attributes. diff --git a/libcloud/test/compute/fixtures/ec2/modify_snapshot_attribute.xml b/libcloud/test/compute/fixtures/ec2/modify_snapshot_attribute.xml new file mode 100644 index 0000000000..e812ea473f --- /dev/null +++ b/libcloud/test/compute/fixtures/ec2/modify_snapshot_attribute.xml @@ -0,0 +1,4 @@ + + 59dbff89-35bd-4eac-99ed-be587EXAMPLE + true + diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py index 0e8727e10b..d645310a09 100644 --- a/libcloud/test/compute/test_ec2.py +++ b/libcloud/test/compute/test_ec2.py @@ -933,6 +933,14 @@ def test_ex_modify_image_attribute(self): resp = self.driver.ex_modify_image_attribute(image, data) self.assertTrue(resp) + def test_ex_modify_snapshot_attribute(self): + snap = VolumeSnapshot(id='snap-1234567890abcdef0', + size=10, driver=self.driver) + + data = {'CreateVolumePermission.Add.1.Group': 'all'} + resp = self.driver.ex_modify_snapshot_attribute(snap, data) + self.assertTrue(resp) + def test_create_node_ex_security_groups(self): EC2MockHttp.type = 'ex_security_groups' @@ -1401,6 +1409,10 @@ def _ModifyInstanceAttribute(self, method, url, body, headers): body = self.fixtures.load('modify_instance_attribute.xml') return (httplib.OK, body, {}, httplib.responses[httplib.OK]) + def _ModifySnapshotAttribute(self, method, url, body, headers): + body = self.fixtures.load('modify_snapshot_attribute.xml') + return (httplib.OK, body, {}, httplib.responses[httplib.OK]) + def _idempotent_CreateTags(self, method, url, body, headers): body = self.fixtures.load('create_tags.xml') return (httplib.OK, body, {}, httplib.responses[httplib.OK])