Exemplo n.º 1
0
def qdisc(interface, action, algorithm=None, handle=None, parent=None,
          stderr=None, dryrun=False, *args, **kwargs):
    """
    Add/change/replace/replace qdisc

    **kwargs will be used for specific arguments, depending on the algorithm
    used.

    :param action: "add", "replace", "change" or "delete"
    :param interface: target interface
    :param algorithm: algorithm used for this leaf (htb, pfifo, sfq, ...)
    :param handle: handle parameter for tc (default: None)
    :param parent: if is None, the rule will be added as root. (default: None)
    :param stderr: indicates stderr to use during the tc commands execution
    """
    command = ["tc", "qdisc", action, "dev", interface]
    if parent is None:
        command.append("root")
    else:
        command += ["parent", parent]
    if handle is not None:
        command += ["handle", str(handle)]
    if algorithm is not None:
        command.append(algorithm)
    for i, j in sorted(kwargs.items()):
        if j is not None:
            command += [str(i), str(j)]

    launch_command(command, stderr, dryrun)
Exemplo n.º 2
0
Arquivo: tc.py Projeto: aruhier/pyqos
def filter_show(interface, dryrun=False):
    """
    Show filters

    :param interface: target interface
    """
    launch_command(["tc", "filter", "show", "dev", interface], dryrun=dryrun)
Exemplo n.º 3
0
Arquivo: tc.py Projeto: aruhier/pyqos
def qos_class_show(interface, show_format=None, dryrun=False):
    """
    Show classes

    :param interface: target interface
    :param show_format: option "FORMAT" for tc. (default: None)
        "stats" -> -s
        "details" -> -d
        "raw" -> -r
        "pretty" -> -p
        "iec" -> -i
    """
    formats = {
        "stats": "-s",
        "details": "-d",
        "raw": "-r",
        "pretty": "-p",
        "iec": "-i"
    }
    correct_format = formats.get(show_format, None)
    command = ["tc"]
    if show_format is not None:
        command.append(correct_format)
    command += ["class", "show", "dev", interface]
    launch_command(command, dryrun=dryrun)
Exemplo n.º 4
0
def filter_show(interface, dryrun=False):
    """
    Show filters

    :param interface: target interface
    """
    launch_command(["tc", "filter", "show", "dev", interface], dryrun=dryrun)
Exemplo n.º 5
0
def filter(interface, action, prio, handle, flowid, parent=None,
           protocol="all", dryrun=False, *args, **kwargs):
    """
    Add/change/replace/delete filter

    **kwargs will be used for specific arguments, depending on the algorithm
    used.

    :param action: "add", "replace", "change" or "delete"
    :param interface: target interface
    :param prio: priority
    :param handle: filter id
    :param flowid: target class
    :param parent: parent class/qdisc (default: None)
    :param protocol: protocol to filter. (default: "all")
    """
    command = ["tc", "filter", action, "dev", interface]
    if parent is not None:
        command += ["parent", parent]
    command += ["protocol", protocol, "prio", str(prio), "handle", str(handle),
                "fw", "flowid", str(flowid)]
    for i, j in sorted(kwargs.items()):
        if j is not None:
            command += [str(i), str(j)]
    launch_command(command, dryrun=dryrun)
Exemplo n.º 6
0
Arquivo: tc.py Projeto: aruhier/pyqos
def qos_class(interface,
              action,
              parent,
              classid=None,
              algorithm="htb",
              dryrun=False,
              *args,
              **kwargs):
    """
    Add/change/replace/replace class

    **kwargs will be used for specific arguments, depending on the algorithm
    used.
    Parameters need to be in kbit. If the unit isn't indicated, add it
    automagically

    :param action: "add", "replace", "change" or "delete"
    :param interface: target interface
    :param parent: parent class/qdisc
    :param classid: id for the current class (default: None)
    :param algorithm: algorithm used for this class (default: htb)
    """
    command = ["tc", "class", action, "dev", interface, "parent", parent]
    if classid is not None:
        command += ["classid", classid]
    command.append(algorithm)
    if algorithm == "htb":
        for key in ("rate", "ceil"):
            if key in kwargs.keys():
                try:
                    kwargs[key] = str(int(kwargs[key])) + "kbit"
                except:
                    pass
        for key in ("burst", "cburst"):
            if key in kwargs.keys():
                try:
                    kwargs[key] = str(int(kwargs[key])) + "k"
                except:
                    pass
    for i, j in sorted(kwargs.items()):
        if j is not None:
            command += [str(i), str(j)]
    launch_command(command, dryrun=dryrun)
Exemplo n.º 7
0
def qos_class_show(interface, show_format=None, dryrun=False):
    """
    Show classes

    :param interface: target interface
    :param show_format: option "FORMAT" for tc. (default: None)
        "stats" -> -s
        "details" -> -d
        "raw" -> -r
        "pretty" -> -p
        "iec" -> -i
    """
    formats = {"stats": "-s", "details": "-d", "raw": "-r", "pretty": "-p",
               "iec": "-i"}
    correct_format = formats.get(show_format, None)
    command = ["tc"]
    if show_format is not None:
        command.append(correct_format)
    command += ["class", "show", "dev", interface]
    launch_command(command, dryrun=dryrun)
Exemplo n.º 8
0
Arquivo: tc.py Projeto: aruhier/pyqos
def qdisc(interface,
          action,
          algorithm=None,
          handle=None,
          parent=None,
          stderr=None,
          dryrun=False,
          opts_args=None,
          **kwargs):
    """
    Add/change/replace/replace qdisc

    **kwargs will be used for specific arguments, depending on the algorithm
    used.

    :param action: "add", "replace", "change" or "delete"
    :param interface: target interface
    :param algorithm: algorithm used for this leaf (htb, pfifo, sfq, ...)
    :param handle: handle parameter for tc (default: None)
    :param parent: if is None, the rule will be added as root. (default: None)
    :param stderr: indicates stderr to use during the tc commands execution
    :param opts_args: list of options without value, to append to the command
    """
    opts_args = opts_args or []
    command = ["tc", "qdisc", action, "dev", interface]
    if parent is None:
        command.append("root")
    else:
        command += ["parent", parent]
    if handle is not None:
        command += ["handle", str(handle)]
    if algorithm is not None:
        command.append(algorithm)
    for i, j in sorted(kwargs.items()):
        if j is not None:
            command += [str(i), str(j)]
    command.extend(sorted(opts_args))

    launch_command(command, stderr, dryrun)
Exemplo n.º 9
0
Arquivo: tc.py Projeto: aruhier/pyqos
def filter(interface,
           action,
           prio,
           handle,
           flowid,
           parent=None,
           protocol="all",
           dryrun=False,
           *args,
           **kwargs):
    """
    Add/change/replace/delete filter

    **kwargs will be used for specific arguments, depending on the algorithm
    used.

    :param action: "add", "replace", "change" or "delete"
    :param interface: target interface
    :param prio: priority
    :param handle: filter id
    :param flowid: target class
    :param parent: parent class/qdisc (default: None)
    :param protocol: protocol to filter. (default: "all")
    """
    command = ["tc", "filter", action, "dev", interface]
    if parent is not None:
        command += ["parent", parent]
    command += [
        "protocol", protocol, "prio",
        str(prio), "handle",
        str(handle), "fw", "flowid",
        str(flowid)
    ]
    for i, j in sorted(kwargs.items()):
        if j is not None:
            command += [str(i), str(j)]
    launch_command(command, dryrun=dryrun)
Exemplo n.º 10
0
def qos_class(interface, action, parent, classid=None, algorithm="htb",
              dryrun=False, *args, **kwargs):
    """
    Add/change/replace/replace class

    **kwargs will be used for specific arguments, depending on the algorithm
    used.
    Parameters need to be in kbit. If the unit isn't indicated, add it
    automagically

    :param action: "add", "replace", "change" or "delete"
    :param interface: target interface
    :param parent: parent class/qdisc
    :param classid: id for the current class (default: None)
    :param algorithm: algorithm used for this class (default: htb)
    """
    command = ["tc", "class", action, "dev", interface, "parent", parent]
    if classid is not None:
        command += ["classid", classid]
    command.append(algorithm)
    if algorithm == "htb":
        for key in ("rate", "ceil"):
            if key in kwargs.keys():
                try:
                    kwargs[key] = str(int(kwargs[key])) + "kbit"
                except:
                    pass
        for key in ("burst", "cburst"):
            if key in kwargs.keys():
                try:
                    kwargs[key] = str(int(kwargs[key])) + "k"
                except:
                    pass
    for i, j in sorted(kwargs.items()):
        if j is not None:
            command += [str(i), str(j)]
    launch_command(command, dryrun=dryrun)