From 396fa8771863be73d7c160f1f44296e9474f16ef Mon Sep 17 00:00:00 2001
From: Thomas Herve <therve@redhat.com>
Date: Wed, 11 Jan 2017 15:57:04 +0100
Subject: [PATCH] Default to Glance v2

While we still require Glance v1 for creating the glance image resource,
there is no reason to not default to v2 for everything else, which is
mostly the glance image constraint. Let's do that.

Change-Id: I5919ec4e884e66941dc8a7365db34f34422d5191
(cherry picked from commit 6813a76e751c1d2bfab1ba2ca563c8ce033cbaf6)
---
 heat/engine/clients/os/glance.py                |  2 +-
 heat/engine/resources/openstack/glance/image.py | 28 ++++++++++++-------------
 2 files changed, 14 insertions(+), 16 deletions(-)

Index: heat-7.0.7.dev8/heat/engine/clients/os/glance.py
===================================================================
--- heat-7.0.7.dev8.orig/heat/engine/clients/os/glance.py
+++ heat-7.0.7.dev8/heat/engine/clients/os/glance.py
@@ -30,7 +30,7 @@ class GlanceClientPlugin(client_plugin.C
 
     supported_versions = [V1, V2] = ['1', '2']
 
-    default_version = V1
+    default_version = V2
 
     def _create(self, version=None):
         con = self.context
Index: heat-7.0.7.dev8/heat/engine/resources/openstack/glance/image.py
===================================================================
--- heat-7.0.7.dev8.orig/heat/engine/resources/openstack/glance/image.py
+++ heat-7.0.7.dev8/heat/engine/resources/openstack/glance/image.py
@@ -180,22 +180,22 @@ class GlanceImage(resource.Resource):
         os_distro = args.pop(self.OS_DISTRO, None)
         ramdisk_id = args.pop(self.RAMDISK_ID, None)
 
-        image_id = self.client().images.create(**args).id
+        image_id = self.client(version=self.client_plugin().V1).images.create(
+            **args).id
         self.resource_id_set(image_id)
 
-        v2_images = self.client(version=self.client_plugin().V2).images
+        images = self.client().images
         if architecture is not None:
-            v2_images.update(image_id, architecture=architecture)
+            images.update(image_id, architecture=architecture)
         if kernel_id is not None:
-            v2_images.update(image_id, kernel_id=kernel_id)
+            images.update(image_id, kernel_id=kernel_id)
         if os_distro is not None:
-            v2_images.update(image_id, os_distro=os_distro)
+            images.update(image_id, os_distro=os_distro)
         if ramdisk_id is not None:
-            v2_images.update(image_id, ramdisk_id=ramdisk_id)
+            images.update(image_id, ramdisk_id=ramdisk_id)
 
         for tag in tags:
-            self.client(
-                version=self.client_plugin().V2).image_tags.update(
+            self.client().image_tags.update(
                 image_id,
                 tag)
 
@@ -212,20 +212,18 @@ class GlanceImage(resource.Resource):
 
             new_tags = set(diff_tags) - set(existing_tags)
             for tag in new_tags:
-                self.client(
-                    version=self.client_plugin().V2).image_tags.update(
+                self.client().image_tags.update(
                     self.resource_id,
                     tag)
 
             removed_tags = set(existing_tags) - set(diff_tags)
             for tag in removed_tags:
                 with self.client_plugin().ignore_not_found:
-                    self.client(
-                        version=self.client_plugin().V2).image_tags.delete(
+                    self.client().image_tags.delete(
                         self.resource_id,
                         tag)
 
-        v2_images = self.client(version=self.client_plugin().V2).images
+        images = self.client().images
 
         if self.EXTRA_PROPERTIES in prop_diff:
             old_properties = self.properties.get(self.EXTRA_PROPERTIES) or {}
@@ -236,9 +234,9 @@ class GlanceImage(resource.Resource):
             # Though remove_props defaults to None within the glanceclient,
             # setting it to a list (possibly []) every time ensures only one
             # calling format to images.update
-            v2_images.update(self.resource_id, remove_props, **prop_diff)
+            images.update(self.resource_id, remove_props, **prop_diff)
         else:
-            v2_images.update(self.resource_id, **prop_diff)
+            images.update(self.resource_id, **prop_diff)
 
     def _show_resource(self):
         if self.glance().version == 1.0:
