collection 교체

This commit is contained in:
정훈 변
2024-02-23 16:37:40 +09:00
parent b494779b5b
commit 3fd554eee9
38862 changed files with 220204 additions and 6600073 deletions

View File

@@ -21,15 +21,17 @@ def _check_argspec(self):
"""
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import re
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.ansible.utils.plugins.module_utils.common.utils import (
dict_merge,
)
from ansible.module_utils.six import iteritems
from ansible_collections.ansible.utils.plugins.module_utils.common.utils import dict_merge
try:
import yaml
@@ -104,9 +106,7 @@ class MonkeyModule(AnsibleModule):
:type msg: str
"""
if self.name:
msg = re.sub(
r"\(basic\.pyc?\)", "'{name}'".format(name=self.name), msg
)
msg = re.sub(r"\(basic\.pyc?\)", "'{name}'".format(name=self.name), msg)
self._valid = False
self._errors = msg
@@ -181,9 +181,7 @@ class AnsibleArgSpecValidator:
if metakey == "suboptions":
temp_schema[okey].update({"options": {}})
suboptions_obj = {"options": ovalue["suboptions"]}
self._extract_schema_from_doc(
suboptions_obj, temp_schema[okey]["options"]
)
self._extract_schema_from_doc(suboptions_obj, temp_schema[okey]["options"])
elif metakey in OPTION_METADATA + OPTION_CONDITIONALS:
temp_schema[okey].update({metakey: ovalue[metakey]})
@@ -214,19 +212,15 @@ class AnsibleArgSpecValidator:
self._schema = dict_merge(self._schema, self._schema_conditionals)
if self._other_args is not None:
self._schema = dict_merge(self._schema, self._other_args)
invalid_keys = [
k for k in self._schema.keys() if k not in VALID_ANSIBLEMODULE_ARGS
]
invalid_keys = [k for k in self._schema.keys() if k not in VALID_ANSIBLEMODULE_ARGS]
if invalid_keys:
valid = False
errors = "Invalid schema. Invalid keys found: {ikeys}".format(
ikeys=",".join(invalid_keys)
ikeys=",".join(invalid_keys),
)
updated_data = {}
else:
mm = MonkeyModule(
data=self._data, schema=self._schema, name=self._name
)
mm = MonkeyModule(data=self._data, schema=self._schema, name=self._name)
valid, errors, updated_data = mm.validate()
return valid, errors, updated_data
@@ -239,20 +233,14 @@ class AnsibleArgSpecValidator:
if self._schema_format == "doc":
self._convert_doc_to_schema()
if self._schema_conditionals is not None:
self._schema = dict_merge(
self._schema, self._schema_conditionals
)
invalid_keys = [
k
for k in self._schema.keys()
if k not in VALID_ANSIBLEMODULE_ARGS
]
self._schema = dict_merge(self._schema, self._schema_conditionals)
invalid_keys = [k for k in self._schema.keys() if k not in VALID_ANSIBLEMODULE_ARGS]
if invalid_keys:
valid = False
errors = [
"Invalid schema. Invalid keys found: {ikeys}".format(
ikeys=",".join(invalid_keys)
)
ikeys=",".join(invalid_keys),
),
]
updated_data = {}
return valid, errors, updated_data
@@ -269,9 +257,7 @@ class AnsibleArgSpecValidator:
return self._validate()
def check_argspec(
schema, name, schema_format="doc", schema_conditionals=None, **args
):
def check_argspec(schema, name, schema_format="doc", schema_conditionals=None, **args):
if schema_conditionals is None:
schema_conditionals = {}
@@ -287,8 +273,6 @@ def check_argspec(
if not valid:
result["errors"] = errors
result["failed"] = True
result["msg"] = "argspec validation failed for {name} plugin".format(
name=name
)
result["msg"] = "argspec validation failed for {name} plugin".format(name=name)
return valid, result, updated_params

View File

@@ -9,6 +9,7 @@ flatten a complex object to dot bracket notation
"""
from __future__ import absolute_import, division, print_function
__metaclass__ = type

View File

@@ -1,192 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
"""
The index_of plugin common code
"""
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import json
from ansible.module_utils.six import string_types, integer_types
from ansible.module_utils._text import to_native
# Note, this file can only be used on the control node
# where ansible is installed
# limit imports to filter and lookup plugins
try:
from ansible.errors import AnsibleError
except ImportError:
pass
def _raise_error(msg):
"""Raise an error message, prepend with filter name
:param msg: The message
:type msg: str
:raises: AnsibleError
"""
error = "Error when using plugin 'index_of': {msg}".format(msg=msg)
raise AnsibleError(error)
def _list_to_and_str(lyst):
"""Convert a list to a command delimited string
with the last entry being an and
:param lyst: The list to turn into a str
:type lyst: list
:return: The nicely formatted string
:rtype: str
"""
res = "{most} and {last}".format(most=", ".join(lyst[:-1]), last=lyst[-1])
return res
def _to_well_known_type(obj):
"""Convert an ansible internal type to a well-known type
ie AnsibleUnicode => str
:param obj: the obj to convert
:type obj: unknown
"""
return json.loads(json.dumps(obj))
def _run_test(entry, test, right, tests):
"""Run a test
:param test: The test to run
:type test: a lambda from the qual_map
:param entry: The x for the lambda
:type entry: str int or bool
:param right: The y for the lambda
:type right: str int bool or list
:return: If the test passed
:rtype: book
"""
msg = (
"Error encountered when testing value "
"'{entry}' (type={entry_type}) against "
"'{right}' (type={right_type}) with '{test}'. "
).format(
entry=entry,
entry_type=type(_to_well_known_type(entry)).__name__,
right=right,
right_type=type(_to_well_known_type(entry)).__name__,
test=test,
)
if test.startswith("!"):
invert = True
test = test.lstrip("!")
if test == "=":
test = "=="
elif test.startswith("not "):
invert = True
test = test.lstrip("not ")
else:
invert = False
if not isinstance(right, list) and test == "in":
right = [right]
j2_test = tests.get(test)
if not j2_test:
msg = "{msg} Error was: the test '{test}' was not found.".format(
msg=msg, test=test
)
_raise_error(msg)
else:
try:
if right is None:
result = j2_test(entry)
else:
result = j2_test(entry, right)
except Exception as exc:
msg = "{msg} Error was: {error}".format(
msg=msg, error=to_native(exc)
)
_raise_error(msg)
if invert:
result = not result
return result
def index_of(
data,
test,
value=None,
key=None,
wantlist=False,
fail_on_missing=False,
tests=None,
):
"""Find the index or indices of entries in list of objects"
:param data: The data passed in (data|index_of(...))
:type data: unknown
:param test: the test to use
:type test: jinja2 test
:param value: The value to use for the test
:type value: unknown
:param key: The key to use when a list of dicts is passed
:type key: valid key type
:param want_list: always return a list, even if 1 index
:type want_list: bool
:param fail_on_missing: Should we fail if key not found?
:type fail_on_missing: bool
:param tests: The jinja tests from the current environment
:type tests: ansible.template.JinjaPluginIntercept
"""
res = list()
if key is None:
for idx, entry in enumerate(data):
result = _run_test(entry, test, value, tests)
if result:
res.append(idx)
elif isinstance(key, (string_types, integer_types, bool)):
if not all(isinstance(entry, dict) for entry in data):
all_tipes = [
type(_to_well_known_type(entry)).__name__ for entry in data
]
msg = (
"When a key name is provided, all list entries are required to "
"be dictionaries, got {str_tipes}"
).format(str_tipes=_list_to_and_str(all_tipes))
_raise_error(msg)
errors = []
for idx, dyct in enumerate(data):
if key in dyct:
entry = dyct.get(key)
result = _run_test(entry, test, value, tests)
if result:
res.append(idx)
elif fail_on_missing:
msg = (
"'{key}' was not found in '{dyct}' at [{index}]"
).format(key=key, dyct=dyct, index=idx)
errors.append(msg)
if errors:
_raise_error(
("{errors}. fail_on_missing={fom}").format(
errors=_list_to_and_str(errors), fom=str(fail_on_missing)
)
)
else:
msg = "Unknown key type, key ({key}) was a {type}. ".format(
key=key, type=type(_to_well_known_type(key)).__name__
)
_raise_error(msg)
if len(res) == 1 and not wantlist:
return res[0]
return res

View File

@@ -9,13 +9,12 @@ flatten a complex object to dot bracket notation
"""
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import re
from ansible.module_utils.common._collections_compat import (
Mapping,
MutableMapping,
)
from ansible.module_utils.common._collections_compat import Mapping, MutableMapping
def to_paths(var, prepend, wantlist):
@@ -43,9 +42,7 @@ def to_paths(var, prepend, wantlist):
elif isinstance(data, list):
if data:
for idx, val in enumerate(data):
flatten(
val, "{name}[{idx}]".format(name=name, idx=idx), out
)
flatten(val, "{name}[{idx}]".format(name=name, idx=idx), out)
elif name:
out[name] = []
else:

View File

@@ -5,6 +5,7 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
from copy import deepcopy
@@ -21,9 +22,7 @@ def sort_list(val):
if len(set(sorted_keys)) != 1:
raise ValueError("dictionaries do not match")
return sorted(
val, key=lambda d: tuple(d[k] for k in sorted_keys[0])
)
return sorted(val, key=lambda d: tuple(d[k] for k in sorted_keys[0]))
return sorted(val)
return val