From f58fa752af50de9d1ac5475534303fd88da403ca Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 18 Jan 2018 09:34:43 +0100 Subject: [PATCH] library: move connection_modified_earlier() from AnsibleUtil to Cmd class --- library/network_connections.py | 72 +++++++++++++++++----------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/library/network_connections.py b/library/network_connections.py index d0c3671..8ec3b20 100755 --- a/library/network_connections.py +++ b/library/network_connections.py @@ -2025,40 +2025,6 @@ class _AnsibleUtil(RunEnvironment): self._connections = c return c - def connection_modified_earlier(self, idx): - # for index @idx, check if any of the previous profiles [0..idx[ - # modify the connection. - - con = self.connections[idx] - assert(con['state'] in ['up', 'down']) - - # also check, if the current profile is 'up' with a 'type' (which - # possibly modifies the connection as well) - if con['state'] == 'up' \ - and 'type' in con \ - and self.run_results[idx]['changed']: - return True - - for i in reversed(range(idx)): - c = self.connections[i] - if 'name' not in c: - continue - if c['name'] != con['name']: - continue - - c_state = c['state'] - if c_state == 'up' and 'type' not in c: - pass - elif c_state == 'down': - return True - elif c_state == 'absent': - return True - elif c_state in ['present', 'up']: - if self.run_results[i]['changed']: - return True - - return False - @property def run_results(self): c = self._run_results @@ -2178,6 +2144,40 @@ class Cmd: return Cmd_initscripts(**kwargs) raise MyError('unsupported provider %s' % (provider)) + def connection_modified_earlier(self, idx): + # for index @idx, check if any of the previous profiles [0..idx[ + # modify the connection. + + con = AnsibleUtil.connections[idx] + assert(con['state'] in ['up', 'down']) + + # also check, if the current profile is 'up' with a 'type' (which + # possibly modifies the connection as well) + if con['state'] == 'up' \ + and 'type' in con \ + and AnsibleUtil.run_results[idx]['changed']: + return True + + for i in reversed(range(idx)): + c = AnsibleUtil.connections[i] + if 'name' not in c: + continue + if c['name'] != con['name']: + continue + + c_state = c['state'] + if c_state == 'up' and 'type' not in c: + pass + elif c_state == 'down': + return True + elif c_state == 'absent': + return True + elif c_state in ['present', 'up']: + if AnsibleUtil.run_results[i]['changed']: + return True + + return False + @property def check_mode(self): return self._check_mode @@ -2390,7 +2390,7 @@ class Cmd_nm(Cmd): return is_active = self.nmutil.connection_is_active(con) - is_modified = AnsibleUtil.connection_modified_earlier(idx) + is_modified = self.connection_modified_earlier(idx) force_state_change = AnsibleUtil.params_force_state_change(connection, False) if is_active and not force_state_change and not is_modified: @@ -2562,7 +2562,7 @@ class Cmd_initscripts(Cmd): return is_active = IfcfgUtil.connection_seems_active(name) - is_modified = AnsibleUtil.connection_modified_earlier(idx) + is_modified = self.connection_modified_earlier(idx) force_state_change = AnsibleUtil.params_force_state_change(connection, False) if do_up: