mirror of
https://github.com/linux-system-roles/network.git
synced 2026-01-23 02:15:17 +00:00
network_state: improve state comparison for achieving idempotency
`libnmstate.show()` would include the info like bridge timer etc which should not be considered when comparing between the previous state and current state. Instead, using the the `libnmstate.show_running_config()` which would filter out these kind of data. Signed-off-by: Wen Liang <liangwen12year@gmail.com>
This commit is contained in:
parent
26c742d7e3
commit
3a591aa3d7
1 changed files with 11 additions and 2 deletions
|
|
@ -39,12 +39,12 @@ class NetworkState:
|
|||
self.params = module.params
|
||||
self.result = dict(changed=False)
|
||||
self.module_name = module_name
|
||||
self.previous_state = libnmstate.show()
|
||||
self.previous_state = self.get_state_config()
|
||||
|
||||
def run(self):
|
||||
desired_state = self.params["desired_state"]
|
||||
libnmstate.apply(desired_state)
|
||||
current_state = libnmstate.show()
|
||||
current_state = self.get_state_config()
|
||||
if current_state != self.previous_state:
|
||||
self.result["changed"] = True
|
||||
|
||||
|
|
@ -52,6 +52,15 @@ class NetworkState:
|
|||
|
||||
self.module.exit_json(**self.result)
|
||||
|
||||
def get_state_config(self):
|
||||
if hasattr(libnmstate, "show_running_config") and callable(
|
||||
getattr(libnmstate, "show_running_config")
|
||||
):
|
||||
state_config = libnmstate.show_running_config()
|
||||
else:
|
||||
state_config = libnmstate.show()
|
||||
return state_config
|
||||
|
||||
|
||||
def run_module():
|
||||
module_args = dict(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue