You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by qu...@apache.org on 2018/03/02 05:42:29 UTC
[02/13] libcloud git commit: implement openstack ex_update_image
implement openstack ex_update_image
so visibility can be set on images
Signed-off-by: Quentin Pradet <qu...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/9a3f98e4
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/9a3f98e4
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/9a3f98e4
Branch: refs/heads/trunk
Commit: 9a3f98e42e232e692c0774422ca54f280a242333
Parents: b6572d7
Author: Rick van de Loo <ri...@gmail.com>
Authored: Wed Dec 6 17:54:04 2017 +0100
Committer: Quentin Pradet <qu...@apache.org>
Committed: Fri Mar 2 09:34:25 2018 +0400
----------------------------------------------------------------------
libcloud/compute/drivers/openstack.py | 18 ++++++++++++++++++
...ages_f24a3c1b-d52a-4116-91da-25b3eee8f55e.json | 2 +-
libcloud/test/compute/test_openstack.py | 18 ++++++++++++++++--
3 files changed, 35 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/9a3f98e4/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index fe06975..d528758 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -2551,6 +2551,24 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
images.append(self._to_image(image))
return images
+ def ex_update_image(self, image_id, data):
+ """
+ Patch a NodeImage. Can be used to set visibility
+ :param image_id: ID of the image which should be used
+ :type image_id: ``str``
+ :param data: The data to PATCH, either a dict or a list
+ :type data: ``dict|list``
+ :rtype: :class:`NodeImage`
+ """
+ response = self.connection.request(
+ '/v2/images/%s' % (image_id,),
+ headers={'Content-type': 'application/'
+ 'openstack-images-'
+ 'v2.1-json-patch'},
+ method='PATCH', data=json.dumps(data)
+ )
+ return self._to_image(response.object)
+
class OpenStack_1_1_FloatingIpPool(object):
"""
http://git-wip-us.apache.org/repos/asf/libcloud/blob/9a3f98e4/libcloud/test/compute/fixtures/openstack_v1.1/_images_f24a3c1b-d52a-4116-91da-25b3eee8f55e.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_images_f24a3c1b-d52a-4116-91da-25b3eee8f55e.json b/libcloud/test/compute/fixtures/openstack_v1.1/_images_f24a3c1b-d52a-4116-91da-25b3eee8f55e.json
index 82f4a92..4d014cf 100644
--- a/libcloud/test/compute/fixtures/openstack_v1.1/_images_f24a3c1b-d52a-4116-91da-25b3eee8f55e.json
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_images_f24a3c1b-d52a-4116-91da-25b3eee8f55e.json
@@ -1 +1 @@
-{"status": "active", "image_location": "snapshot", "image_state": "available", "tags": [], "kernel_id": null, "container_format": "bare", "min_ram": 0, "ramdisk_id": null, "locations": [{"url": "file:///var/lib/glance/images/f24a3c1b-d52a-4116-91da-25b3eee8f55e", "metadata": {"mountpoint": "/var/lib/glance/images", "type": "nfs", "id": "NetApp1", "share_location": "nfs://some.ip.somewhere/blabla_data001"}}], "visibility": "private", "updated_at": "2017-11-28T10:19:49Z", "owner": "d85e344900774f5aad27e4e8e91205d6", "schema": "/v2/schemas/image", "file": "/v2/images/f24a3c1b-d52a-4116-91da-25b3eee8f55e/file", "min_disk": 40, "virtual_size": null, "base_image_ref": "5be2b652-a965-4ecb-a2b4-b9f83d7779e6", "size": 1256259584, "instance_uuid": "24f0a531-e45f-491b-86f2-3708dd45a478", "os_distro": "ubuntu", "user_id": "b0d846d9ac93452bb93857e0305584bd", "name": "hypernode", "image_type": "snapshot", "checksum": "3530464d095c9d62771b99ebecd2d70b", "created_at": "2017-09-11T13:00:05Z", "disk_
format": "qcow2", "id": "f24a3c1b-d52a-4116-91da-25b3eee8f55e", "protected": false, "os_type": "linux", "direct_url": "file:///var/lib/glance/images/f24a3c1b-d52a-4116-91da-25b3eee8f55e", "self": "/v2/images/f24a3c1b-d52a-4116-91da-25b3eee8f55e", "owner_id": "d85e344900774f5aad27e4e8e91205d6"}
+{"status": "active", "image_location": "snapshot", "image_state": "available", "tags": [], "kernel_id": null, "container_format": "bare", "min_ram": 0, "ramdisk_id": null, "locations": [{"url": "file:///var/lib/glance/images/f24a3c1b-d52a-4116-91da-25b3eee8f55e", "metadata": {"mountpoint": "/var/lib/glance/images", "type": "nfs", "id": "NetApp1", "share_location": "nfs://some.ip.somewhere/blabla_data001"}}], "visibility": "shared", "updated_at": "2017-11-28T10:19:49Z", "owner": "d85e344900774f5aad27e4e8e91205d6", "schema": "/v2/schemas/image", "file": "/v2/images/f24a3c1b-d52a-4116-91da-25b3eee8f55e/file", "min_disk": 40, "virtual_size": null, "base_image_ref": "5be2b652-a965-4ecb-a2b4-b9f83d7779e6", "size": 1256259584, "instance_uuid": "24f0a531-e45f-491b-86f2-3708dd45a478", "os_distro": "ubuntu", "user_id": "b0d846d9ac93452bb93857e0305584bd", "name": "hypernode", "image_type": "snapshot", "checksum": "3530464d095c9d62771b99ebecd2d70b", "created_at": "2017-09-11T13:00:05Z", "disk_f
ormat": "qcow2", "id": "f24a3c1b-d52a-4116-91da-25b3eee8f55e", "protected": false, "os_type": "linux", "direct_url": "file:///var/lib/glance/images/f24a3c1b-d52a-4116-91da-25b3eee8f55e", "self": "/v2/images/f24a3c1b-d52a-4116-91da-25b3eee8f55e", "owner_id": "d85e344900774f5aad27e4e8e91205d6"}
http://git-wip-us.apache.org/repos/asf/libcloud/blob/9a3f98e4/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index a10b724..de04c42 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -1605,7 +1605,7 @@ class OpenStack_2_Tests(OpenStack_1_1_Tests):
self.assertEqual(image.extra['serverId'], None)
self.assertEqual(image.extra['minDisk'], 40)
self.assertEqual(image.extra['minRam'], 0)
- self.assertEqual(image.extra['visibility'], "private")
+ self.assertEqual(image.extra['visibility'], "shared")
def test_list_images(self):
images = self.driver.list_images()
@@ -1622,6 +1622,20 @@ class OpenStack_2_Tests(OpenStack_1_1_Tests):
self.assertEqual(image.extra['minDisk'], 40)
self.assertEqual(image.extra['minRam'], 0)
+ def test_ex_update_image(self):
+ image_id = 'f24a3c1b-d52a-4116-91da-25b3eee8f55e'
+ data = {
+ 'op': 'replace',
+ 'path': '/visibility',
+ 'value': 'shared'
+ }
+ image = self.driver.ex_update_image(image_id, data)
+ self.assertEqual(image.name, 'hypernode')
+ self.assertEqual(image.extra['serverId'], None)
+ self.assertEqual(image.extra['minDisk'], 40)
+ self.assertEqual(image.extra['minRam'], 0)
+ self.assertEqual(image.extra['visibility'], "shared")
+
class OpenStack_1_1_FactoryMethodTests(OpenStack_1_1_Tests):
should_list_locations = False
@@ -1770,7 +1784,7 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
raise NotImplementedError()
def _v2_1337_v2_images_f24a3c1b_d52a_4116_91da_25b3eee8f55e(self, method, url, body, headers):
- if method == "GET":
+ if method == "GET" or method == "PATCH":
body = self.fixtures.load('_images_f24a3c1b-d52a-4116-91da-25b3eee8f55e.json')
return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
else: