Ejemplo n.º 1
0
    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 = remove_duplicate_interface(commands)
        return commands
Ejemplo n.º 2
0
 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 self.is_in_ports(interface["name"], 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"])
             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(interface, have_dict))
         commands.extend(self._set_config(interface, each, module))
     # Remove the duplicate interface call
     commands = remove_duplicate_interface(commands)
     return commands
Ejemplo n.º 3
0
    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 = []
        tmp_remove_cmds = dict()
        exists_dict = dict()

        for interface in want:
            for each_interface in interface.get("members"):
                exists = False
                for each in have:
                    if each.get("members"):
                        for every in each.get("members"):
                            match = False
                            if every["member"] == each_interface["member"]:
                                exists_dict[each_interface["member"]] = True
                                match = True
                                break
                            else:
                                tmp_remove_cmds[
                                    every["member"]] = self._clear_config(
                                        interface, each)
                                continue
                        if match:
                            # have_dict = filter_dict_having_none_value(interface, each)
                            if each.get("name") != interface.get("name"):
                                commands.extend(
                                    self._clear_config(dict(), each))
                                commands.extend(
                                    self._set_config(interface, each, module))
                    elif each.get("name") == each_interface["member"]:
                        exists_dict[each_interface["member"]] = True
                        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))
                        break

        for port, cmd in tmp_remove_cmds.items():
            try:
                status = exists_dict[port]
                if not status:
                    commands.extend(cmd)
            except Exception:
                commands.extend(cmd)

        # Remove the duplicate interface call
        commands = remove_duplicate_interface(commands)
        return commands
Ejemplo n.º 4
0
    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 = []

        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
Ejemplo n.º 5
0
    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
            else:
                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
Ejemplo n.º 6
0
    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_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
                            else:
                                continue
                        if match:
                            # have_dict = filter_dict_having_none_value(
                            #     interface, each)
                            if each.get("name") != interface.get("name"):
                                commands.extend(
                                    self._clear_config(dict(), each))
                                commands.extend(
                                    self._set_config(interface, each, module))
                    elif each.get("name") == each_interface["member"]:
                        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))
                        break
        # Remove the duplicate interface call
        commands = remove_duplicate_interface(commands)

        return commands