Exemple #1
0
def set_unset_link_metric(client, override, interface, metric, yes):
    """
    Set/Unset metric override for the specific link. This can be used to
    emulate soft drains.
    """

    links = client.dump_links()
    print()

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

    def intf_override(links, interface):
        if interface in links.interfaceDetails:
            return links.interfaceDetails[interface].metricOverride
        return None

    if not override and not intf_override(links, interface):
        print("Interface hasn't been assigned metric override.\n")
        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

    links = client.set_unset_link_metric(override, interface, metric)

    # Verify post command action
    if override == (intf_override(links, interface) is not None):
        print("Successfully {} for the interface.\n".format(action))
    else:
        print("Failed to {} for the interface.\n".format(action))
Exemple #2
0
def set_unset_overload(client, overload, yes):
    """
    Set/Unset overload bit for the node. Setting overload bit will take
    away all transit traffic going through node while node will still
    remains to be reachable.
    """

    links = client.dump_links()
    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

    links = client.set_unset_overload(overload)

    # Verify post command action
    if overload == links.isOverloaded:
        print("Successfully {}..\n".format(action))
    else:
        print("Failed to {}.\n".format(action))
Exemple #3
0
def set_unset_link_overload(client, overload, interface, yes):
    """
    Set/Unset link overload. All transit traffic on this link will be drained.
    Equivalent to hard draining the link
    """

    links = client.dump_links()
    print()

    def intf_is_overloaded(links, interface):
        if interface in links.interfaceDetails:
            return links.interfaceDetails[interface].isOverloaded
        return False

    if overload and intf_is_overloaded(links, interface):
        print("Interface is already overloaded.\n")
        sys.exit(0)

    if not overload and not intf_is_overloaded(links, interface):
        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

    links = client.set_unset_link_overload(overload, interface)

    if overload == intf_is_overloaded(links, interface):
        print("Successfully {} for the interface.\n".format(action))
    else:
        print("Failed to {} for the interface.\n".format(action))
Exemple #4
0
    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))
Exemple #5
0
    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))
Exemple #6
0
def set_unset_link_metric(client, override, interface, metric):
    '''
    Set/Unset metric override for the specific link. This can be used to
    emulate soft drains.
    '''

    links = client.dump_links()
    print()

    def intf_override(links, interface):
        if interface in links.interfaceDetails:
            return links.interfaceDetails[interface].metricOverride
        return None

    if not override and not intf_override(links, interface):
        print('Interface hasn\'t been assigned metric override.\n')
        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)):
        print()
        return

    links = client.set_unset_link_metric(override, interface, metric)

    # Verify post command action
    if override == (intf_override(links, interface) is not None):
        print('Successfully {} for the interface.\n'.format(action))
    else:
        print('Failed to {} for the interface.\n'.format(action))
Exemple #7
0
    def _run(self, client: OpenrCtrl.Client, yes: bool = False) -> None:
        question_str = "Are you sure to force sending GR msg to neighbors?"
        if not utils.yesno(question_str, yes):
            print()
            return

        client.floodRestartingMsg()
        print("Successfully forcing to send GR msgs.\n")
Exemple #8
0
    def unset_adj_metric(cli_opts, node, interface, yes):  # noqa: B902
        """
        Unset previously set custom metric value on the node.
        """
        question_str = "Are you sure to unset metric " "for adjacency {} {} ?".format(
            node, interface)
        if not utils.yesno(question_str, yes):
            return

        lm.UnsetAdjMetricCmd(cli_opts).run(node, interface, yes)
        nodes = parse_nodes(cli_opts, "")
        kvstore.ShowAdjNodeCmd(cli_opts).run(nodes, node, interface)
Exemple #9
0
    def set_adj_metric(cli_opts, node, interface, metric, yes):  # noqa: B902
        """
        Set custom metric value for the adjacency
        """
        question_str = "Are you sure to override metric for adjacency {} {} ?".format(
            node, interface)
        if not utils.yesno(question_str, yes):
            return

        lm.SetAdjMetricCmd(cli_opts).run(node, interface, metric, yes)
        nodes = parse_nodes(cli_opts, "")
        kvstore.ShowAdjNodeCmd(cli_opts).run(nodes, node, interface)
Exemple #10
0
    def unset_adj_metric(cli_opts, node, interface, yes):  # noqa: B902
        '''
        Unset previously set custom metric value on the node.
        '''
        question_str = 'Are you sure to unset metric ' \
                       'for adjacency {} {} ?'.format(node, interface)
        if not utils.yesno(question_str, yes):
            return

        lm.UnsetAdjMetricCmd(cli_opts).run(node, interface, yes)
        nodes = parse_nodes(cli_opts.host, '', cli_opts.lm_cmd_port)
        kvstore.ShowAdjNodeCmd(cli_opts).run(nodes, node, interface)
Exemple #11
0
    def set_adj_metric(cli_opts, node, interface, metric, yes):  # noqa: B902
        '''
        Set custom metric value for the adjacency
        '''
        question_str = 'Are you sure to override metric '\
                       'for adjacency {} {} ?'.format(node, interface)
        if not utils.yesno(question_str, yes):
            return

        lm.SetAdjMetricCmd(cli_opts).run(node, interface, metric, yes)
        nodes = parse_nodes(cli_opts.host, '', cli_opts.lm_cmd_port)
        kvstore.ShowAdjNodeCmd(cli_opts).run(nodes, node, interface)
Exemple #12
0
    def run(self, yes):

        if not yes:
            yes = utils.yesno("Are you sure to trigger Open/R crash")

        if not yes:
            print("Not triggering force crash")
            return

        print("Triggering force crash")
        sock = socket.Socket(self.cli_opts.zmq_ctx, zmq.REQ, timeout=200)
        sock.set_sock_opt(zmq.LINGER, 1000)
        sock.connect(consts.Consts.FORCE_CRASH_SERVER_URL)
        sock.send("User {} issuing crash command".format(os.environ["USER"]))
        sock.close()
Exemple #13
0
    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))
Exemple #14
0
def set_unset_link_overload(client, overload, interface, yes):
    '''
    Set/Unset link overload. All transit traffic on this link will be drained.
    Equivalent to hard draining the link
    '''

    links = client.dump_links()
    print()

    def intf_is_overloaded(links, interface):
        if interface in links.interfaceDetails:
            return links.interfaceDetails[interface].isOverloaded
        return False

    if overload and intf_is_overloaded(links, interface):
        print('Interface is already overloaded.\n')
        sys.exit(0)

    if not overload and not intf_is_overloaded(links, interface):
        print('Interface is not overloaded.\n')
        sys.exit(0)

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

    links = client.set_unset_link_overload(overload, interface)

    if overload == intf_is_overloaded(links, interface):
        print('Successfully {} for the interface.\n'.format(action))
    else:
        print('Failed to {} for the interface.\n'.format(action))