libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From quent...@apache.org
Subject [03/13] libcloud git commit: use glance api for openstack v2 list_images
Date Fri, 02 Mar 2018 05:42:30 GMT
use glance api for openstack v2 list_images

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/8e5dd528
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/8e5dd528
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/8e5dd528

Branch: refs/heads/trunk
Commit: 8e5dd528eeda977e2362603c051a4d0e96a33c33
Parents: 1cb91d7
Author: Rick van de Loo <rickvandeloo@gmail.com>
Authored: Wed Dec 6 17:23:47 2017 +0100
Committer: Quentin Pradet <quentinp@apache.org>
Committed: Fri Mar 2 09:34:25 2018 +0400

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py           | 24 ++++++++++++++++++--
 .../fixtures/openstack_v1.1/_images_v2.json     |  1 +
 libcloud/test/compute/test_openstack.py         | 22 ++++++++++++++++++
 3 files changed, 45 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/8e5dd528/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index d56a8e2..7917327 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -1292,7 +1292,6 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
         server = api_image.get('server', {})
         updated = api_image.get('updated_at') or api_image['updated']
         created = api_image.get('created_at') or api_image['created']
-        print(api_image)
         min_ram = api_image.get('min_ram')
 
         if min_ram is None:
@@ -1313,6 +1312,7 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
                 status=api_image['status'],
                 progress=api_image.get('progress'),
                 metadata=api_image.get('metadata'),
+                os_type=api_image.get('os_type'),
                 serverId=server.get('id'),
                 minDisk=min_disk,
                 minRam=min_ram,
@@ -2519,7 +2519,7 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
 
     def get_image(self, image_id):
         """
-        Get a NodeImage using the V2 glance API
+        Get a NodeImage using the V2 Glance API
 
         @inherits: :class:`NodeDriver.get_image`
 
@@ -2531,6 +2531,26 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         return self._to_image(self.connection.request(
             '/v2/images/%s' % (image_id,)).object)
 
+    def list_images(self, location=None, ex_only_active=True):
+        """
+        Lists all active images using the V2 Glance API
+
+        @inherits: :class:`NodeDriver.list_images`
+        """
+        if location is not None:
+            raise NotImplementedError(
+                "location in list_images is not implemented "
+                "in the OpenStack_2_NodeDriver")
+        if not ex_only_active:
+            raise NotImplementedError(
+                "ex_only_active in list_images is not implemented "
+                "in the OpenStack_2_NodeDriver")
+        response = self.connection.request('/v2/images')
+        images = []
+        for image in response.object['images']:
+            images.append(self._to_image(image))
+        return images
+
 
 class OpenStack_1_1_FloatingIpPool(object):
     """

http://git-wip-us.apache.org/repos/asf/libcloud/blob/8e5dd528/libcloud/test/compute/fixtures/openstack_v1.1/_images_v2.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_images_v2.json b/libcloud/test/compute/fixtures/openstack_v1.1/_images_v2.json
new file mode 100644
index 0000000..f40a6d9
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_images_v2.json
@@ -0,0 +1 @@
+{"images": [{"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/com_osp_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_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/4bd743f8-7e7d-4568-8f31-b3f06b90e70a", "metadata":
{"mountpoint": "/var/lib/glance/images", "type": "nfs", "id": "NetApp1", "share_location":
"nfs://some.ip.somewhere/com_osp_data001"}}], "visibility": "private", "updated_at": "2017-09-07T13:07:33Z",
"owner": "d85e344900774f5aad27e4e8e91205d6", "schema": "/v2/schemas/image", "file": "/v2/images/4bd743f8-7e7d-4568-8f31-b3f06b90e70a/file",
"min_disk": 40, "virtual_size": null, "base_image_ref": "5be2b652-a965-4e
 cb-a2b4-b9f83d7779e6", "size": 1248264192, "instance_uuid": "b4166e71-f40b-4a5b-a489-87601ab8a600",
"os_distro": "ubuntu", "user_id": "b0d846d9ac93452bb93857e0305584bd", "name": "hypernode",
"image_type": "snapshot", "checksum": "1969ec22f73d524eb766b4c308e2192a", "created_at": "2017-09-07T13:06:24Z",
"disk_format": "qcow2", "id": "4bd743f8-7e7d-4568-8f31-b3f06b90e70a", "protected": false,
"os_type": "linux", "direct_url": "file:///var/lib/glance/images/4bd743f8-7e7d-4568-8f31-b3f06b90e70a",
"self": "/v2/images/4bd743f8-7e7d-4568-8f31-b3f06b90e70a", "owner_id": "d85e344900774f5aad27e4e8e91205d6"}],
"schema": "/v2/schemas/images", "first": "/v2/images"}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/8e5dd528/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index 858f825..985fcf9 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -1600,6 +1600,21 @@ class OpenStack_2_Tests(OpenStack_1_1_Tests):
         self.assertEqual(image.extra['minRam'], 0)
         self.assertEqual(image.extra['visibility'], "private")
 
+    def test_list_images(self):
+        images = self.driver.list_images()
+        self.assertEqual(len(images), 2, 'Wrong images count')
+
+        image = images[0]
+        self.assertEqual(image.id, 'f24a3c1b-d52a-4116-91da-25b3eee8f55e')
+        self.assertEqual(image.name, 'hypernode')
+        self.assertEqual(image.extra['updated'], '2017-11-28T10:19:49Z')
+        self.assertEqual(image.extra['created'], '2017-09-11T13:00:05Z')
+        self.assertEqual(image.extra['status'], 'active')
+        self.assertEqual(image.extra['os_type'], 'linux')
+        self.assertIsNone(image.extra['serverId'])
+        self.assertEqual(image.extra['minDisk'], 40)
+        self.assertEqual(image.extra['minRam'], 0)
+
 
 class OpenStack_1_1_FactoryMethodTests(OpenStack_1_1_Tests):
     should_list_locations = False
@@ -1754,6 +1769,13 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
         else:
             raise NotImplementedError()
 
+    def _v2_1337_v2_images(self, method, url, body, headers):
+        if method == "GET":
+            body = self.fixtures.load('_images_v2.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+        else:
+            raise NotImplementedError()
+
     def _v1_1_slug_images_26365521_8c62_11f9_2c33_283d153ecc3a(self, method, url, body, headers):
         if method == "DELETE":
             return (httplib.NO_CONTENT, "", {}, httplib.responses[httplib.NO_CONTENT])


Mime
View raw message