def _state_overridden(self, want, have): """ The command generator when state is overridden :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ commands = [] for each in have: for interface in want: if each['name'] == interface['name']: break elif interface['name'] in each['name']: break else: # We didn't find a matching desired state, which means we can # pretend we received an empty desired state. interface = dict(name=each['name']) commands.extend(self._clear_config(interface, each)) continue have_dict = filter_dict_having_none_value(interface, each) want = dict() commands.extend(self._clear_config(want, have_dict)) commands.extend(self._set_config(interface, each)) # Remove the duplicate interface call commands = remove_duplicate_interface(commands) return commands
def _state_replaced(self, want, have, module): """ The command generator when state is replaced :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ commands = [] for interface in want: interface["name"] = normalize_interface(interface["name"]) for each in have: if ( each["name"] == interface["name"] or interface["name"] in each["name"] ): break else: commands.extend(self._set_config(interface, {}, module)) continue interface = remove_empties(interface) have_dict = filter_dict_having_none_value(interface, each) commands.extend(self._clear_config(dict(), have_dict)) commands.extend(self._set_config(interface, each, module)) # Remove the duplicate interface call commands = remove_duplicate_interface(commands) return commands
def _state_overridden(self, want, have, module): """ The command generator when state is overridden :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ commands = [] not_in_have = set() in_have = set() for each in have: for interface in want: interface['name'] = normalize_interface(interface['name']) if each['name'] == interface['name']: in_have.add(interface['name']) break elif interface['name'] != each['name']: not_in_have.add(interface['name']) else: # We didn't find a matching desired state, which means we can # pretend we recieved an empty desired state. interface = dict(name=each['name']) kwargs = {'want': interface, 'have': each} commands.extend(self._clear_config(**kwargs)) continue have_dict = filter_dict_having_none_value(interface, each) commands.extend(self._clear_config(dict(), have_dict)) commands.extend(self._set_config(interface, each, module)) # Add the want interface that's not already configured in have interface for each in (not_in_have - in_have): for every in want: interface = 'interface {0}'.format(every['name']) if each and interface not in commands: commands.extend(self._set_config(every, {}, module)) # Remove the duplicate interface call commands = remove_duplicate_interface(commands) return commands
def _state_replaced(self, want, have): """ The command generator when state is replaced :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ commands = [] for interface in want: for each in have: if each['name'] == interface['name']: break elif interface['name'] in each['name']: break else: continue have_dict = filter_dict_having_none_value(interface, each) want = dict() commands.extend(self._clear_config(want, have_dict)) commands.extend(self._set_config(interface, each)) # Remove the duplicate interface call commands = remove_duplicate_interface(commands) return commands