summaryrefslogtreecommitdiffstats
path: root/ansible_collections/kaytus/ksmanage/plugins/module_utils/ksmanage.py
blob: 1152f7710b89291b8ff0bacb872e99cdcb1c22c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding:utf-8 -*-
# Copyright(C) 2023 Kaytus Inc. All Rights Reserved.

from __future__ import (absolute_import, division, print_function)

__metaclass__ = type

try:
    import inmanage
    ksmanage_temp = True
except ImportError:
    ksmanage_temp = False
from ansible.module_utils.basic import env_fallback
from ansible.module_utils.six import iteritems

ksmanage_provider_spec = {
    'host': dict(type='str'),
    'username': dict(type='str', fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])),
    'password': dict(type='str', fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD']), no_log=True),
}
ksmanage_argument_spec = {
    'provider': dict(type='dict', options=ksmanage_provider_spec),
}
ksmanage_top_spec = {
    'host': dict(type='str'),
    'username': dict(type='str'),
    'password': dict(type='str', no_log=True),
}
ksmanage_argument_spec.update(ksmanage_top_spec)


def load_params(module):
    """load_params"""
    provider = module.params.get('provider') or dict()
    for key, value in iteritems(provider):
        if key in ksmanage_argument_spec:
            if module.params.get(key) is None and value is not None:
                module.params[key] = value


def get_connection(module):
    """get_connection"""
    load_params(module)
    # result = dict()
    # if module.check_mode:
    #     result['changed'] = True
    #     result['state'] = 'Success'
    #     result['message'] = module.params['subcommand']
    # else:
    dict_param = module.params
    if not ksmanage_temp:
        module.fail_json(msg='inManage must be installed to use this module')
    result = inmanage.main(dict_param)
    return result