Add SDK support for `glance image-tasks`
This patch adds the missing sdk support for the image-tasks to retrieve tasks associated to a particular image Change-Id: Ifa4d7ca58da98a96b86dc7a55a87fbd78f8d45bd Signed-off-by: Cyril Roelandt <cyril@redhat.com>
This commit is contained in:
committed by
Cyril Roelandt
parent
8c2f9a1e57
commit
2d8ff66030
@@ -22,6 +22,13 @@ Image Operations
|
||||
deactivate_image, reactivate_image, stage_image,
|
||||
add_tag, remove_tag
|
||||
|
||||
Image Task Operations
|
||||
^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. autoclass:: openstack.image.v2._proxy.Proxy
|
||||
:noindex:
|
||||
:members: image_tasks
|
||||
|
||||
Member Operations
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import warnings
|
||||
from openstack import exceptions
|
||||
from openstack.image.v2 import cache as _cache
|
||||
from openstack.image.v2 import image as _image
|
||||
from openstack.image.v2 import image_tasks as _image_tasks
|
||||
from openstack.image.v2 import member as _member
|
||||
from openstack.image.v2 import metadef_namespace as _metadef_namespace
|
||||
from openstack.image.v2 import metadef_object as _metadef_object
|
||||
@@ -1021,6 +1022,19 @@ class Proxy(proxy.Proxy):
|
||||
|
||||
return True
|
||||
|
||||
def image_tasks(self, image):
|
||||
"""Return a generator of Image Tasks
|
||||
|
||||
:param image: The value can be either the name of an image or a
|
||||
:class:`~openstack.image.v2.image.Image` instance.
|
||||
:return: A generator object of image tasks
|
||||
:rtype: :class: ~openstack.image.v2.image_tasks.ImageTasks
|
||||
:raises: :class:`~openstack.exceptions.NotFoundException`
|
||||
when no resource can be found.
|
||||
"""
|
||||
image_id = resource.Resource._get_id(image)
|
||||
return self._list(_image_tasks.ImageTasks, image_id=image_id)
|
||||
|
||||
def add_tag(self, image, tag):
|
||||
"""Add a tag to an image
|
||||
|
||||
|
||||
57
openstack/image/v2/image_tasks.py
Normal file
57
openstack/image/v2/image_tasks.py
Normal file
@@ -0,0 +1,57 @@
|
||||
# Copyright 2024 RedHat Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from openstack import resource
|
||||
|
||||
|
||||
class ImageTasks(resource.Resource):
|
||||
resources_key = 'tasks'
|
||||
base_path = '/images/%(image_id)s/tasks'
|
||||
|
||||
allow_list = True
|
||||
|
||||
_max_microversion = '2.17'
|
||||
|
||||
#: The type of task represented by this content
|
||||
type = resource.Body('type')
|
||||
#: The current status of this task. The value can be pending, processing,
|
||||
#: success or failure
|
||||
status = resource.Body('status')
|
||||
#: An identifier for the owner of the task, usually the tenant ID
|
||||
owner = resource.Body('owner')
|
||||
#: The date and time when the task is subject to removal (ISO8601 format)
|
||||
expires_at = resource.Body('expires_at')
|
||||
#: The date and time when the task was created (ISO8601 format)
|
||||
created_at = resource.Body('created_at')
|
||||
#: The date and time when the task was updated (ISO8601 format)
|
||||
updated_at = resource.Body('updated_at')
|
||||
#: The date and time when the task was deleted (ISO8601 format)
|
||||
deleted_at = resource.Body('deleted_at')
|
||||
#: Whether the task was deleted
|
||||
deleted = resource.Body('deleted')
|
||||
#: The ID of the image associated to this task
|
||||
image_id = resource.Body('image_id')
|
||||
#: The request ID of the user message
|
||||
request_id = resource.Body('request_id')
|
||||
#: The user id associated with this task
|
||||
user_id = resource.Body('user_id')
|
||||
#: A JSON object specifying the input parameters to the task
|
||||
input = resource.Body('input')
|
||||
#: A JSON object specifying information about the ultimate outcome of the
|
||||
#: task
|
||||
result = resource.Body('result')
|
||||
#: Human-readable text, possibly an empty string, usually displayed in a
|
||||
#: error situation to provide more information about what has occurred
|
||||
message = resource.Body('message')
|
||||
60
openstack/tests/unit/image/v2/test_image_tasks.py
Normal file
60
openstack/tests/unit/image/v2/test_image_tasks.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# Copyright 2024 RedHat Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import testtools
|
||||
|
||||
from openstack.image.v2 import image_tasks
|
||||
|
||||
EXAMPLE = {
|
||||
'id': '56ab5f98-2bb7-44c7-bc05-52bde37eb53b',
|
||||
'type': 'import',
|
||||
'status': 'failure',
|
||||
'owner': '2858d31bc5f54f4db66e53ab905ef566',
|
||||
'expires_at': '2024-10-10T09:28:58.000000',
|
||||
'created_at': '2024-10-08T09:28:58.000000',
|
||||
'updated_at': '2024-10-08T09:28:58.000000',
|
||||
'deleted_at': None,
|
||||
'deleted': False,
|
||||
'image_id': '56a39162-730d-401c-8a77-11bc078cf3e2',
|
||||
'request_id': 'req-7d2f073c-f6f8-4807-9fdb-5ce6b10c65c5',
|
||||
'user_id': 'dec9b6d341ec481abddf1027576c2d60',
|
||||
'input': {'image_id': '56a39162-730d-401c-8a77-11bc078cf3e2'},
|
||||
'result': None,
|
||||
'message': "Input does not contain 'import_from' field",
|
||||
}
|
||||
|
||||
|
||||
class TestImageTasks(testtools.TestCase):
|
||||
def test_basic(self):
|
||||
sot = image_tasks.ImageTasks()
|
||||
self.assertEqual('/images/%(image_id)s/tasks', sot.base_path)
|
||||
self.assertTrue(sot.allow_list)
|
||||
|
||||
def test_make_it(self):
|
||||
sot = image_tasks.ImageTasks(**EXAMPLE)
|
||||
self.assertEqual(EXAMPLE['id'], sot.id)
|
||||
self.assertEqual(EXAMPLE['type'], sot.type)
|
||||
self.assertEqual(EXAMPLE['status'], sot.status)
|
||||
self.assertEqual(EXAMPLE['owner'], sot.owner)
|
||||
self.assertEqual(EXAMPLE['expires_at'], sot.expires_at)
|
||||
self.assertEqual(EXAMPLE['created_at'], sot.created_at)
|
||||
self.assertEqual(EXAMPLE['updated_at'], sot.updated_at)
|
||||
self.assertEqual(EXAMPLE['deleted_at'], sot.deleted_at)
|
||||
self.assertEqual(EXAMPLE['deleted'], sot.deleted)
|
||||
self.assertEqual(EXAMPLE['image_id'], sot.image_id)
|
||||
self.assertEqual(EXAMPLE['request_id'], sot.request_id)
|
||||
self.assertEqual(EXAMPLE['user_id'], sot.user_id)
|
||||
self.assertEqual(EXAMPLE['input'], sot.input)
|
||||
self.assertEqual(EXAMPLE['result'], sot.result)
|
||||
self.assertEqual(EXAMPLE['message'], sot.message)
|
||||
@@ -21,6 +21,7 @@ from openstack import exceptions
|
||||
from openstack.image.v2 import _proxy
|
||||
from openstack.image.v2 import cache as _cache
|
||||
from openstack.image.v2 import image as _image
|
||||
from openstack.image.v2 import image_tasks as _image_tasks
|
||||
from openstack.image.v2 import member as _member
|
||||
from openstack.image.v2 import metadef_namespace as _metadef_namespace
|
||||
from openstack.image.v2 import metadef_object as _metadef_object
|
||||
@@ -605,6 +606,14 @@ class TestImage(TestImageProxy):
|
||||
expected_args=[self.proxy],
|
||||
)
|
||||
|
||||
def test_image_tasks(self):
|
||||
self.verify_list(
|
||||
self.proxy.image_tasks,
|
||||
_image_tasks.ImageTasks,
|
||||
method_kwargs={'image': 'image_1'},
|
||||
expected_kwargs={'image_id': 'image_1'},
|
||||
)
|
||||
|
||||
|
||||
class TestMember(TestImageProxy):
|
||||
def test_member_create(self):
|
||||
|
||||
5
releasenotes/notes/get-image-tasks-c66a05c2c67976db.yaml
Normal file
5
releasenotes/notes/get-image-tasks-c66a05c2c67976db.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Adds operation which retrieves tasks associated
|
||||
to a particular image.
|
||||
Reference in New Issue
Block a user