Repository: libcloud Updated Branches: refs/heads/trunk c4cfea6e1 -> 17fe85b04
Add method to modify snapshot attribute for EC2 Signed-off-by: Sayan Chowdhury <[email protected]> Closes #990 Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/ebcfed52 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/ebcfed52 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/ebcfed52 Branch: refs/heads/trunk Commit: ebcfed52becef9bf0f8705b39c6b0959db283f0b Parents: c4cfea6 Author: Sayan Chowdhury <[email protected]> Authored: Wed Feb 22 17:17:45 2017 +0530 Committer: Anthony Shaw <[email protected]> Committed: Sat Apr 1 11:53:28 2017 +1100 ---------------------------------------------------------------------- libcloud/compute/drivers/ec2.py | 24 ++++++++++++++++++++ .../fixtures/ec2/modify_snapshot_attribute.xml | 4 ++++ libcloud/test/compute/test_ec2.py | 12 ++++++++++ 3 files changed, 40 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/ebcfed52/libcloud/compute/drivers/ec2.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/ec2.py b/libcloud/compute/drivers/ec2.py index 61e6344..f376854 100644 --- a/libcloud/compute/drivers/ec2.py +++ b/libcloud/compute/drivers/ec2.py @@ -4794,6 +4794,30 @@ class BaseEC2NodeDriver(NodeDriver): 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. http://git-wip-us.apache.org/repos/asf/libcloud/blob/ebcfed52/libcloud/test/compute/fixtures/ec2/modify_snapshot_attribute.xml ---------------------------------------------------------------------- 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 0000000..e812ea4 --- /dev/null +++ b/libcloud/test/compute/fixtures/ec2/modify_snapshot_attribute.xml @@ -0,0 +1,4 @@ +<ModifySnapshotAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/"> + <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId> + <return>true</return> +</ModifySnapshotAttributeResponse> http://git-wip-us.apache.org/repos/asf/libcloud/blob/ebcfed52/libcloud/test/compute/test_ec2.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_ec2.py b/libcloud/test/compute/test_ec2.py index 191cbf7..659d669 100644 --- a/libcloud/test/compute/test_ec2.py +++ b/libcloud/test/compute/test_ec2.py @@ -934,6 +934,14 @@ class EC2Tests(LibcloudTestCase, TestCaseMixin): 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' @@ -1402,6 +1410,10 @@ class EC2MockHttp(MockHttpTestCase): 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])
