Refactor: Migrate shade library to openstacksdk 29/67729/4
authorChandra Dasari <cdasari@contractor.linuxfoundation.org>
Fri, 14 May 2021 13:54:55 +0000 (09:54 -0400)
committerChandra Dasari <cdasari@contractor.linuxfoundation.org>
Tue, 18 May 2021 17:33:14 +0000 (13:33 -0400)
Replacing shade library with openstacksdk for openstack image commands.

Signed-off-by: Chandra Dasari <cdasari@contractor.linuxfoundation.org>
Change-Id: I23f901de37d502674edc617784ad3095dbc38288
Issue: RELENG-3392

lftools/openstack/image.py
releasenotes/notes/migrate-shade-to-openstacksdk-232ab9ff19f8cc61.yaml [new file with mode: 0644]
requirements.txt

index 9fef374..5cc1a9c 100644 (file)
@@ -20,7 +20,9 @@ import subprocess
 import sys
 import tempfile
 
-import shade
+import openstack
+import openstack.config
+from openstack.cloud.exc import OpenStackCloudException
 from six.moves import urllib
 
 log = logging.getLogger(__name__)
@@ -52,7 +54,7 @@ def _filter_images(images, days=0, hide_public=False, ci_managed=True):
 
 def list(os_cloud, days=0, hide_public=False, ci_managed=True):
     """List images found according to parameters."""
-    cloud = shade.openstack_cloud(cloud=os_cloud)
+    cloud = openstack.connection.from_config(cloud=os_cloud)
     images = cloud.list_images()
 
     filtered_images = _filter_images(images, days, hide_public, ci_managed)
@@ -93,7 +95,7 @@ def cleanup(os_cloud, days=0, hide_public=False, ci_managed=True, clouds=None):
 
             try:
                 result = cloud.delete_image(image.name)
-            except shade.exc.OpenStackCloudException as e:
+            except OpenStackCloudException as e:
                 if str(e).startswith("Multiple matches found for"):
                     log.warning("{}. Skipping image...".format(str(e)))
                     continue
@@ -110,11 +112,11 @@ def cleanup(os_cloud, days=0, hide_public=False, ci_managed=True, clouds=None):
             else:
                 log.info('Removed "{}" from {}.'.format(image.name, cloud.cloud_config.name))
 
-    cloud = shade.openstack_cloud(cloud=os_cloud)
+    cloud = openstack.connection.from_config(cloud=os_cloud)
     if clouds:
         cloud_list = []
         for c in clouds.split(","):
-            cloud_list.append(shade.openstack_cloud(cloud=c))
+            cloud_list.append(openstack.connection.from_config(cloud=c))
 
     images = cloud.list_images()
     filtered_images = _filter_images(images, days, hide_public, ci_managed)
@@ -201,7 +203,7 @@ def share(os_cloud, image, clouds):
 def upload(os_cloud, image, name, disk_format="raw"):
     """Upload image to openstack."""
     log.info('Uploading image {} with name "{}".'.format(image, name))
-    cloud = shade.openstack_cloud(cloud=os_cloud)
+    cloud = openstack.connection.from_config(cloud=os_cloud)
 
     if re.match(r"^http[s]?://", image):
         tmp = tempfile.NamedTemporaryFile(suffix=".img")
diff --git a/releasenotes/notes/migrate-shade-to-openstacksdk-232ab9ff19f8cc61.yaml b/releasenotes/notes/migrate-shade-to-openstacksdk-232ab9ff19f8cc61.yaml
new file mode 100644 (file)
index 0000000..e1ab9cc
--- /dev/null
@@ -0,0 +1,4 @@
+---
+other:
+  - |
+    The shade library for openstack is deprecated. We are switching to the openstacksdk for image commands.
index 0d02590..4116fc6 100644 (file)
@@ -45,3 +45,4 @@ urllib3==1.25.8
 websocket-client==0.57.0
 wrapt==1.12.1
 xdg==3.0.2
+openstacksdk==0.56.0