Skip to content

Commit

Permalink
439 ims jobs querying (#442)
Browse files Browse the repository at this point in the history
439 ims jobs querying

Reviewed-by: Anton Sidelnikov
  • Loading branch information
RusselSand authored Jun 12, 2024
1 parent 28023d8 commit 8fb7832
Show file tree
Hide file tree
Showing 37 changed files with 442 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .stestr.blacklist.functional
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ otcextensions.tests.functional.sdk.waf.v1.test_domain*
otcextensions.tests.functional.sdk.tms*
otcextensions.tests.functional.sdk.nat.v2.test_dnat*
otcextensions.tests.functional.osclient.kms*
otcextensions.tests.functional.sdk.ims*
otcextensions.tests.functional.sdk.imsv1*
otcextensions.tests.functional.sdk.imsv2*
20 changes: 20 additions & 0 deletions doc/source/sdk/proxies/ims_v1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
IMS API
=======

.. automodule:: otcextensions.sdk.imsv1.v1._proxy

The Image Management Service Class
----------------------------------

Image Management Service (IMS) high-level interface is
available through the ``ims`` member of a
:class:`~openstack.connection.Connection` object. The ``ims`` member
will only be added if the ``otcextensions.sdk.register_otc_extensions(conn)``
method is called.

Image Operations
^^^^^^^^^^^^^^^^^^^^^^^^^

.. autoclass:: otcextensions.sdk.imsv1.v1._proxy.Proxy
:noindex:
:members: get_async_job
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
IMS API
=======

.. automodule:: otcextensions.sdk.ims.v2._proxy
.. automodule:: otcextensions.sdk.imsv2.v2._proxy

The Image Management Service Class
----------------------------------
Expand All @@ -15,6 +15,6 @@ method is called.
Image Operations
^^^^^^^^^^^^^^^^^^^^^^^^^

.. autoclass:: otcextensions.sdk.ims.v2._proxy.Proxy
.. autoclass:: otcextensions.sdk.imsv2.v2._proxy.Proxy
:noindex:
:members: create_image
3 changes: 2 additions & 1 deletion doc/source/sdk/proxies/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Service Proxies
VPC Endpoint (VPCEP) <vpcep>
Web Application Firewall (WAF) <waf>
Tag Management Service (TMS) <tms>
Image Management Service (IMS) <ims>
Image Management Service V1 (IMSv1) <ims_v1>
Image Management Service V2 (IMSv2) <ims_v2>

.. _service-proxies:

Expand Down
2 changes: 1 addition & 1 deletion doc/source/sdk/resources/ims/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ IMS Resources
.. toctree::
:maxdepth: 1

v1/async_job
v2/image

13 changes: 13 additions & 0 deletions doc/source/sdk/resources/ims/v1/async_job.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
otcextensions.sdk.imsv1.v1.async_job
=====================================

.. automodule:: otcextensions.sdk.imsv1.v1.async_job

The AsyncJob Class
------------------

The ``AsyncJob`` class inherits from
:class:`~otcextensions.sdk.sdk_resource.Resource`.

.. autoclass:: otcextensions.sdk.imsv1.v1.async_job.AsyncJob
:members:
6 changes: 3 additions & 3 deletions doc/source/sdk/resources/ims/v2/image.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
otcextensions.sdk.ims.v2.image
otcextensions.sdk.imsv2.v2.image
=====================================

.. automodule:: otcextensions.sdk.ims.v2.image
.. automodule:: otcextensions.sdk.imsv2.v2.image

The Image Class
---------------

The ``Image`` class inherits from
:class:`~otcextensions.sdk.sdk_resource.Resource`.

.. autoclass:: otcextensions.sdk.ims.v2.image.Image
.. autoclass:: otcextensions.sdk.imsv2.v2.image.Image
:members:
4 changes: 2 additions & 2 deletions examples/ims/create_image_from_obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
attrs = {
"name": "CentOS-7-x86_64-GenericCloud.qcow2",
"description": "Create an image from a file in an OBS bucket",
"image_url": "ims-extensions-test:CentOS-7-x86_64.qcow2",
"image_url": "imsv2-extensions-test:CentOS-7-x86_64.qcow2",
"os_version": "CentOS 7.0 64bit",
"min_disk": 40,
"image_tags": [{"key": "key2", "value": "value2"},
{"key": "key1", "value": "value1"}]
}
result = conn.ims.create_image(**attrs)
result = conn.imsv2.create_image(**attrs)
print(result)
28 changes: 28 additions & 0 deletions examples/ims/query_async_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
# 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.
"""
Query Async Job
"""

import openstack
from otcextensions import sdk

openstack.enable_logging(True)
conn = openstack.connect(cloud='otc')
sdk.register_otc_extensions(conn)
attrs = {
"project_id": "5dd3c0b24cdc4d31952c49589182a89d",
"job_id": 'ff8080828f9a78db018fe7c6e2f772b2'
}
result = conn.imsv1.get_async_job(**attrs)
print(result)
8 changes: 6 additions & 2 deletions otcextensions/sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,12 @@
'service_type': 'identity',
'replace_system': True
},
'ims': {
'service_type': 'ims',
'imsv1': {
'service_type': 'imsv1',
'endpoint_service_type': 'image',
},
'imsv2': {
'service_type': 'imsv2',
'endpoint_service_type': 'image',
},
'kms': {
Expand Down
File renamed without changes.
153 changes: 153 additions & 0 deletions otcextensions/sdk/imsv1/imsv1_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# 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 warnings

from openstack import exceptions
from openstack import service_description

from otcextensions.sdk.imsv1.v1 import _proxy as _proxy_v1


class Imsv1Service(service_description.ServiceDescription):
"""The IMS service."""

supported_versions = {
'1': _proxy_v1.Proxy,
}

def _make_proxy(self, instance):
"""Create a Proxy for the service in question.
:param instance:
The `openstack.connection.Connection` we're working with.
"""
config = instance.config
version_string = config.get_api_version('imsv1') or '1'
endpoint_override = config.get_endpoint(self.service_type)
ep = config.get_service_catalog().url_for(
service_type=self.service_type,
region_name=config.region_name)

epo = '%(base)s/v%(ver)s' % {
'base': ep,
'ver': version_string}

if epo and not endpoint_override:
endpoint_override = epo

if not version_string and len(self.supported_versions) == 1:
version_string = list(self.supported_versions)[0]

proxy_obj = None
if endpoint_override and version_string and self.supported_versions:
proxy_class = self.supported_versions.get(version_string[0])
if proxy_class:
proxy_obj = config.get_session_client(
self.service_type,
constructor=proxy_class,
)
proxy_obj.endpoint_override = endpoint_override
proxy_obj.additional_headers = {
'Content-Type': 'application/json'}
else:
warnings.warn(
"The configured version, {version} for service"
" {service_type} is not known or supported by"
" openstacksdk. The resulting Proxy object will only"
" have direct passthrough REST capabilities.".format(
version=version_string,
service_type=self.service_type),
category=exceptions.UnsupportedServiceVersion)
elif endpoint_override and self.supported_versions:
temp_adapter = config.get_session_client(
self.service_type
)
api_version = temp_adapter.get_endpoint_data().api_version
proxy_class = self.supported_versions.get(str(api_version[0]))
if proxy_class:
proxy_obj = config.get_session_client(
self.service_type,
constructor=proxy_class,
)
else:
warnings.warn(
"Service {service_type} has an endpoint override set"
" but the version discovered at that endpoint, {version}"
" is not supported by openstacksdk. The resulting Proxy"
" object will only have direct passthrough REST"
" capabilities.".format(
version=api_version,
service_type=self.service_type),
category=exceptions.UnsupportedServiceVersion)

if proxy_obj:
if getattr(proxy_obj, 'skip_discovery', False):
return proxy_obj

data = proxy_obj.get_endpoint_data()
if data.catalog_url != data.service_url:
ep_key = '{service_type}_endpoint_override'.format(
service_type=self.service_type)
config.config[ep_key] = data.service_url
proxy_obj = config.get_session_client(
self.service_type,
constructor=proxy_class,
)
return proxy_obj
version_kwargs = {}
if version_string:
version_kwargs['version'] = version_string
elif self.supported_versions:
supported_versions = sorted([
int(f) for f in self.supported_versions])
version_kwargs['min_version'] = str(supported_versions[0])
version_kwargs['max_version'] = '{version}.latest'.format(
version=str(supported_versions[-1]))

temp_adapter = config.get_session_client(
self.service_type,
allow_version_hack=True,
**version_kwargs
)
found_version = temp_adapter.get_api_major_version()
if found_version is None:
if version_kwargs:
raise exceptions.NotSupported(
"The {service_type} service for {cloud}:{region_name}"
" exists but does not have any supported versions.".format(
service_type=self.service_type,
cloud=instance.name,
region_name=instance.config.region_name))
else:
raise exceptions.NotSupported(
"The {service_type} service for {cloud}:{region_name}"
" exists but no version was discoverable.".format(
service_type=self.service_type,
cloud=instance.name,
region_name=instance.config.region_name))
proxy_class = self.supported_versions.get(str(found_version[0]))
if not proxy_class:
warnings.warn(
"Service {service_type} has no discoverable version."
" The resulting Proxy object will only have direct"
" passthrough REST capabilities.".format(
service_type=self.service_type),
category=exceptions.UnsupportedServiceVersion)
return temp_adapter
proxy_class = self.supported_versions.get(str(found_version[0]))
if proxy_class:
version_kwargs['constructor'] = proxy_class
return config.get_session_client(
self.service_type,
allow_version_hack=True,
**version_kwargs
)
File renamed without changes.
27 changes: 27 additions & 0 deletions otcextensions/sdk/imsv1/v1/_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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 proxy
from otcextensions.sdk.imsv1.v1 import async_job as _async_job


class Proxy(proxy.Proxy):
skip_discovery = True

def get_async_job(self, project_id, job_id, **attrs):
"""Get an asynchronous job
:returns: One
:class:`~otcextensions.sdk.imsv2.v1.async_job.AsyncJob`
"""
base_path = f'/{project_id}/jobs/{job_id}'
return self._get(_async_job.AsyncJob, requires_id=False,
base_path=base_path)
32 changes: 32 additions & 0 deletions otcextensions/sdk/imsv1/v1/async_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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 AsyncJob(resource.Resource):
resource_key = 'async_job'
base_path = '/jobs'

allow_fetch = True
requires_id = False

project_id = resource.Body('project_id')
job_id = resource.Body('job_id')
status = resource.Body('status')
job_type = resource.Body('job_type')
begin_time = resource.Body('begin_time')
end_time = resource.Body('end_time')
error_code = resource.Body('error_code')
fail_reason = resource.Body('fail_reason')
entities = resource.Body('entities', type=list)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
from openstack import exceptions
from openstack import service_description

from otcextensions.sdk.ims.v2 import _proxy
from otcextensions.sdk.imsv2.v2 import _proxy


class ImsService(service_description.ServiceDescription):
class Imsv2Service(service_description.ServiceDescription):
"""The IMS service."""

supported_versions = {
Expand All @@ -31,7 +31,7 @@ def _make_proxy(self, instance):
The `openstack.connection.Connection` we're working with.
"""
config = instance.config
version_string = config.get_api_version('ims') or '2'
version_string = config.get_api_version('imsv2') or '2'
endpoint_override = config.get_endpoint(self.service_type)
ep = config.get_service_catalog().url_for(
service_type=self.service_type,
Expand Down
File renamed without changes.
Loading

0 comments on commit 8fb7832

Please sign in to comment.