libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From quent...@apache.org
Subject [3/3] libcloud git commit: implement ex_create_image_member for OpenStack
Date Fri, 09 Mar 2018 04:47:21 GMT
implement ex_create_image_member for OpenStack

give a project (previously known as tenant) access to an image. after the tenant has been
given access, it still needs to accept the image (using the scoped token for that project).

Signed-off-by: Quentin Pradet <quentinp@apache.org>


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

Branch: refs/heads/trunk
Commit: deb37f36c909d3f2ce9769305bb3b050b40e0f14
Parents: ec53824
Author: Rick van de Loo <rickvandeloo@gmail.com>
Authored: Sun Mar 4 13:00:20 2018 +0100
Committer: Quentin Pradet <quentinp@apache.org>
Committed: Fri Mar 9 08:46:40 2018 +0400

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py           | 32 ++++++++++++++++++++
 ...54e_a1b2_4df8_b747_4bec97abc799_members.json |  2 ++
 libcloud/test/compute/test_openstack.py         | 21 +++++++++++++
 3 files changed, 55 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/deb37f36/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 527dce9..1e52ceb 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -2622,6 +2622,38 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
             image_members.append(self._to_image_member(image_member))
         return image_members
 
+    def ex_create_image_member(self, image_id, member_id):
+        """
+        Give a project access to an image.
+
+        The image should have visibility status 'shared'.
+
+        Note that this is not an idempotent operation. If this action is
+        attempted using a tenant that is already in the image members
+        group the API will throw a Conflict (409).
+        See https://developer.openstack.org/api-ref/image/v2/index.html#create-image-member
+
+        :param str image_id: The ID of the image to share with the specified tenant
+        :param str member_id: The ID of the project / tenant (the image member)
+        Note that this is the Keystone project ID and not the project name,
+        so something like e2151b1fe02d4a8a2d1f5fc331522c0a
+        :return None:
+
+        :param      image_id: ID of the image to share
+        :type       image_id: ``str``
+
+        :param      project: ID of the project to give access to the image
+        :type       image_id: ``str``
+
+        :rtype: ``list`` of :class:`NodeImageMember`
+        """
+        data = {'member': member_id}
+        response = self.image_connection.request(
+            '/v2/images/%s/members' % image_id,
+            method='POST', data=json.dumps(data)
+        )
+        return self._to_image_member(response.object)
+
     def ex_get_image_member(self, image_id, member_id):
         """
         Get a member of an image by id

http://git-wip-us.apache.org/repos/asf/libcloud/blob/deb37f36/libcloud/test/compute/fixtures/openstack_v1.1/_images_9af1a54e_a1b2_4df8_b747_4bec97abc799_members.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_images_9af1a54e_a1b2_4df8_b747_4bec97abc799_members.json
b/libcloud/test/compute/fixtures/openstack_v1.1/_images_9af1a54e_a1b2_4df8_b747_4bec97abc799_members.json
new file mode 100644
index 0000000..3bc4174
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_images_9af1a54e_a1b2_4df8_b747_4bec97abc799_members.json
@@ -0,0 +1,2 @@
+{"status": "pending", "created_at": "2018-03-02T14:19:38Z", "updated_at": "2018-03-02T14:19:38Z",
"image_id": "9af1a54e-a1b2-4df8-b747-4bec97abc799", "member_id": "e2151b1fe02d4a8a2d1f5fc331522c0a",
"schema": "/v2/schemas/member"}
+

http://git-wip-us.apache.org/repos/asf/libcloud/blob/deb37f36/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index 02ed3f3..ab59884 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -1650,6 +1650,20 @@ class OpenStack_2_Tests(OpenStack_1_1_Tests):
         self.assertEqual(image_member.extra['updated'], '2017-01-12T12:31:54Z')
         self.assertEqual(image_member.extra['schema'], '/v2/schemas/member')
 
+    def test_ex_create_image_member(self):
+        image_id = '9af1a54e-a1b2-4df8-b747-4bec97abc799'
+        image_member_id = 'e2151b1fe02d4a8a2d1f5fc331522c0a'
+        image_member = self.driver.ex_create_image_member(
+            image_id, image_member_id
+        )
+
+        self.assertEqual(image_member.id, image_member_id)
+        self.assertEqual(image_member.image_id, image_id)
+        self.assertEqual(image_member.state, NodeImageMemberState.PENDING)
+        self.assertEqual(image_member.created, '2018-03-02T14:19:38Z')
+        self.assertEqual(image_member.extra['updated'], '2018-03-02T14:19:38Z')
+        self.assertEqual(image_member.extra['schema'], '/v2/schemas/member')
+
     def test_ex_get_image_member(self):
         image_id = 'd9a9cd9a-278a-444c-90a6-d24b8c688a63'
         image_member_id = '016926dff12345e8b10329f24c99745b'
@@ -1825,6 +1839,13 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
         else:
             raise NotImplementedError()
 
+    def _v2_1337_v2_images_9af1a54e_a1b2_4df8_b747_4bec97abc799_members(self, method, url,
body, headers):
+        if method == "POST":
+            body = self.fixtures.load('_images_9af1a54e_a1b2_4df8_b747_4bec97abc799_members.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+        else:
+            raise NotImplementedError()
+
     def _v2_1337_v2_images_d9a9cd9a_278a_444c_90a6_d24b8c688a63_members_016926dff12345e8b10329f24c99745b(self,
method, url, body, headers):
         if method == "GET":
             body = self.fixtures.load(


Mime
View raw message