mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
retire shade in favor of openstacksdk for openstack modules (#40532)
* Establish connection through openstacksdk * Switch from shade to openstacksdk * fix typo in link to openstacksdk * remove nova_client usage * further remove of min_version from openstack modules
This commit is contained in:
parent
e16490c9c0
commit
89ce826a9f
51 changed files with 266 additions and 321 deletions
|
@ -108,44 +108,50 @@ def openstack_module_kwargs(**kwargs):
|
|||
return ret
|
||||
|
||||
|
||||
def openstack_cloud_from_module(module, min_version=None):
|
||||
def openstack_cloud_from_module(module, min_version='0.12.0'):
|
||||
from distutils.version import StrictVersion
|
||||
try:
|
||||
import shade
|
||||
# Due to the name shadowing we should import other way
|
||||
import importlib
|
||||
sdk = importlib.import_module('openstack')
|
||||
except ImportError:
|
||||
module.fail_json(msg='shade is required for this module')
|
||||
module.fail_json(msg='openstacksdk is required for this module')
|
||||
|
||||
if min_version:
|
||||
if StrictVersion(shade.__version__) < StrictVersion(min_version):
|
||||
if StrictVersion(sdk.version.__version__) < StrictVersion(min_version):
|
||||
module.fail_json(
|
||||
msg="To utilize this module, the installed version of"
|
||||
"the shade library MUST be >={min_version}".format(
|
||||
"the openstacksdk library MUST be >={min_version}".format(
|
||||
min_version=min_version))
|
||||
|
||||
cloud_config = module.params.pop('cloud', None)
|
||||
if isinstance(cloud_config, dict):
|
||||
fail_message = (
|
||||
"A cloud config dict was provided to the cloud parameter"
|
||||
" but also a value was provided for {param}. If a cloud"
|
||||
" config dict is provided, {param} should be"
|
||||
" excluded.")
|
||||
for param in (
|
||||
'auth', 'region_name', 'verify',
|
||||
'cacert', 'key', 'api_timeout', 'interface'):
|
||||
if module.params[param] is not None:
|
||||
module.fail_json(fail_message.format(param=param))
|
||||
if module.params['auth_type'] != 'password':
|
||||
module.fail_json(fail_message.format(param='auth_type'))
|
||||
return shade, shade.operator_cloud(**cloud_config)
|
||||
else:
|
||||
return shade, shade.operator_cloud(
|
||||
cloud=cloud_config,
|
||||
auth_type=module.params['auth_type'],
|
||||
auth=module.params['auth'],
|
||||
region_name=module.params['region_name'],
|
||||
verify=module.params['verify'],
|
||||
cacert=module.params['cacert'],
|
||||
key=module.params['key'],
|
||||
api_timeout=module.params['api_timeout'],
|
||||
interface=module.params['interface'],
|
||||
)
|
||||
try:
|
||||
if isinstance(cloud_config, dict):
|
||||
fail_message = (
|
||||
"A cloud config dict was provided to the cloud parameter"
|
||||
" but also a value was provided for {param}. If a cloud"
|
||||
" config dict is provided, {param} should be"
|
||||
" excluded.")
|
||||
for param in (
|
||||
'auth', 'region_name', 'verify',
|
||||
'cacert', 'key', 'api_timeout', 'interface'):
|
||||
if module.params[param] is not None:
|
||||
module.fail_json(fail_message.format(param=param))
|
||||
if module.params['auth_type'] != 'password':
|
||||
module.fail_json(fail_message.format(param='auth_type'))
|
||||
return sdk, sdk.connect(**cloud_config)
|
||||
else:
|
||||
return sdk, sdk.connect(
|
||||
cloud=cloud_config,
|
||||
auth_type=module.params['auth_type'],
|
||||
auth=module.params['auth'],
|
||||
region_name=module.params['region_name'],
|
||||
verify=module.params['verify'],
|
||||
cacert=module.params['cacert'],
|
||||
key=module.params['key'],
|
||||
api_timeout=module.params['api_timeout'],
|
||||
interface=module.params['interface'],
|
||||
)
|
||||
except sdk.exceptions.SDKException as e:
|
||||
# Probably a cloud configuration/login error
|
||||
module.fail_json(msg=str(e))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue