Skip to content

Commit dd656f9

Browse files
author
rsmekala
committed
convert_to_bool_func has been replaced with ansible.module_utils.basic.boolean
1 parent 6b0c39b commit dd656f9

File tree

2 files changed

+5
-48
lines changed

2 files changed

+5
-48
lines changed

action_plugins/juniper_junos_common_action.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
from __future__ import absolute_import, division, print_function
3535
from ansible.plugins.action.network import ActionModule as ActionNetworkModule
36-
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
36+
from ansible.module_utils.basic import boolean as ansible_vars_convert_to_boolean
3737
import os
3838

3939
try:
@@ -52,28 +52,7 @@
5252
'ansible_private_key_file']
5353
}
5454

55-
56-
def convert_to_bool_func(arg):
57-
"""Try converting arg to a bool value using Ansible's aliases for bool.
58-
59-
Args:
60-
arg: The value to convert.
61-
62-
Returns:
63-
A boolean value if successfully converted, or None if not.
64-
"""
65-
if arg is None or type(arg) == bool:
66-
return arg
67-
if isinstance(arg, basestring):
68-
arg = arg.lower()
69-
if arg in BOOLEANS_TRUE:
70-
return True
71-
elif arg in BOOLEANS_FALSE:
72-
return False
73-
else:
74-
return None
75-
76-
55+
# Moved the defintion
7756
class ActionModule(ActionNetworkModule):
7857
"""A subclass of ActionNormal used by all juniper_junos_* modules.
7958
@@ -151,4 +130,4 @@ def convert_to_bool(self, arg):
151130
Returns:
152131
A boolean value if successfully converted, or None if not.
153132
"""
154-
return convert_to_bool_func(arg)
133+
return ansible_vars_convert_to_boolean(arg)

module_utils/juniper_junos_common.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535

3636
# Ansible imports
3737
from ansible.module_utils.basic import AnsibleModule
38-
from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE
39-
38+
from ansible.module_utils.basic import boolean as ansible_vars_convert_to_boolean
4039
from ansible.module_utils._text import to_bytes
4140

4241
# Standard library imports
@@ -588,27 +587,6 @@ class ModuleDocFragment(object):
588587
CONFIG_MODEL_CHOICES = ['openconfig', 'custom', 'ietf', 'True']
589588

590589

591-
def convert_to_bool_func(arg):
592-
"""Try converting arg to a bool value using Ansible's aliases for bool.
593-
594-
Args:
595-
arg: The value to convert.
596-
597-
Returns:
598-
A boolean value if successfully converted, or None if not.
599-
"""
600-
if arg is None or type(arg) == bool:
601-
return arg
602-
if isinstance(arg, basestring):
603-
arg = arg.lower()
604-
if arg in BOOLEANS_TRUE:
605-
return True
606-
elif arg in BOOLEANS_FALSE:
607-
return False
608-
else:
609-
return None
610-
611-
612590
class JuniperJunosModule(AnsibleModule):
613591
"""A subclass of AnsibleModule used by all juniper_junos_* modules.
614592
@@ -1127,7 +1105,7 @@ def convert_to_bool(self, arg):
11271105
Returns:
11281106
A boolean value if successfully converted, or None if not.
11291107
"""
1130-
return convert_to_bool_func(arg)
1108+
return ansible_vars_convert_to_boolean(arg)
11311109

11321110
def parse_arg_to_list_of_dicts(self,
11331111
option_name,

0 commit comments

Comments
 (0)