mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-30 08:31:28 -07:00
ovirt: get default auth/connection params from environment vars (#19385)
* cloud: ovirt: add possibility specify auth params in env vars * module_utils: ovirt: fix pep8 issues
This commit is contained in:
parent
36213e8b21
commit
9a2b220005
4 changed files with 42 additions and 15 deletions
|
@ -19,6 +19,7 @@
|
|||
#
|
||||
|
||||
import inspect
|
||||
import os
|
||||
import time
|
||||
|
||||
from abc import ABCMeta, abstractmethod
|
||||
|
@ -28,7 +29,6 @@ from enum import Enum
|
|||
|
||||
try:
|
||||
import ovirtsdk4 as sdk
|
||||
import ovirtsdk4.types as otypes
|
||||
import ovirtsdk4.version as sdk_version
|
||||
HAS_SDK = LooseVersion(sdk_version.VERSION) >= LooseVersion('4.0.0')
|
||||
except ImportError:
|
||||
|
@ -126,6 +126,7 @@ def create_connection(auth):
|
|||
kerberos=auth.get('kerberos', None),
|
||||
)
|
||||
|
||||
|
||||
def convert_to_bytes(param):
|
||||
"""
|
||||
This method convert units to bytes, which follow IEC standard.
|
||||
|
@ -209,7 +210,7 @@ def search_by_attributes(service, **kwargs):
|
|||
else:
|
||||
res = [
|
||||
e for e in service.list() if len([
|
||||
k for k, v in kwargs.items() if getattr(e, k, None) == v
|
||||
k for k, v in kwargs.items() if getattr(e, k, None) == v
|
||||
]) == len(kwargs)
|
||||
]
|
||||
|
||||
|
@ -279,6 +280,32 @@ def wait(
|
|||
time.sleep(float(poll_interval))
|
||||
|
||||
|
||||
def __get_auth_dict():
|
||||
OVIRT_URL = os.environ.get('OVIRT_URL')
|
||||
OVIRT_USERNAME = os.environ.get('OVIRT_USERNAME')
|
||||
OVIRT_PASSWORD = os.environ.get('OVIRT_PASSWORD')
|
||||
OVIRT_TOKEN = os.environ.get('OVIRT_TOKEN')
|
||||
OVIRT_CAFILE = os.environ.get('OVIRT_CAFILE')
|
||||
OVIRT_INSECURE = OVIRT_CAFILE is None
|
||||
|
||||
env_vars = None
|
||||
if OVIRT_URL and ((OVIRT_USERNAME and OVIRT_PASSWORD) or OVIRT_TOKEN):
|
||||
env_vars = {
|
||||
'url': OVIRT_URL,
|
||||
'username': OVIRT_USERNAME,
|
||||
'password': OVIRT_PASSWORD,
|
||||
'insecure': OVIRT_INSECURE,
|
||||
'token': OVIRT_TOKEN,
|
||||
'ca_file': OVIRT_CAFILE,
|
||||
}
|
||||
if env_vars is not None:
|
||||
auth = dict(default=env_vars, type='dict')
|
||||
else:
|
||||
auth = dict(required=True, type='dict')
|
||||
|
||||
return auth
|
||||
|
||||
|
||||
def ovirt_facts_full_argument_spec(**kwargs):
|
||||
"""
|
||||
Extend parameters of facts module with parameters which are common to all
|
||||
|
@ -288,7 +315,7 @@ def ovirt_facts_full_argument_spec(**kwargs):
|
|||
:return: extended dictionary with common parameters
|
||||
"""
|
||||
spec = dict(
|
||||
auth=dict(required=True, type='dict'),
|
||||
auth=__get_auth_dict(),
|
||||
fetch_nested=dict(default=False, type='bool'),
|
||||
nested_attributes=dict(type='list'),
|
||||
)
|
||||
|
@ -304,7 +331,7 @@ def ovirt_full_argument_spec(**kwargs):
|
|||
:return: extended dictionary with common parameters
|
||||
"""
|
||||
spec = dict(
|
||||
auth=dict(required=True, type='dict'),
|
||||
auth=__get_auth_dict(),
|
||||
timeout=dict(default=180, type='int'),
|
||||
wait=dict(default=True, type='bool'),
|
||||
poll_interval=dict(default=3, type='int'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue