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 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) commands.extend(self._clear_config(dict(), 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): """ 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: # configuring non-existing interface commands.extend(self._set_config(interface, dict())) 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 = 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: for each in have: if each["name"] == interface["name"]: break else: if "." in interface["name"]: commands.extend( self._set_config(interface, dict(), module) ) 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)) # 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 :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :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 commands.extend(self._clear_config(interface, each, 'overridden')) 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, module): """ The command generator when state is overridden :param want: the desired configuration as a dictionary :param obj_in_have: the current configuration as a dictionary :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']) 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)) # 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 = [] for interface in want: if interface.get("members"): for each_interface in interface.get("members"): for each in have: if each.get("members"): for every in each.get("members"): match = False if every["member"] == each_interface["member"]: match = True break commands.extend( self._clear_config(interface, each) ) continue if match: have_dict = self.filter_dict_having_none_value( interface, each ) commands.extend( self._clear_config(dict(), have_dict) ) commands.extend( self._set_config(interface, each, module) ) elif each.get("name") == each_interface["member"]: have_dict = self.filter_dict_having_none_value( interface, each ) commands.extend( self._clear_config(dict(), have_dict) ) commands.extend( self._set_config(interface, each, module) ) break # 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 :param want: the desired configuration as a dictionary :param obj_in_have: the current configuration as a dictionary :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: count = 0 if each['name'] == interface['name']: break elif interface['name'] in each['name']: break count += 1 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) commands.extend(self._clear_config(dict(), have_dict)) commands.extend(self._set_config(interface, each)) # as the pre-existing interface are now configured by # above set_config call, deleting the respective # interface entry from the want list del want[count] # Iterating through want list which now only have new interfaces to be # configured for each in want: commands.extend(self._set_config(each, dict())) # 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 :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :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 else: continue commands.extend(self._clear_config(interface, each, "replaced")) commands.extend(self._set_config(interface, each)) # Remove the duplicate interface call commands = remove_duplicate_interface(commands) return commands