예제 #1
0
파일: lm.py 프로젝트: schijioke-uche/openr
    def toggle_link_overload_bit(
        self,
        client: OpenrCtrl.Client,
        overload: bool,
        interface: str,
        yes: bool = False,
    ) -> None:
        links = client.getInterfaces()
        print()

        if interface not in links.interfaceDetails:
            print("No such interface: {}".format(interface))
            return

        if overload and links.interfaceDetails[interface].isOverloaded:
            print("Interface is already overloaded.\n")
            sys.exit(0)

        if not overload and not links.interfaceDetails[interface].isOverloaded:
            print("Interface is not overloaded.\n")
            sys.exit(0)

        action = "set overload bit" if overload else "unset overload bit"
        question_str = "Are you sure to {} for interface {} ?"
        if not utils.yesno(question_str.format(action, interface), yes):
            print()
            return

        if overload:
            client.setInterfaceOverload(interface)
        else:
            client.unsetInterfaceOverload(interface)

        print("Successfully {} for the interface.\n".format(action))
예제 #2
0
파일: lm.py 프로젝트: schijioke-uche/openr
    def toggle_node_overload_bit(
        self, client: OpenrCtrl.Client, overload: bool, yes: bool = False
    ) -> None:
        links = client.getInterfaces()
        host = links.thisNodeName
        print()

        if overload and links.isOverloaded:
            print("Node {} is already overloaded.\n".format(host))
            sys.exit(0)

        if not overload and not links.isOverloaded:
            print("Node {} is not overloaded.\n".format(host))
            sys.exit(0)

        action = "set overload bit" if overload else "unset overload bit"
        if not utils.yesno(
            "Are you sure to {} for node {} ?".format(action, host), yes
        ):
            print()
            return

        if overload:
            client.setNodeOverload()
        else:
            client.unsetNodeOverload()

        print("Successfully {}..\n".format(action))
예제 #3
0
 def _run(self, client: OpenrCtrl.Client, only_suppressed: bool, json: bool) -> None:
     links = client.getInterfaces()
     if only_suppressed:
         links.interfaceDetails = {
             k: v for k, v in links.interfaceDetails.items() if v.linkFlapBackOffMs
         }
     if json:
         self.print_links_json(links)
     else:
         if self.enable_color:
             overload_color = "red" if links.isOverloaded else "green"
             overload_status = click.style(
                 "{}".format("YES" if links.isOverloaded else "NO"),
                 fg=overload_color,
             )
             caption = "Node Overload: {}".format(overload_status)
             self.print_links_table(
                 links.interfaceDetails, caption, self.enable_color
             )
         else:
             caption = "Node Overload: {}".format(
                 "YES" if links.isOverloaded else "NO"
             )
             self.print_links_table(
                 links.interfaceDetails, caption, self.enable_color
             )
예제 #4
0
파일: lm.py 프로젝트: schijioke-uche/openr
    def toggle_link_metric(
        self,
        client: OpenrCtrl.Client,
        override: bool,
        interface: str,
        metric: int,
        yes: bool,
    ) -> None:
        links = client.getInterfaces()
        print()

        if interface not in links.interfaceDetails:
            print("No such interface: {}".format(interface))
            return

        status = self.check_link_overriden(links, interface, metric)
        if not override and status is None:
            print("Interface hasn't been assigned metric override.\n")
            sys.exit(0)

        if override and status:
            print(
                "Interface: {} has already been set with metric: {}.\n".format(
                    interface, metric
                )
            )
            sys.exit(0)

        action = "set override metric" if override else "unset override metric"
        question_str = "Are you sure to {} for interface {} ?"
        if not utils.yesno(question_str.format(action, interface), yes):
            print()
            return

        if override:
            client.setInterfaceMetric(interface, metric)
        else:
            client.unsetInterfaceMetric(interface)

        print("Successfully {} for the interface.\n".format(action))