0
  #   ˆl–Ðz¾”*eJe@¿q¶n2â˜´oÀ„�eïÃÂ ?
    #!/usr/bin/python3
# vim: sts=4 ts=4 sw=4 expandtab :

from optparse import OptionParser, OptionGroup
import subprocess
import json
import sys

def handle_cmd_line():
    parser = OptionParser()
    parser.add_option('--config', dest='config', default = '',
                      help = "convert the team JSON format configuration file " \
                      + "to NetworkManager connection profile, please use " \
                      + "'teamdctl TEAM config dump [actual]' to dump the config file." \
                      + " Note the script only convert config file. IP " \
                      + "address configurations still need to be set manually.")
    parser.add_option('--rename', dest='rename', default = '',
                      help = "rename the default team interface name." \
                      + " Careful: firewall rules, aliases interfaces, etc., " \
                      + "will break after the renaming because the tool " \
                      + "will only change the config file, nothing else.")

    group = OptionGroup(parser, 'Dangerous Options',
                        "Caution: You need to dump the team configuration " \
                        "file first and then delete old team device to avoid " \
                        "device name conflicts.")
    group.add_option('--exec-cmd', dest='exec_cmd', action='store_true', default = False,
                      help = "exec nmcli and add the connections directly " \
                      + "instead of printing the nmcli cmd to screen. " \
                      + "This parameter is NOT recommended, it would be good " \
                      + "to double check the cmd before apply.")
    parser.add_option_group(group)

    (options, args) = parser.parse_args()

    if subprocess.run(['nmcli', '-v'], stdout=subprocess.DEVNULL,
                      stderr=subprocess.DEVNULL).returncode != 0:
        print("Warn: NetworkManager is needed for this script!");
        sys.exit(1)

    return options

def convert_runner_opts(runner_opts):
    bond_opts = ""

    if runner_opts['name'] == 'broadcast':
        bond_opts = "mode=broadcast"
    elif runner_opts['name'] == 'roundrobin':
        bond_opts = "mode=balance-rr"
    elif runner_opts['name'] == 'activebackup':
        bond_opts = "mode=active-backup"
        if 'hwaddr_policy' in runner_opts:
	        if runner_opts['hwaddr_policy'] == 'same_all':
	            bond_opts += ",fail_over_mac=none"
	        elif runner_opts['hwaddr_policy'] == 'by_active':
	            bond_opts += ",fail_over_mac=active"
	        elif runner_opts['hwaddr_policy'] == 'only_active':
	            bond_opts += ",fail_over_mac=follow"
	        else:
	            print("# Warn: invalid runner.hwaddr_policy: " + runner_opts['hwaddr_policy'])
    elif runner_opts['name'] == 'loadbalance':
        bond_opts = "mode=balance-tlb"
    elif runner_opts['name'] == 'lacp':
        bond_opts = "mode=802.3ad"
        if 'active' in runner_opts:
            print("# Warn: option runner.active: %r is not supported by bonding" % runner_opts['active'])
        if 'fast_rate' in runner_opts:
            if runner_opts['fast_rate']:
                bond_opts += ",lacp_rate=1"
            else:
                bond_opts += ",lacp_rate=0"
        if 'sys_prio' in runner_opts:
                bond_opts += ",ad_actor_sys_prio=" + str(runner_opts['sys_prio'])
        if 'min_ports' in runner_opts:
            bond_opts += ",min_links=" + str(runner_opts['min_ports'])
        if 'agg_select_policy' in runner_opts:
            if runner_opts['agg_select_policy'] == 'bandwidth':
                bond_opts += ",ad_select=bandwidth"
            elif runner_opts['agg_select_policy'] == 'count':
                bond_opts += ",ad_select=count"
            else:
                print("# Warn: Option runner.agg_select_policy: %s is not supported by bonding" %
                        runner_opts['agg_select_policy'])
                sys.exit(1)
    else:
        print("Error: Unsupported runner.name: %s f