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:28 UTC

[01/13] libcloud git commit: implement openstack v2 glance image api

Repository: libcloud
Updated Branches:
  refs/heads/trunk 1eca23bad -> 013f8849d


implement openstack v2 glance image api

currently the compute driver uses the nova proxy to the glance image api, but this proxied api is deprecated and can not handle functionality like image sharing (setting an image to shared, creating new image members and accepting images as image members). this commit adds a connection to the glance API in the v2 driver

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

Branch: refs/heads/trunk
Commit: 1cb91d7fa304c0d92d5761fbea0db751dcfe6565
Parents: 1eca23b
Author: Rick van de Loo <ri...@gmail.com>
Authored: Wed Dec 6 16:54:44 2017 +0100
Committer: Quentin Pradet <qu...@apache.org>
Committed: Fri Mar 2 09:34:24 2018 +0400

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py           | 76 ++++++++++++++++++--
 ...es_f24a3c1b-d52a-4116-91da-25b3eee8f55d.json |  1 +
 ...es_f24a3c1b-d52a-4116-91da-25b3eee8f55e.json |  1 +
 libcloud/test/compute/test_openstack.py         | 58 ++++++++++++++-
 4 files changed, 130 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/1cb91d7f/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 38fd3aa..d56a8e2 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -15,6 +15,7 @@
 """
 OpenStack driver
 """
+
 from libcloud.common.exceptions import BaseHTTPError
 from libcloud.utils.iso8601 import parse_date
 
@@ -73,6 +74,12 @@ class OpenStackComputeConnection(OpenStackBaseConnection):
     service_region = 'RegionOne'
 
 
+class OpenStackImageConnection(OpenStackBaseConnection):
+    service_type = 'image'
+    service_name = 'glance'
+    service_region = 'RegionOne'
+
+
 class OpenStackNodeDriver(NodeDriver, OpenStackDriverMixin):
     """
     Base OpenStack node driver. Should not be used directly.
@@ -1283,19 +1290,32 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
 
     def _to_image(self, api_image):
         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:
+            min_ram = api_image.get('minRam')
+        min_disk = api_image.get('min_disk')
+
+        if min_disk is None:
+            min_disk = api_image.get('minDisk')
+
         return NodeImage(
             id=api_image['id'],
             name=api_image['name'],
             driver=self,
             extra=dict(
-                updated=api_image['updated'],
-                created=api_image['created'],
+                visibility=api_image.get('visibility'),
+                updated=updated,
+                created=created,
                 status=api_image['status'],
                 progress=api_image.get('progress'),
                 metadata=api_image.get('metadata'),
                 serverId=server.get('id'),
-                minDisk=api_image.get('minDisk'),
-                minRam=api_image.get('minRam'),
+                minDisk=min_disk,
+                minRam=min_ram,
             )
         )
 
@@ -2446,23 +2466,71 @@ class OpenStack_2_Connection(OpenStackComputeConnection):
         return json.dumps(data)
 
 
+class OpenStack_2_ImageConnection(OpenStackImageConnection):
+    responseCls = OpenStack_1_1_Response
+    accept_format = 'application/json'
+    default_content_type = 'application/json; charset=UTF-8'
+
+    def encode_data(self, data):
+        return json.dumps(data)
+
+
 class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
     """
     OpenStack node driver.
     """
     connectionCls = OpenStack_2_Connection
+
+    # Previously all image functionality was available through the
+    # compute API. This deprecated proxied API does not offer all
+    # functionality that the Glance Image service API offers.
+    # See https://developer.openstack.org/api-ref/compute/
+    # > These APIs are proxy calls to the Image service. Nova has deprecated all
+    # > the proxy APIs and users should use the native APIs instead. These will fail
+    # > with a 404 starting from microversion 2.36. See: Relevant Image APIs.
+    # For example, managing image visibility and sharing machine images across
+    # tenants can not be done using the proxied image API in the compute endpoint,
+    # but it can be done with the Glance Image API.
+    # See https://developer.openstack.org/api-ref/image/v2/index.html#list-image-members
+    image_connectionCls = OpenStack_2_ImageConnection
+    image_connection = None
     type = Provider.OPENSTACK
 
     features = {"create_node": ["generates_password"]}
     _networks_url_prefix = '/os-networks'
 
     def __init__(self, *args, **kwargs):
+        original_connectionCls = self.connectionCls
         self._ex_force_api_version = str(kwargs.pop('ex_force_api_version',
                                                     None))
         if 'ex_force_auth_version' not in kwargs:
             kwargs['ex_force_auth_version'] = '3.x_password'
+
+        # We run the init once to get the Glance V2 API connection
+        # and put that on the object under self.image_connection.
+        self.connectionCls = self.image_connectionCls
+        super(OpenStack_2_NodeDriver, self).__init__(*args, **kwargs)
+        self.image_connection = self.connection
+
+        # We run the init again to get the compute API connection
+        # and that's put under self.connection as normal.
+        self.connectionCls = original_connectionCls
         super(OpenStack_2_NodeDriver, self).__init__(*args, **kwargs)
 
+    def get_image(self, image_id):
+        """
+        Get a NodeImage using the V2 glance API
+
+        @inherits: :class:`NodeDriver.get_image`
+
+        :param      image_id: ID of the image which should be used
+        :type       image_id: ``str``
+
+        :rtype: :class:`NodeImage`
+        """
+        return self._to_image(self.connection.request(
+            '/v2/images/%s' % (image_id,)).object)
+
 
 class OpenStack_1_1_FloatingIpPool(object):
     """

http://git-wip-us.apache.org/repos/asf/libcloud/blob/1cb91d7f/libcloud/test/compute/fixtures/openstack_v1.1/_images_f24a3c1b-d52a-4116-91da-25b3eee8f55d.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_images_f24a3c1b-d52a-4116-91da-25b3eee8f55d.json b/libcloud/test/compute/fixtures/openstack_v1.1/_images_f24a3c1b-d52a-4116-91da-25b3eee8f55d.json
new file mode 100644
index 0000000..03bbfaa
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_images_f24a3c1b-d52a-4116-91da-25b3eee8f55d.json
@@ -0,0 +1 @@
+{"status": "saving", "image_location": "snapshot", "image_state": "pending", "tags": [], "kernel_id": null, "container_format": "bare", "min_ram": 0, "ramdisk_id": null, "locations": [{"url": "file:///var/lib/glance/images/4949f9ee-2421-4c81-8b49-13119446008b", "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/4949f9ee-2421-4c81-8b49-13119446008b/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": "new_image", "image_type": "snapshot", "checksum": "3530464d095c9d62771b99ebecd2d70b", "created_at": "2017-09-11T13:00:05Z", "disk_fo
 rmat": "qcow2", "id": "4949f9ee-2421-4c81-8b49-13119446008b", "protected": false, "os_type": "linux", "direct_url": "file:///var/lib/glance/images/4949f9ee-2421-4c81-8b49-13119446008b", "self": "/v2/images/4949f9ee-2421-4c81-8b49-13119446008b", "owner_id": "d85e344900774f5aad27e4e8e91205d6"}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/1cb91d7f/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
new file mode 100644
index 0000000..82f4a92
--- /dev/null
+++ b/libcloud/test/compute/fixtures/openstack_v1.1/_images_f24a3c1b-d52a-4116-91da-25b3eee8f55e.json
@@ -0,0 +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"}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/1cb91d7f/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index 9f81203..858f825 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -46,8 +46,8 @@ from libcloud.compute.drivers.openstack import (
     OpenStackSecurityGroupRule, OpenStack_1_1_FloatingIpPool,
     OpenStack_1_1_FloatingIpAddress, OpenStackKeyPair,
     OpenStack_1_0_Connection,
-    OpenStackNodeDriver
-)
+    OpenStackNodeDriver,
+    OpenStack_2_NodeDriver)
 from libcloud.compute.base import Node, NodeImage, NodeSize
 from libcloud.pricing import set_pricing, clear_pricing_data
 
@@ -1153,6 +1153,7 @@ class OpenStack_1_1_Tests(unittest.TestCase, TestCaseMixin):
         self.assertEqual(image.extra['serverId'], None)
         self.assertEqual(image.extra['minDisk'], "5")
         self.assertEqual(image.extra['minRam'], "256")
+        self.assertEqual(image.extra['visibility'], None)
 
     def test_delete_image(self):
         image = NodeImage(
@@ -1562,6 +1563,44 @@ class OpenStack_1_1_Tests(unittest.TestCase, TestCaseMixin):
         self.assertTrue(ret)
 
 
+class OpenStack_2_Tests(OpenStack_1_1_Tests):
+    driver_klass = OpenStack_2_NodeDriver
+    driver_type = OpenStack_2_NodeDriver
+    driver_kwargs = {
+        'ex_force_auth_version': '2.0',
+        'ex_force_auth_url': 'https://auth.api.example.com'
+    }
+
+    def test_ex_force_auth_token_passed_to_connection(self):
+        base_url = 'https://servers.api.rackspacecloud.com/v1.1/slug'
+        kwargs = {
+            'ex_force_auth_version': '2.0',
+            'ex_force_auth_token': 'preset-auth-token',
+            'ex_force_auth_url': 'https://auth.api.example.com',
+            'ex_force_base_url': base_url
+        }
+
+        driver = self.driver_type(*self.driver_args, **kwargs)
+        driver.list_nodes()
+
+        self.assertEqual(kwargs['ex_force_auth_token'],
+                         driver.connection.auth_token)
+        self.assertEqual('servers.api.rackspacecloud.com',
+                         driver.connection.host)
+        self.assertEqual('/v1.1/slug', driver.connection.request_path)
+        self.assertEqual(443, driver.connection.port)
+
+    def test_get_image(self):
+        image_id = 'f24a3c1b-d52a-4116-91da-25b3eee8f55e'
+        image = self.driver.get_image(image_id)
+        self.assertEqual(image.id, image_id)
+        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'], "private")
+
+
 class OpenStack_1_1_FactoryMethodTests(OpenStack_1_1_Tests):
     should_list_locations = False
     should_list_volumes = True
@@ -1708,6 +1747,13 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
         else:
             raise NotImplementedError()
 
+    def _v2_1337_v2_images_f24a3c1b_d52a_4116_91da_25b3eee8f55e(self, method, url, body, headers):
+        if method == "GET":
+            body = self.fixtures.load('_images_f24a3c1b-d52a-4116-91da-25b3eee8f55e.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])
@@ -1722,6 +1768,14 @@ class OpenStack_1_1_MockHttp(MockHttp, unittest.TestCase):
         else:
             raise NotImplementedError()
 
+    def _v2_1337_v2_images_4949f9ee_2421_4c81_8b49_13119446008b(self, method, url, body, headers):
+        if method == "GET":
+            body = self.fixtures.load(
+                '_images_f24a3c1b-d52a-4116-91da-25b3eee8f55d.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+        else:
+            raise NotImplementedError()
+
     def _v1_1_slug_servers_1c01300f_ef97_4937_8f03_ac676d6234be_os_security_groups(self, method, url, body, headers):
         if method == "GET":
             body = self.fixtures.load(


[08/13] libcloud git commit: openstack_identity tests check for glance

Posted by qu...@apache.org.
openstack_identity tests check for glance

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

Branch: refs/heads/trunk
Commit: e3ec8e53bcb8b59874c232b47b0c2237230e05e8
Parents: 9a3f98e
Author: Rick van de Loo <ri...@gmail.com>
Authored: Wed Dec 6 18:02:40 2017 +0100
Committer: Quentin Pradet <qu...@apache.org>
Committed: Fri Mar 2 09:34:26 2018 +0400

----------------------------------------------------------------------
 libcloud/test/common/test_openstack_identity.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/e3ec8e53/libcloud/test/common/test_openstack_identity.py
----------------------------------------------------------------------
diff --git a/libcloud/test/common/test_openstack_identity.py b/libcloud/test/common/test_openstack_identity.py
index 79a129e..9ac042c 100644
--- a/libcloud/test/common/test_openstack_identity.py
+++ b/libcloud/test/common/test_openstack_identity.py
@@ -525,7 +525,7 @@ class OpenStackServiceCatalogTestCase(unittest.TestCase):
         catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                           auth_version='2.0')
         entries = catalog.get_entries()
-        self.assertEqual(len(entries), 6)
+        self.assertEqual(len(entries), 7)
 
         entry = [e for e in entries if e.service_name == 'cloudServers'][0]
         self.assertEqual(entry.service_type, 'compute')
@@ -591,7 +591,7 @@ class OpenStackServiceCatalogTestCase(unittest.TestCase):
         catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                           auth_version='2.0')
         service_types = catalog.get_service_types()
-        self.assertEqual(service_types, ['compute', 'object-store',
+        self.assertEqual(service_types, ['compute', 'image', 'object-store',
                                          'rax:object-cdn'])
 
         service_types = catalog.get_service_types(region='ORD')
@@ -610,6 +610,7 @@ class OpenStackServiceCatalogTestCase(unittest.TestCase):
                                          'cloudServers',
                                          'cloudServersOpenStack',
                                          'cloudServersPreprod',
+                                         'glance',
                                          'nova'])
 
         service_names = catalog.get_service_names(service_type='compute')


[12/13] libcloud git commit: Fix changes that will not be in 2.3.0

Posted by qu...@apache.org.
Fix changes that will not be in 2.3.0


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

Branch: refs/heads/trunk
Commit: ff6d180db8a10e69bdbda48fadaad85c90539925
Parents: b41da95
Author: Quentin Pradet <qu...@apache.org>
Authored: Fri Mar 2 09:36:40 2018 +0400
Committer: Quentin Pradet <qu...@apache.org>
Committed: Fri Mar 2 09:36:40 2018 +0400

----------------------------------------------------------------------
 CHANGES.rst | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/ff6d180d/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index 9ad4c0b..c5c55ff 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,6 +1,24 @@
 Changelog
 =========
 
+Changes in Apache Libcloud in development
+-----------------------------------------
+
+Compute
+~~~~~~~
+
+- [Dimension Data] Fix IndexError in list_images (GITHUB-1171)
+  [Adam Friedman]
+
+- [EC2] Add AWS eu-west-3 (Paris) region (GITHUB-1175)
+  [Anthony Monthe]
+
+- [GCE] Expand GCE Firewall options coverage (LIBCLOUD-960, GITHUB-1144)
+  [maxlip]
+
+- [GCE] Extend ex_create_address to allow internal ip creation (GITHUB-1174)
+  [Jeremy Solarz]
+
 Changes in Apache Libcloud 2.3.0
 --------------------------------
 
@@ -83,9 +101,6 @@ Compute
   (LIBCLOUD-977, GITHUB-1169)
   [Adam Wight]
 
-- [Dimension Data] Fix IndexError in list_images (GITHUB-1171)
-  [Adam Friedman]
-
 - [EC2] Add new x1.16xlarge and x1e.32xlarge instance type. (GITHUB-1101)
   [Anthony Monthe]
 
@@ -105,9 +120,6 @@ Compute
 - [EC2] Fix EBS volume encryption (GITHUB-1008)
   [Sergey Babak]
 
-- [EC2] Add AWS eu-west-3 (Paris) region (GITHUB-1175)
-  [Anthony Monthe]
-
 - [ECS Aliyun] Support modify_security_group_attributes (GITHUB-1157)
   [Zhang Yiming]
 
@@ -136,12 +148,6 @@ Compute
 - [GCE] Add support for accelerators (LIBCLOUD-963, GITHUB-1163)
   [Michael Johnson]
 
-- [GCE] Extend ex_create_address to allow internal ip creation (GITHUB-1174)
-  [Jeremy Solarz]
-
-- [GCE] Expand GCE Firewall options coverage (LIBCLOUD-960, GITHUB-1144)
-  [maxlip]
-
 - [ProfitBricks] Update driver and add support for the new API v4. (GITHUB-1103)
   [Nurfet Becirevic]
 


[04/13] libcloud git commit: add glance endpoint to openstack auth fixture

Posted by qu...@apache.org.
add glance endpoint to openstack auth fixture

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

Branch: refs/heads/trunk
Commit: b6572d7ff0a1e14591a1d7470d67a9dd86ccde7c
Parents: 8e5dd52
Author: Rick van de Loo <ri...@gmail.com>
Authored: Wed Dec 6 17:43:53 2017 +0100
Committer: Quentin Pradet <qu...@apache.org>
Committed: Fri Mar 2 09:34:25 2018 +0400

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py           |  4 ++--
 .../compute/fixtures/openstack/_v2_0__auth.json | 22 ++++++++++++++++++++
 libcloud/test/compute/test_openstack.py         |  7 +++++++
 3 files changed, 31 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/b6572d7f/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 7917327..fe06975 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -2528,7 +2528,7 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
 
         :rtype: :class:`NodeImage`
         """
-        return self._to_image(self.connection.request(
+        return self._to_image(self.image_connection.request(
             '/v2/images/%s' % (image_id,)).object)
 
     def list_images(self, location=None, ex_only_active=True):
@@ -2545,7 +2545,7 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
             raise NotImplementedError(
                 "ex_only_active in list_images is not implemented "
                 "in the OpenStack_2_NodeDriver")
-        response = self.connection.request('/v2/images')
+        response = self.image_connection.request('/v2/images')
         images = []
         for image in response.object['images']:
             images.append(self._to_image(image))

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b6572d7f/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json b/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
index 9cbf93b..91fe35b 100644
--- a/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
+++ b/libcloud/test/compute/fixtures/openstack/_v2_0__auth.json
@@ -79,6 +79,28 @@
             {
                 "endpoints": [
                     {
+                        "region": "RegionOne",
+                        "tenantId": "1337",
+                        "publicURL": "https://test_endpoint.com/v2/1337",
+                        "versionInfo": "https://test_endpoint.com/v2/",
+                        "versionList": "https://test_endpoint.com/",
+                        "versionId": "2"
+                    },
+                    {
+                        "region": "fr1",
+                        "tenantId": "1337",
+                        "publicURL": "https://test_endpoint.com/v2/1337",
+                        "versionInfo": "https://test_endpoint.com/v2/",
+                        "versionList": "https://test_endpoint.com/",
+                        "versionId": "2"
+                    }
+                ],
+                "name": "glance",
+                "type": "image"
+            },
+            {
+                "endpoints": [
+                    {
                         "region": "DFW",
                         "tenantId": "613469",
                         "publicURL": "https://dfw.servers.api.rackspacecloud.com/v2/1337",

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b6572d7f/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index 985fcf9..a10b724 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -1571,6 +1571,13 @@ class OpenStack_2_Tests(OpenStack_1_1_Tests):
         'ex_force_auth_url': 'https://auth.api.example.com'
     }
 
+    def setUp(self):
+        super(OpenStack_2_Tests, self).setUp()
+        self.driver_klass.image_connectionCls.conn_class = OpenStack_2_0_MockHttp
+        self.driver_klass.image_connectionCls.auth_url = "https://auth.api.example.com"
+        # normally authentication happens lazily, but we force it here
+        self.driver.image_connection._populate_hosts_and_request_paths()
+
     def test_ex_force_auth_token_passed_to_connection(self):
         base_url = 'https://servers.api.rackspacecloud.com/v1.1/slug'
         kwargs = {


[09/13] libcloud git commit: add OpenStack_2_NodeDriver to api docs

Posted by qu...@apache.org.
add OpenStack_2_NodeDriver to api docs

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

Branch: refs/heads/trunk
Commit: b41da95179fa477027b93ff3efa2787ad12a4a9c
Parents: 2321d34
Author: Rick van de Loo <ri...@gmail.com>
Authored: Sun Feb 11 09:06:27 2018 +0100
Committer: Quentin Pradet <qu...@apache.org>
Committed: Fri Mar 2 09:34:26 2018 +0400

----------------------------------------------------------------------
 docs/compute/drivers/openstack.rst | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/b41da951/docs/compute/drivers/openstack.rst
----------------------------------------------------------------------
diff --git a/docs/compute/drivers/openstack.rst b/docs/compute/drivers/openstack.rst
index 17f9cc0..199fa38 100644
--- a/docs/compute/drivers/openstack.rst
+++ b/docs/compute/drivers/openstack.rst
@@ -247,16 +247,23 @@ are supported by two different subclasses of the OpenStackNodeDriver. The
 default is the 1.1 API. The 1.0 API is supported to be able to connect to
 OpenStack instances which do not yet support the version 1.1 API.
 
-Compute 1.1 API version (current)
+Compute 2.0 API version (current)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-.. autoclass:: libcloud.compute.drivers.openstack.OpenStack_1_1_NodeDriver
+.. autoclass:: libcloud.compute.drivers.openstack.OpenStack_2_NodeDriver
     :members:
     :inherited-members:
 
-Compute 1.0 API version (old installations)
+Compute 1.1 API version (old installations)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+.. autoclass:: libcloud.compute.drivers.openstack.OpenStack_1_1_NodeDriver
+    :members:
+    :inherited-members:
+
+Compute 1.0 API version (older installations)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
 .. autoclass:: libcloud.compute.drivers.openstack.OpenStack_1_0_NodeDriver
     :members:
     :inherited-members:


[05/13] libcloud git commit: fix OpenStack_2_NodeDriver docstring

Posted by qu...@apache.org.
fix OpenStack_2_NodeDriver docstring

> This actually inherits get_image from
> OpenStack_1_1_NodeDriver. - pquentin

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

Branch: refs/heads/trunk
Commit: eedcf77d9691a4f8aeabb23f5f69c054c53b0cbd
Parents: 2858623
Author: Rick van de Loo <ri...@gmail.com>
Authored: Sat Feb 10 18:09:58 2018 +0100
Committer: Quentin Pradet <qu...@apache.org>
Committed: Fri Mar 2 09:34:26 2018 +0400

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/eedcf77d/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index a8d339f..9bd3881 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -2522,7 +2522,7 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         """
         Get a NodeImage using the V2 Glance API
 
-        @inherits: :class:`NodeDriver.get_image`
+        @inherits: :class:`OpenStack_1_1_NodeDriver.get_image`
 
         :param      image_id: ID of the image which should be used
         :type       image_id: ``str``


[07/13] libcloud git commit: use image_connection in v2 OS update_image

Posted by qu...@apache.org.
use image_connection in v2 OS update_image

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

Branch: refs/heads/trunk
Commit: 2321d34f7d095d98470c3bc1aaeb1d77b0d94bd6
Parents: 1da2550
Author: Rick van de Loo <ri...@gmail.com>
Authored: Sat Feb 10 19:01:49 2018 +0100
Committer: Quentin Pradet <qu...@apache.org>
Committed: Fri Mar 2 09:34:26 2018 +0400

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/2321d34f/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 28b708e..020b657 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -2570,12 +2570,17 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         """
         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
+        for example: [
+          {'op': 'replace', 'path': '/visibility', 'value': 'shared'}
+        ]
+
         :type       data: ``dict|list``
         :rtype: :class:`NodeImage`
         """
-        response = self.connection.request(
+        response = self.image_connection.request(
             '/v2/images/%s' % (image_id,),
             headers={'Content-type': 'application/'
                                      'openstack-images-'


[06/13] libcloud git commit: docstr location and ex_only_active OS list_images

Posted by qu...@apache.org.
docstr location and ex_only_active OS list_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/8f12b92e
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/8f12b92e
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/8f12b92e

Branch: refs/heads/trunk
Commit: 8f12b92ebd1bf0395d169fb02773f6c6bedb09fe
Parents: eedcf77
Author: Rick van de Loo <ri...@gmail.com>
Authored: Sat Feb 10 18:13:10 2018 +0100
Committer: Quentin Pradet <qu...@apache.org>
Committed: Fri Mar 2 09:34:26 2018 +0400

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/8f12b92e/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 9bd3881..3dfa47a 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -281,7 +281,7 @@ class OpenStackNodeDriver(NodeDriver, OpenStackDriverMixin):
 
         @inherits: :class:`NodeDriver.list_images`
 
-        :param ex_only_active: True if list only active
+        :param ex_only_active: True if list only active (optional)
         :type ex_only_active: ``bool``
 
         """
@@ -2537,6 +2537,16 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
         Lists all active images using the V2 Glance API
 
         @inherits: :class:`NodeDriver.list_images`
+
+        :param location: Which data center to list the images in. If
+                               empty, undefined behavior will be selected.
+                               (optional)
+
+        :type location: :class:`.NodeLocation`
+        :param ex_only_active: True if list only active (optional)
+
+        :type ex_only_active: ``bool``
+
         """
         if location is not None:
             raise NotImplementedError(


[02/13] libcloud git commit: implement openstack ex_update_image

Posted by qu...@apache.org.
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:


[13/13] libcloud git commit: Add changes for #1151

Posted by qu...@apache.org.
Add changes for #1151

Closes #1151


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

Branch: refs/heads/trunk
Commit: 013f8849d2357c730ac17ea3ca6b171f6b0d7a7f
Parents: ff6d180
Author: Quentin Pradet <qu...@apache.org>
Authored: Fri Mar 2 09:38:50 2018 +0400
Committer: Quentin Pradet <qu...@apache.org>
Committed: Fri Mar 2 09:38:50 2018 +0400

----------------------------------------------------------------------
 CHANGES.rst | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/013f8849/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index c5c55ff..c9f8bc1 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -19,6 +19,8 @@ Compute
 - [GCE] Extend ex_create_address to allow internal ip creation (GITHUB-1174)
   [Jeremy Solarz]
 
+- [OpenStack] Implement Glance Image API v2 (GITHUB-1151)
+
 Changes in Apache Libcloud 2.3.0
 --------------------------------
 


[11/13] libcloud git commit: add space after if min_ram

Posted by qu...@apache.org.
add space after if min_ram

>  it's surprising to visually group min_ram and min_disk. I guess I
>  would have added newlines after the if statements. - pquentin

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

Branch: refs/heads/trunk
Commit: 28586230c26d83ab4a3510713771f1bd3cf085d7
Parents: e3ec8e5
Author: Rick van de Loo <ri...@gmail.com>
Authored: Sat Feb 10 18:08:44 2018 +0100
Committer: Quentin Pradet <qu...@apache.org>
Committed: Fri Mar 2 09:34:26 2018 +0400

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/28586230/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index d528758..a8d339f 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -1296,6 +1296,7 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
 
         if min_ram is None:
             min_ram = api_image.get('minRam')
+
         min_disk = api_image.get('min_disk')
 
         if min_disk is None:


[10/13] libcloud git commit: fix line too long linting errors in OS driver

Posted by qu...@apache.org.
fix line too long linting errors in OS driver

fixes:
libcloud/compute/drivers/openstack.py:2488:80: E501 line too long (80 > 79 characters)
libcloud/compute/drivers/openstack.py:2489:80: E501 line too long (84 > 79 characters)
libcloud/compute/drivers/openstack.py:2492:80: E501 line too long (82 > 79 characters)
libcloud/compute/drivers/openstack.py:2494:80: E501 line too long (88 > 79 characters)

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

Branch: refs/heads/trunk
Commit: 1da255007897ad2099f8fa618ffb3abe938ba109
Parents: 8f12b92
Author: Rick van de Loo <ri...@gmail.com>
Authored: Sat Feb 10 18:15:11 2018 +0100
Committer: Quentin Pradet <qu...@apache.org>
Committed: Fri Mar 2 09:34:26 2018 +0400

----------------------------------------------------------------------
 libcloud/compute/drivers/openstack.py | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/1da25500/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 3dfa47a..28b708e 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -2486,13 +2486,17 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
     # compute API. This deprecated proxied API does not offer all
     # functionality that the Glance Image service API offers.
     # See https://developer.openstack.org/api-ref/compute/
-    # > These APIs are proxy calls to the Image service. Nova has deprecated all
-    # > the proxy APIs and users should use the native APIs instead. These will fail
-    # > with a 404 starting from microversion 2.36. See: Relevant Image APIs.
-    # For example, managing image visibility and sharing machine images across
-    # tenants can not be done using the proxied image API in the compute endpoint,
-    # but it can be done with the Glance Image API.
-    # See https://developer.openstack.org/api-ref/image/v2/index.html#list-image-members
+    #
+    # > These APIs are proxy calls to the Image service. Nova has deprecated
+    # > all the proxy APIs and users should use the native APIs instead. These
+    # > will fail with a 404 starting from microversion 2.36. See: Relevant
+    # > Image APIs.
+    #
+    # For example, managing image visibility and sharing machine
+    # images across tenants can not be done using the proxied image API in the
+    # compute endpoint, but it can be done with the Glance Image API.
+    # See https://developer.openstack.org/api-ref/
+    # image/v2/index.html#list-image-members
     image_connectionCls = OpenStack_2_ImageConnection
     image_connection = None
     type = Provider.OPENSTACK


[03/13] libcloud git commit: use glance api for openstack v2 list_images

Posted by qu...@apache.org.
use glance api for openstack v2 list_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/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 <ri...@gmail.com>
Authored: Wed Dec 6 17:23:47 2017 +0100
Committer: Quentin Pradet <qu...@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])