Esempio n. 1
0
def run_bgp_command(vtysh_cmd, bgp_namespace=multi_asic.DEFAULT_NAMESPACE):
    bgp_instance_id = ' '
    output = None
    if bgp_namespace is not multi_asic.DEFAULT_NAMESPACE:
        bgp_instance_id = multi_asic.get_asic_id_from_name(bgp_namespace)

    cmd = 'sudo docker exec bgp{} vtysh -c "{}"'.format(
        bgp_instance_id, vtysh_cmd)
    try:
        output = clicommon.run_command(cmd, return_cmd=True)
    except Exception:
        ctx = click.get_current_context()
        ctx.fail("Unable to get summary from bgp".format(bgp_instance_id))

    return output
Esempio n. 2
0
def run_bgp_command(vtysh_cmd, bgp_namespace=multi_asic.DEFAULT_NAMESPACE, vtysh_shell_cmd=constants.VTYSH_COMMAND):
    bgp_instance_id = ' '
    output = None
    if bgp_namespace is not multi_asic.DEFAULT_NAMESPACE:
        bgp_instance_id = " -n {} ".format(
            multi_asic.get_asic_id_from_name(bgp_namespace))

    cmd = 'sudo {} {} -c "{}"'.format(
        vtysh_shell_cmd, bgp_instance_id, vtysh_cmd)
    try:
        output = clicommon.run_command(cmd, return_cmd=True)
    except Exception:
        ctx = click.get_current_context()
        ctx.fail("Unable to get summary from bgp {}".format(bgp_instance_id))

    return output
Esempio n. 3
0
 def run(self):
     '''
         Main method of the class
     '''
     self.get_po_names()
     for po,ns in self.lag_names.items():
         self.lags[po] = {}
         if 'multi_asic' in sys.modules:
             ns_id = multi_asic.get_asic_id_from_name(ns) if ns else ''
         else:
             ns_id = ''
         self.lags[po]['po_stats'] = self.get_po_status(po, ns_id)
         self.lags[po]['po_config'] = self.get_po_config(po, ns_id)
         self.lags[po]['po_intf_stat'] = self.get_po_intf_stat(po, ns)
         self.lags[po]['po_namespace_id'] = ns_id
     self.module.exit_json(ansible_facts={'lag_facts': {'names': self.lag_names, 'lags': self.lags}})
     return
def get_port_config(hwsku=None,
                    platform=None,
                    port_config_file=None,
                    hwsku_config_file=None,
                    asic_name=None):
    config_db = db_connect_configdb(asic_name)
    # If available, Read from CONFIG DB first
    if config_db is not None and port_config_file is None:

        port_data = config_db.get_table("PORT")
        if bool(port_data):
            ports = ast.literal_eval(json.dumps(port_data))
            port_alias_map = {}
            port_alias_asic_map = {}
            for intf_name in ports.keys():
                if "alias" in ports[intf_name]:
                    port_alias_map[ports[intf_name]["alias"]] = intf_name
            return (ports, port_alias_map, port_alias_asic_map)

    if asic_name is not None:
        asic_id = str(get_asic_id_from_name(asic_name))
    else:
        asic_id = None

    if not port_config_file:
        port_config_file = device_info.get_path_to_port_config_file(
            hwsku, asic_id)

        if not port_config_file:
            return ({}, {}, {})

    # Read from 'platform.json' file
    if port_config_file.endswith('.json'):
        if not hwsku_config_file:
            hwsku_json_file = get_hwsku_file_name(hwsku, platform)
            if not hwsku_json_file:
                return ({}, {}, {})
        else:
            hwsku_json_file = hwsku_config_file

        return parse_platform_json_file(hwsku_json_file, port_config_file)

    # If 'platform.json' file is not available, read from 'port_config.ini'
    else:
        return parse_port_config_file(port_config_file)
Esempio n. 5
0
def get_port_alias_to_name_map(hwsku, asic_id=None):
    try:
        from sonic_py_common import multi_asic
        from ansible.module_utils.multi_asic_utils  import load_db_config
        load_db_config()
        namespace_list = multi_asic.get_all_namespaces()
        for key, list in namespace_list.items():
            asic_ids = []
            for ns in list:
                asic_ids.append(multi_asic.get_asic_id_from_name(ns))
            namespace_list[key] = asic_ids
    except ImportError:
        namespace_list = ['']
    port_alias_to_name_map = {}
    port_alias_asic_map = {}
    if hwsku == "Force10-S6000":
        for i in range(0, 128, 4):
            port_alias_to_name_map["fortyGigE0/%d" % i] = "Ethernet%d" % i
    elif hwsku == "Force10-S6100":
        for i in range(0, 4):
            for j in range(0, 16):
                port_alias_to_name_map["fortyGigE1/%d/%d" % (i + 1, j + 1)] = "Ethernet%d" % (i * 16 + j)
    elif hwsku == "Force10-Z9100":
        for i in range(0, 128, 4):
            port_alias_to_name_map["hundredGigE1/%d" % (i / 4 + 1)] = "Ethernet%d" % i
    # TODO: Come up with a generic formula for generating etp style aliases based on number of ports and lanes
    elif hwsku == "DellEMC-Z9332f-M-O16C64":
        # 100G ports
        s100G_ports = [x for x in range(0, 96, 2)] + [x for x in range(128, 160, 2)]

        # 400G ports
        s400G_ports = [x for x in range(96, 128, 8)] + [x for x in range(160, 256, 8)]

        # 10G ports
        s10G_ports = [x for x in range(256, 258)]

        for i in s100G_ports:
            alias = "etp{}{}".format(((i + 8) // 8), chr(ord('a') + (i // 2) % 4))
            port_alias_to_name_map[alias] = "Ethernet{}".format(i)
        for i in s400G_ports:
            alias = "etp{}".format((i // 8) + 1)
            port_alias_to_name_map[alias] = "Ethernet{}".format(i)
        for i in s10G_ports:
            alias = "etp{}".format(33 if i == 256 else 34)
            port_alias_to_name_map[alias] = "Ethernet{}".format(i)
    elif hwsku == "DellEMC-Z9332f-O32":
        for i in range(0, 256, 8):
            alias = "etp{}".format((i // 8) + 1)
            port_alias_to_name_map[alias] = "Ethernet{}".format(i)
        for i in range(256, 258):
            alias = "etp{}".format(33 if i == 256 else 34)
            port_alias_to_name_map[alias] = "Ethernet{}".format(i)
    elif hwsku == "Arista-7050-QX32":
        for i in range(1, 25):
            port_alias_to_name_map["Ethernet%d/1" % i] = "Ethernet%d" % ((i - 1) * 4)
        for i in range(25, 33):
            port_alias_to_name_map["Ethernet%d" % i] = "Ethernet%d" % ((i - 1) * 4)
    elif hwsku == "Arista-7050-QX-32S":
        for i in range(0, 4):
            port_alias_to_name_map["Ethernet1/%d" % (i + 1)] = "Ethernet%d" % i
        for i in range(6, 29):
            port_alias_to_name_map["Ethernet%d/1" % i] = "Ethernet%d" % ((i - 5) * 4)
        for i in range(29, 37):
            port_alias_to_name_map["Ethernet%d" % i] = "Ethernet%d" % ((i - 5) * 4)
    elif hwsku == "Arista-7280CR3-C40":
        for i in range(1, 33):
            port_alias_to_name_map["Ethernet%d/1" % i] = "Ethernet%d" % ((i - 1) * 4)
        for i in range(33, 41, 2):
            port_alias_to_name_map["Ethernet%d/1" % i] = "Ethernet%d" % ((i - 1) * 4)
            port_alias_to_name_map["Ethernet%d/5" % i] = "Ethernet%d" % (i * 4)
    elif hwsku == "Arista-7260CX3-C64" or hwsku == "Arista-7170-64C":
        for i in range(1, 65):
            port_alias_to_name_map["Ethernet%d/1" % i] = "Ethernet%d" % ((i - 1) * 4)
    elif hwsku == "Arista-7060CX-32S-C32" or hwsku == "Arista-7060CX-32S-Q32" or hwsku == "Arista-7060CX-32S-C32-T1" or hwsku == "Arista-7170-32CD-C32" \
        or hwsku == "Arista-7050CX3-32S-C32":
        for i in range(1, 33):
            port_alias_to_name_map["Ethernet%d/1" % i] = "Ethernet%d" % ((i - 1) * 4)
    elif hwsku == "Mellanox-SN2700-D40C8S8":
        # 10G ports
        s10G_ports = range(0, 4) + range(8, 12)

        # 50G ports
        s50G_ports = [x for x in range(16, 24, 2)] + [x for x in range(40, 88, 2)] + [x for x in range(104, 128, 2)]

        # 100G ports
        s100G_ports = [x for x in range(24, 40, 4)] + [x for x in range(88, 104, 4)]

        for i in s10G_ports:
            alias = "etp%d" % (i / 4 + 1) + chr(ord('a') + i % 4)
            port_alias_to_name_map[alias] = "Ethernet%d" % i
        for i in s50G_ports:
            alias = "etp%d" % (i / 4 + 1) + ("a" if i % 4 == 0 else "b")
            port_alias_to_name_map[alias] = "Ethernet%d" % i
        for i in s100G_ports:
            alias = "etp%d" % (i / 4 + 1)
            port_alias_to_name_map[alias] = "Ethernet%d" % i
    elif hwsku == "Mellanox-SN2700-D48C8":
        # 50G ports
        s50G_ports = [x for x in range(0, 24, 2)] + [x for x in range(40, 88, 2)] + [x for x in range(104, 128, 2)]

        # 100G ports
        s100G_ports = [x for x in range(24, 40, 4)] + [x for x in range(88, 104, 4)]

        for i in s50G_ports:
            alias = "etp%d" % (i / 4 + 1) + ("a" if i % 4 == 0 else "b")
            port_alias_to_name_map[alias] = "Ethernet%d" % i
        for i in s100G_ports:
            alias = "etp%d" % (i / 4 + 1)
            port_alias_to_name_map[alias] = "Ethernet%d" % i
    elif hwsku == "Mellanox-SN2700" or hwsku == "ACS-MSN2700":
        for i in range(1, 33):
            port_alias_to_name_map["etp%d" % i] = "Ethernet%d" % ((i - 1) * 4)
    elif hwsku == "Arista-7060CX-32S-D48C8":
        # All possible breakout 50G port numbers:
        all_ports = [x for x in range(1, 33)]

        # 100G ports
        s100G_ports = [x for x in range(7, 11)]
        s100G_ports += [x for x in range(23, 27)]

        port_alias_to_name_map = _port_alias_to_name_map_50G(all_ports, s100G_ports)
    elif hwsku == "Arista-7260CX3-D108C8":
        # All possible breakout 50G port numbers:
        all_ports = [x for x in range(1, 65)]

        # 100G ports
        s100G_ports = [x for x in range(13, 21)]

        port_alias_to_name_map = _port_alias_to_name_map_50G(all_ports, s100G_ports)
    elif hwsku == "Arista-7800R3-48CQ-LC" or\
         hwsku == "Arista-7800R3K-48CQ-LC":
         for i in range(1, 48):
             port_alias_to_name_map["Ethernet%d/1" % i] = "Ethernet%d" % ((i - 1) * 4)
    elif hwsku == "INGRASYS-S9100-C32":
        for i in range(1, 33):
            port_alias_to_name_map["Ethernet%d/1" % i] = "Ethernet%d" % ((i - 1) * 4)
    elif hwsku == "INGRASYS-S9100-C32" or hwsku == "INGRASYS-S9130-32X" or hwsku == "INGRASYS-S8810-32Q":
        for i in range(1, 33):
            port_alias_to_name_map["Ethernet%d/1" % i] = "Ethernet%d" % ((i - 1) * 4)
    elif hwsku == "INGRASYS-S8900-54XC":
        for i in range(1, 49):
            port_alias_to_name_map["Ethernet%d" % i] = "Ethernet%d" % (i - 1)
        for i in range(49, 55):
            port_alias_to_name_map["Ethernet%d/1" % i] = "Ethernet%d" % ((i - 49) * 4 + 48)
    elif hwsku == "INGRASYS-S8900-64XC":
        for i in range(1, 49):
            port_alias_to_name_map["Ethernet%d" % i] = "Ethernet%d" % (i - 1)
        for i in range(49, 65):
            port_alias_to_name_map["Ethernet%d/1" % i] = "Ethernet%d" % ((i - 49) * 4 + 48)
    elif hwsku == "Accton-AS7712-32X":
        for i in range(1, 33):
            port_alias_to_name_map["hundredGigE%d" % i] = "Ethernet%d" % ((i - 1) * 4)
    elif hwsku == "Celestica-DX010-C32":
        for i in range(1, 33):
            port_alias_to_name_map["etp%d" % i] = "Ethernet%d" % ((i - 1) * 4)
    elif hwsku == "Seastone-DX010":
        for i in range(1, 33):
            port_alias_to_name_map["Eth%d" % i] = "Ethernet%d" % ((i - 1) * 4)
    elif hwsku in ["Celestica-E1031-T48S4", "Nokia-7215", "Nokia-M0-7215"]:
        for i in range(1, 53):
            port_alias_to_name_map["etp%d" % i] = "Ethernet%d" % ((i - 1))
    elif hwsku == "et6448m":
        for i in range(0, 52):
            port_alias_to_name_map["Ethernet%d" % i] = "Ethernet%d" % i
    elif hwsku == "Nokia-IXR7250E-36x400G":
        if asic_id is not None:
            asic_offset = int(asic_id) * 18
            for i in range(0, 18):
                port_alias_to_name_map["Ethernet%d" % (asic_offset + i)] = "Ethernet%d" % ((asic_offset + i))
                port_alias_asic_map["Eth%d-ASIC%d" % (i, int(asic_id))] = "Ethernet%d" % ((asic_offset + i))
        else:
            for i in range(0, 36):
                port_alias_to_name_map["Ethernet%d" % i] = "Ethernet%d" % i
    elif hwsku == 'Nokia-IXR7250E-SUP-10':
        port_alias_to_name_map = {}
    elif hwsku == "newport":
        for i in range(0, 256, 8):
            port_alias_to_name_map["Ethernet%d" % i] = "Ethernet%d" % i
    elif hwsku == "32x100Gb":
        for i in range(0, 32):
            port_alias_to_name_map["Ethernet%d" % i] = "Ethernet%d" % i
    elif hwsku == "36x100Gb":
        for i in range(0, 36):
            port_alias_to_name_map["Ethernet%d" % i] = "Ethernet%d" % i
    elif hwsku == "64x100Gb":
        for i in range(0, 64):
            port_alias_to_name_map["Ethernet%d" % i] = "Ethernet%d" % i
    elif hwsku == "msft_multi_asic_vs":
        if asic_id is not None and asic_id in namespace_list['front_ns']:
            asic_offset = int(asic_id) * 16
            backplane_offset = 15
            for i in range(1, 17):
                port_alias_to_name_map["Ethernet1/%d"%(asic_offset+i)] = "Ethernet%d"%((asic_offset + i -1) *4)
                port_alias_asic_map["Eth%d-ASIC%d"%(i-1, int(asic_id))] = "Ethernet%d"%((asic_offset + i -1) *4)
                port_alias_to_name_map["Eth%d-ASIC%d"%((backplane_offset+i), int(asic_id))] = "Ethernet-BP%d"%((asic_offset + i -1) *4)
                port_alias_asic_map["Eth%d-ASIC%d"%((backplane_offset+i), int(asic_id))] = "Ethernet-BP%d"%((asic_offset + i -1) *4)
        elif asic_id is not None  and asic_id in namespace_list['back_ns']:
            asic_offset = 32 * (int(asic_id) - 2)
            for i in range(1, 33):
                port_alias_asic_map["Eth%d-ASIC%d"%(i-1, int(asic_id))] = "Ethernet-BP%d"%((asic_offset + i -1) *4)
                port_alias_to_name_map["Eth%d-ASIC%d"%(i-1, int(asic_id))] = "Ethernet-BP%d"%((asic_offset + i -1) *4)
        else:
            for i in range(1,65):
                port_alias_to_name_map["Ethernet1/%d" % i] = "Ethernet%d" % ((i - 1) * 4)
    elif hwsku == "msft_four_asic_vs":
        if asic_id is not None and asic_id in namespace_list['front_ns']:
            asic_offset = int(asic_id) * 4
            backplane_offset = 3
            for i in range(1, 5):
                port_alias_to_name_map["Ethernet1/%d"%(asic_offset+i)] = "Ethernet%d"%((asic_offset + i -1) *4)
                port_alias_asic_map["Eth%d-ASIC%d"%(i-1, int(asic_id))] = "Ethernet%d"%((asic_offset + i -1) *4)
                port_alias_to_name_map["Eth%d-ASIC%d"%((backplane_offset+i), int(asic_id))] = "Ethernet-BP%d"%((asic_offset + i -1) *4)
                port_alias_asic_map["Eth%d-ASIC%d"%((backplane_offset+i), int(asic_id))] = "Ethernet-BP%d"%((asic_offset + i -1) *4)
        elif asic_id is not None  and asic_id in namespace_list['back_ns']:
            asic_offset = 8 * (int(asic_id) -1)
            for i in range(1, 9):
                port_alias_asic_map["Eth%d-ASIC%d"%(i-1, int(asic_id))] = "Ethernet-BP%d"%((asic_offset + i -1) *4)
                port_alias_to_name_map["Eth%d-ASIC%d"%(i-1, int(asic_id))] = "Ethernet-BP%d"%((asic_offset + i -1) *4)
        else:
            for i in range(1,9):
                port_alias_to_name_map["Ethernet1/%d" % i] = "Ethernet%d" % ((i - 1) * 4)
    elif hwsku == "B6510-48VS8CQ" or hwsku == "RA-B6510-48V8C":
        for i in range(1,49):
            port_alias_to_name_map["twentyfiveGigE0/%d" % i] = "Ethernet%d" % i
        for i in range(49,57):
            port_alias_to_name_map["hundredGigE0/%d" % (i-48)] = "Ethernet%d" % i
    elif hwsku == "RA-B6910-64C":
        for i in range(1,65):
            port_alias_to_name_map["hundredGigE%d" % i] = "Ethernet%d" % i
    else:
        for i in range(0, 128, 4):
            port_alias_to_name_map["Ethernet%d" % i] = "Ethernet%d" % i

    return port_alias_to_name_map, port_alias_asic_map