From 517e3db5bca6015c0ac95ebf7cdea18e9ff7fca5 Mon Sep 17 00:00:00 2001 From: Chandra Dasari Date: Fri, 14 May 2021 09:54:55 -0400 Subject: [PATCH] Refactor: Migrate shade library to openstacksdk Replacing shade library with openstacksdk for openstack image commands. Signed-off-by: Chandra Dasari Change-Id: I23f901de37d502674edc617784ad3095dbc38288 Issue: RELENG-3392 --- lftools/openstack/image.py | 14 ++++++++------ .../migrate-shade-to-openstacksdk-232ab9ff19f8cc61.yaml | 4 ++++ requirements.txt | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/migrate-shade-to-openstacksdk-232ab9ff19f8cc61.yaml diff --git a/lftools/openstack/image.py b/lftools/openstack/image.py index 9fef3745..5cc1a9cb 100644 --- a/lftools/openstack/image.py +++ b/lftools/openstack/image.py @@ -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 index 00000000..e1ab9ccc --- /dev/null +++ b/releasenotes/notes/migrate-shade-to-openstacksdk-232ab9ff19f8cc61.yaml @@ -0,0 +1,4 @@ +--- +other: + - | + The shade library for openstack is deprecated. We are switching to the openstacksdk for image commands. diff --git a/requirements.txt b/requirements.txt index 0d02590d..4116fc66 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 -- 2.16.6