Skip to content

Commit

Permalink
always return current gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Zagulajew committed Dec 31, 2023
1 parent 15fa537 commit 8fc9074
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions plugins/module_utils/default_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ def __init__(self, module, pfsense=None):
self.root_elt = self.pfsense.get_element('gateways')
self.target_elt = self.root_elt
self.obj = dict()
self.defaultgw4 = ""
self.defaultgw6 = ""
self.result["debug"] = ""
self.interface_elt = None
self.read_only = False
Expand All @@ -57,8 +55,10 @@ def _params_to_obj(self):
my_defaultgw = self._gw2machine(params['gateway'])
if params['ipprotocol'] == "inet":
obj['defaultgw4'] = my_defaultgw
self.result["defaultgw4"] = params["gateway"]
elif params['ipprotocol'] == "inet6":
obj['defaultgw6'] = my_defaultgw
self.result["defaultgw6"] = params["gateway"]
else:
self.module.fail_json(msg='Please specify a valid ipprotocol (inet6/inet4)')

Expand All @@ -77,9 +77,9 @@ def _validate_params(self):
if elt.tag in ["gateway_group"]:
gateway_list.append(elt.find("name").text)
elif elt.tag == "defaultgw4":
self.defaultgw4 = elt.text
self.result["defaultgw4"] = self._gw2human(elt.text)
elif elt.tag == "defaultgw6":
self.defaultgw6 = elt.text
self.result["defaultgw6"] = self._gw2human(elt.text)

if params["gateway"]:
if str(params["gateway"]) not in gateway_list:
Expand All @@ -103,8 +103,8 @@ def _create_target(self):
def _gw2machine(gateway):
"""
Translates special gateway to machine-readable
"-" means None
"" means Automatic
"-" means none
"" means automatic
"""
if gateway is not None:
if gateway.lower() == "automatic":
Expand All @@ -117,8 +117,8 @@ def _gw2machine(gateway):
def _gw2human(gateway):
"""
Translates special gateway as human-readable
"-" means None
"" means Automatic
"-" means none
"" means automatic
"""
if gateway is None:
return "automatic"
Expand All @@ -144,9 +144,6 @@ def run(self, params):

if params["gateway"]:
self._add()
else:
self.result["defaultgw6"] = self._gw2human(self.defaultgw6)
self.result["defaultgw4"] = self._gw2human(self.defaultgw4)

def _update(self):
""" make the target pfsense reload """
Expand Down

0 comments on commit 8fc9074

Please sign in to comment.