mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-08 05:52:37 +00:00
Refactor k8s_cluster_info to use new module_utils code (#325)
Refactor k8s_cluster_info to use new module_utils code SUMMARY Refactor k8s_cluster_info to use new module_utils code ISSUE TYPE COMPONENT NAME k8s_cluster_info ADDITIONAL INFORMATION Reviewed-by: Alina Buzachis <None> Reviewed-by: None <None>
This commit is contained in:
@@ -141,36 +141,29 @@ apis:
|
|||||||
|
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import traceback
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
HAS_K8S = False
|
|
||||||
try:
|
try:
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.client.resource import (
|
from ansible_collections.kubernetes.core.plugins.module_utils.client.resource import (
|
||||||
ResourceList,
|
ResourceList,
|
||||||
)
|
)
|
||||||
|
except ImportError:
|
||||||
|
# Handled during module setup
|
||||||
|
pass
|
||||||
|
|
||||||
HAS_K8S = True
|
|
||||||
except ImportError as e:
|
|
||||||
K8S_IMP_ERR = e
|
|
||||||
K8S_IMP_EXC = traceback.format_exc()
|
|
||||||
|
|
||||||
from ansible.module_utils._text import to_native
|
|
||||||
from ansible.module_utils.basic import missing_required_lib
|
|
||||||
from ansible.module_utils.parsing.convert_bool import boolean
|
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import (
|
from ansible_collections.kubernetes.core.plugins.module_utils.ansiblemodule import (
|
||||||
AnsibleModule,
|
AnsibleModule,
|
||||||
)
|
)
|
||||||
|
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.core import (
|
||||||
|
AnsibleK8SModule,
|
||||||
|
)
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
|
||||||
AUTH_ARG_SPEC,
|
AUTH_ARG_SPEC,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def execute_module(module, client):
|
def execute_module(module, client):
|
||||||
invalidate_cache = boolean(
|
if module.params.get("invalidate_cache"):
|
||||||
module.params.get("invalidate_cache", True), strict=False
|
|
||||||
)
|
|
||||||
if invalidate_cache:
|
|
||||||
client.resources.invalidate_cache()
|
client.resources.invalidate_cache()
|
||||||
results = defaultdict(dict)
|
results = defaultdict(dict)
|
||||||
for resource in list(client.resources):
|
for resource in list(client.resources):
|
||||||
@@ -204,7 +197,7 @@ def execute_module(module, client):
|
|||||||
|
|
||||||
version_info = {
|
version_info = {
|
||||||
"client": version,
|
"client": version,
|
||||||
"server": client.version,
|
"server": client.client.version,
|
||||||
}
|
}
|
||||||
module.exit_json(
|
module.exit_json(
|
||||||
changed=False, apis=results, connection=connection, version=version_info
|
changed=False, apis=results, connection=connection, version=version_info
|
||||||
@@ -218,14 +211,11 @@ def argspec():
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(argument_spec=argspec(), supports_check_mode=True)
|
module = AnsibleK8SModule(
|
||||||
if not HAS_K8S:
|
module_class=AnsibleModule, argument_spec=argspec(), supports_check_mode=True
|
||||||
module.fail_json(
|
)
|
||||||
msg=missing_required_lib("kubernetes"),
|
|
||||||
exception=K8S_IMP_EXC,
|
from ansible_collections.kubernetes.core.plugins.module_utils.k8s.client import (
|
||||||
error=to_native(K8S_IMP_ERR),
|
|
||||||
)
|
|
||||||
from ansible_collections.kubernetes.core.plugins.module_utils.common import (
|
|
||||||
get_api_client,
|
get_api_client,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user