def _state_replaced(self, want, have): """ The command generator when state is replaced :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :param interface_type: interface type :rtype: A list :returns: the commands necessary to migrate the current configuration to the deisred 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
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 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']) commands.extend(self._clear_config(interface, each)) 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)) # Remove the duplicate interface call commands = commands return commands
def _state_replaced(self, want, have): """ The command generator when state is replaced :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :param interface_type: interface type :rtype: A list :returns: the commands necessary to migrate the current configuration to the deisred configuration """ commands = [] have_dict = filter_dict_having_none_value(want, have) commands.extend(self._clear_config(have_dict)) commands.extend(self._set_config(want, have)) 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: for each in have: if each['name'] == interface['name']: break have_dict = filter_dict_having_none_value(interface, each) #commands.extend(self._clear_config(dict(), have_dict)) commands.extend(self._clear_config(interface, each)) commands.extend(self._set_config(interface, each, module)) return commands