mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 22:00:22 -07:00
A first pass at moving libs to new dir structure (#33727)
* A first pass at moving libs to new dir structure The network modules changed their module_utils dir structure. This first patch establishes mod utils for F5 in this new structure. Module use will be limited until things are more fleshed out * Fixing upstream errors * Fixing more issues
This commit is contained in:
parent
7b76124c07
commit
e4abb0de33
4 changed files with 75 additions and 0 deletions
0
lib/ansible/module_utils/network/f5/__init__.py
Normal file
0
lib/ansible/module_utils/network/f5/__init__.py
Normal file
0
lib/ansible/module_utils/network/f5/bigip/__init__.py
Normal file
0
lib/ansible/module_utils/network/f5/bigip/__init__.py
Normal file
28
lib/ansible/module_utils/network/f5/bigip/common.py
Normal file
28
lib/ansible/module_utils/network/f5/bigip/common.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (c) 2017 F5 Networks Inc.
|
||||||
|
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
from f5.bigip import ManagementRoot as BigipManagementRoot
|
||||||
|
from f5.bigip.contexts import TransactionContextManager as BigipTransactionContextManager
|
||||||
|
from f5.bigiq import ManagementRoot as BigiqManagementRoot
|
||||||
|
from f5.iworkflow import ManagementRoot as IworkflowManagementRoot
|
||||||
|
from icontrol.exceptions import iControlUnexpectedHTTPError
|
||||||
|
HAS_F5SDK = True
|
||||||
|
except ImportError:
|
||||||
|
HAS_F5SDK = False
|
||||||
|
|
||||||
|
|
||||||
|
def cleanup_tokens(client):
|
||||||
|
try:
|
||||||
|
resource = client.api.shared.authz.tokens_s.token.load(
|
||||||
|
name=client.api.icrs.token
|
||||||
|
)
|
||||||
|
resource.delete()
|
||||||
|
except Exception:
|
||||||
|
pass
|
47
lib/ansible/module_utils/network/f5/common.py
Normal file
47
lib/ansible/module_utils/network/f5/common.py
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (c) 2017 F5 Networks Inc.
|
||||||
|
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
from ansible.module_utils.network.common.utils import to_list, ComplexList
|
||||||
|
from ansible.module_utils.connection import exec_command
|
||||||
|
from ansible.module_utils._text import to_text
|
||||||
|
|
||||||
|
|
||||||
|
# Fully Qualified name (with the partition)
|
||||||
|
def fq_name(partition, name):
|
||||||
|
if name is not None and not name.startswith('/'):
|
||||||
|
return '/%s/%s' % (partition, name)
|
||||||
|
return name
|
||||||
|
|
||||||
|
|
||||||
|
# Fully Qualified name (with partition) for a list
|
||||||
|
def fq_list_names(partition, list_names):
|
||||||
|
if list_names is None:
|
||||||
|
return None
|
||||||
|
return map(lambda x: fq_name(partition, x), list_names)
|
||||||
|
|
||||||
|
|
||||||
|
def to_commands(module, commands):
|
||||||
|
spec = {
|
||||||
|
'command': dict(key=True),
|
||||||
|
'prompt': dict(),
|
||||||
|
'answer': dict()
|
||||||
|
}
|
||||||
|
transform = ComplexList(spec, module)
|
||||||
|
return transform(commands)
|
||||||
|
|
||||||
|
|
||||||
|
def run_commands(module, commands, check_rc=True):
|
||||||
|
responses = list()
|
||||||
|
commands = to_commands(module, to_list(commands))
|
||||||
|
for cmd in commands:
|
||||||
|
cmd = module.jsonify(cmd)
|
||||||
|
rc, out, err = exec_command(module, cmd)
|
||||||
|
if check_rc and rc != 0:
|
||||||
|
module.fail_json(msg=to_text(err, errors='surrogate_then_replace'), rc=rc)
|
||||||
|
responses.append(to_text(out, errors='surrogate_then_replace'))
|
||||||
|
return responses
|
Loading…
Add table
Add a link
Reference in a new issue