-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
439 ims jobs querying Reviewed-by: Anton Sidelnikov
- Loading branch information
1 parent
28023d8
commit 8fb7832
Showing
37 changed files
with
442 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ IMS Resources | |
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
v1/async_job | ||
v2/image | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.