Beispiel #1
0
 def _add_next_hop(self, want, have, opr=True):
     """
     This function gets the diff for next hop specific attributes
     and form the commands to add attributes which are present in want but not in have.
     :param want:
     :param have:
     :return: list of commands.
     """
     commands = []
     want_copy = deepcopy(remove_empties(want))
     have_copy = deepcopy(remove_empties(have))
     if not opr:
         diff_next_hops = get_lst_same_for_dicts(want_copy, have_copy,
                                                 "next_hops")
     else:
         diff_next_hops = get_lst_diff_for_dicts(want_copy, have_copy,
                                                 "next_hops")
     if diff_next_hops:
         for hop in diff_next_hops:
             for element in hop:
                 if element == "forward_router_address":
                     commands.append(
                         self._compute_command(
                             dest=want["dest"],
                             key="next-hop",
                             value=hop[element],
                             opr=opr,
                         ))
                 elif element == "enabled" and not hop[element]:
                     commands.append(
                         self._compute_command(
                             dest=want["dest"],
                             key="next-hop",
                             attrib=hop["forward_router_address"],
                             value="disable",
                             opr=opr,
                         ))
                 elif element == "admin_distance":
                     commands.append(
                         self._compute_command(
                             dest=want["dest"],
                             key="next-hop",
                             attrib=hop["forward_router_address"] + " " +
                             "distance",
                             value=str(hop[element]),
                             opr=opr,
                         ))
                 elif element == "interface":
                     commands.append(
                         self._compute_command(
                             dest=want["dest"],
                             key="next-hop",
                             attrib=hop["forward_router_address"] + " " +
                             "next-hop-interface",
                             value=hop[element],
                             opr=opr,
                         ))
     return commands
Beispiel #2
0
 def _add_bond_members(self, want, have):
     commands = []
     diff_members = get_lst_diff_for_dicts(want, have, 'members')
     if diff_members:
         for key in diff_members:
             commands.append(
                 self._compute_command(key['member'], 'bond-group', want['name'], type='ethernet')
             )
     return commands
Beispiel #3
0
    def _update_next_hop(self, want, have, opr=True):
        """
        This function gets the difference for next_hops list and
        form the commands to delete the attributes which are present in have but not in want.
        :param want:
        :param have:
        :return: list of commands
        """
        commands = []

        want_copy = deepcopy(remove_empties(want))
        have_copy = deepcopy(remove_empties(have))

        diff_next_hops = get_lst_diff_for_dicts(have_copy, want_copy,
                                                "next_hops")
        if diff_next_hops:
            for hop in diff_next_hops:
                for element in hop:
                    if element == "forward_router_address":
                        commands.append(
                            self._compute_command(
                                dest=want["dest"],
                                key="next-hop",
                                value=hop[element],
                                remove=True,
                            ))
                    elif element == "enabled":
                        commands.append(
                            self._compute_command(
                                dest=want["dest"],
                                key="next-hop",
                                attrib=hop["forward_router_address"],
                                value="disable",
                                remove=True,
                            ))
                    elif element == "admin_distance":
                        commands.append(
                            self._compute_command(
                                dest=want["dest"],
                                key="next-hop",
                                attrib=hop["forward_router_address"] + " " +
                                "distance",
                                value=str(hop[element]),
                                remove=True,
                            ))
                    elif element == "interface":
                        commands.append(
                            self._compute_command(
                                dest=want["dest"],
                                key="next-hop",
                                attrib=hop["forward_router_address"] + " " +
                                "next-hop-interface",
                                value=hop[element],
                                remove=True,
                            ))
        return commands
 def _add_bond_members(self, want, have):
     commands = []
     diff_members = get_lst_diff_for_dicts(want, have, "members")
     if diff_members:
         for key in diff_members:
             commands.append(
                 self._compute_command(
                     key["member"],
                     "bond-group",
                     want["name"],
                     type="ethernet",
                 ))
     return commands
Beispiel #5
0
 def _add_next_hop(self, want, have, opr=True):
     """
     This function gets the diff for next hop specific attributes
     and form the commands to add attributes which are present in want but not in have.
     :param want:
     :param have:
     :return: list of commands.
     """
     commands = []
     want_copy = deepcopy(remove_empties(want))
     have_copy = deepcopy(remove_empties(have))
     if not opr:
         diff_next_hops = get_lst_same_for_dicts(want_copy, have_copy, 'next_hops')
     else:
         diff_next_hops = get_lst_diff_for_dicts(want_copy, have_copy, 'next_hops')
     if diff_next_hops:
         for hop in diff_next_hops:
             for element in hop:
                 if element == 'forward_router_address':
                     commands.append(
                         self._compute_command(dest=want['dest'],
                                               key='next-hop',
                                               value=hop[element],
                                               opr=opr)
                     )
                 elif element == 'enabled' and not hop[element]:
                     commands.append(
                         self._compute_command(dest=want['dest'],
                                               key='next-hop',
                                               attrib=hop['forward_router_address'],
                                               value='disable',
                                               opr=opr)
                     )
                 elif element == 'admin_distance':
                     commands.append(
                         self._compute_command(dest=want['dest'],
                                               key='next-hop',
                                               attrib=hop['forward_router_address'] + " " + element,
                                               value=str(hop[element]),
                                               opr=opr)
                     )
                 elif element == 'interface':
                     commands.append(
                         self._compute_command(dest=want['dest'],
                                               key='next-hop',
                                               attrib=hop['forward_router_address'] + " " + element,
                                               value=hop[element],
                                               opr=opr)
                     )
     return commands
Beispiel #6
0
    def _update_next_hop(self, want, have, opr=True):
        """
        This function gets the difference for next_hops list and
        form the commands to delete the attributes which are present in have but not in want.
        :param want:
        :param have:
        :return: list of commands
        """
        commands = []

        want_copy = deepcopy(remove_empties(want))
        have_copy = deepcopy(remove_empties(have))

        diff_next_hops = get_lst_diff_for_dicts(have_copy, want_copy, 'next_hops')
        if diff_next_hops:
            for hop in diff_next_hops:
                for element in hop:
                    if element == 'forward_router_address':
                        commands.append(
                            self._compute_command(dest=want['dest'], key='next-hop', value=hop[element], remove=True)
                        )
                    elif element == 'enabled':
                        commands.append(
                            self._compute_command(dest=want['dest'],
                                                  key='next-hop', attrib=hop['forward_router_address'], value='disable', remove=True)
                        )
                    elif element == 'admin_distance':
                        commands.append(
                            self._compute_command(dest=want['dest'], key='next-hop',
                                                  attrib=hop['forward_router_address'] + " " + element, value=str(hop[element]), remove=True)
                        )
                    elif element == 'interface':
                        commands.append(
                            self._compute_command(dest=want['dest'], key='next-hop',
                                                  attrib=hop['forward_router_address'] + " " + element, value=hop[element], remove=True)
                        )
        return commands
Beispiel #7
0
 def _add_lldp_protocols(self, want, have):
     commands = []
     diff_members = get_lst_diff_for_dicts(want, have, "legacy_protocols")
     for key in diff_members:
         commands.append(self._compute_command("legacy-protocols", key))
     return commands