Exemple #1
0
    def run(self, ipv4, ipv6, prefixes: t.List[str]):
        with ExitStack() as stack:
            client = stack.enter_context(self._create_agent_client())
            qsfp_client = stack.enter_context(self._create_qsfp_client())
            vlan_port_map = utils.get_vlan_port_map(client,
                                                    qsfp_client,
                                                    colors=False,
                                                    details=False)
            vlan_aggregate_port_map = utils.get_vlan_aggregate_port_map(client)
            resp = client.getRouteTableDetails()
            if not resp:
                print("No Route Table Details Found")
                return
            for entry in resp:
                prefix_str = (
                    f"{utils.ip_ntop(entry.dest.ip.addr)}/{entry.dest.prefixLength}"
                )

                # Apply filter
                if ipv6 and not ipv4 and len(entry.dest.ip.addr) == 4:
                    continue
                if ipv4 and not ipv6 and len(entry.dest.ip.addr) == 16:
                    continue
                if prefixes and prefix_str not in prefixes:
                    continue

                # Print route details
                printRouteDetailEntry(entry, vlan_aggregate_port_map,
                                      vlan_port_map)
Exemple #2
0
    def run(self, client_id, ipv4, ipv6, prefixes: t.List[str]):
        with ExitStack() as stack:
            agent_client = stack.enter_context(self._create_agent_client())
            try:
                qsfp_client = stack.enter_context(self._create_qsfp_client())
            except TTransportException:
                qsfp_client = None
            if client_id is None:
                resp = agent_client.getRouteTable()
            else:
                resp = agent_client.getRouteTableByClient(client_id)
            if not resp:
                print("No Route Table Entries Found")
                return

            # Getting the port/agg to VLAN map in order to display them
            vlan_port_map = utils.get_vlan_port_map(
                agent_client, qsfp_client, colors=False, details=False
            )
            vlan_aggregate_port_map = utils.get_vlan_aggregate_port_map(agent_client)

            for entry in resp:
                prefix_str = (
                    f"{utils.ip_ntop(entry.dest.ip.addr)}/{entry.dest.prefixLength}"
                )
                ucmp_active = " (UCMP Active)" if is_ucmp_active(entry.nextHops) else ""

                # Apply filters
                if ipv6 and not ipv4 and len(entry.dest.ip.addr) == 4:
                    continue
                if ipv4 and not ipv6 and len(entry.dest.ip.addr) == 16:
                    continue
                if prefixes and prefix_str not in prefixes:
                    continue

                # Print header
                print(f"Network Address: {prefix_str}{ucmp_active}")

                # Need to check the nextHopAddresses
                if entry.nextHops:
                    for nextHop in entry.nextHops:
                        print(
                            "\tvia %s"
                            % (
                                utils.nexthop_to_str(
                                    nextHop,
                                    vlan_aggregate_port_map=vlan_aggregate_port_map,
                                    vlan_port_map=vlan_port_map,
                                )
                            )
                        )
                else:
                    for address in entry.nextHopAddrs:
                        print(
                            "\tvia %s"
                            % utils.nexthop_to_str(NextHopThrift(address=address))
                        )
Exemple #3
0
    def run(self, client_id, ipv4, ipv6):
        with ExitStack() as stack:
            agent_client = stack.enter_context(self._create_agent_client())
            qsfp_client = stack.enter_context(self._create_qsfp_client())
            if client_id is None:
                resp = agent_client.getRouteTable()
            else:
                resp = agent_client.getRouteTableByClient(client_id)
            if not resp:
                print("No Route Table Entries Found")
                return

            # Getting the port/agg to VLAN map in order to display them
            vlan_port_map = utils.get_vlan_port_map(
                agent_client, qsfp_client, colors=False, details=False
            )
            vlan_aggregate_port_map = utils.get_vlan_aggregate_port_map(agent_client)

            for entry in resp:
                if ipv6 and not ipv4 and len(entry.dest.ip.addr) == 4:
                    continue
                if ipv4 and not ipv6 and len(entry.dest.ip.addr) == 16:
                    continue

                prefix = utils.ip_ntop(entry.dest.ip.addr)
                prefix_mask_len = entry.dest.prefixLength
                ucmp_active = " (UCMP Active)" if is_ucmp_active(entry.nextHops) else ""
                print(f"Network Address: {prefix}/{prefix_mask_len}{ucmp_active}")

                # Need to check the nextHopAddresses
                if entry.nextHops:
                    for nextHop in entry.nextHops:
                        print(
                            "\tvia %s"
                            % (
                                utils.nexthop_to_str(
                                    nextHop,
                                    vlan_aggregate_port_map=vlan_aggregate_port_map,
                                    vlan_port_map=vlan_port_map,
                                    ucmp_active=ucmp_active,
                                )
                            )
                        )
                else:
                    for address in entry.nextHopAddrs:
                        print(
                            "\tvia %s"
                            % utils.nexthop_to_str(NextHopThrift(address=address))
                        )
Exemple #4
0
 def run(self, ip, vrf):
     addr = Address(addr=ip, type=AddressType.V4)
     if not addr.addr:
         print('No ip address provided')
         return
     with self._create_agent_client() as client, \
             self._create_qsfp_client() as qsfp_client:
         # Getting the port/agg to VLAN map in order to display them
         vlan_port_map = utils.get_vlan_port_map(client,
                                                 qsfp_client,
                                                 colors=False,
                                                 details=False)
         vlan_aggregate_port_map = utils.get_vlan_aggregate_port_map(client)
         self.printIpRouteDetails(client, addr, vrf,
                                  vlan_aggregate_port_map, vlan_port_map)
Exemple #5
0
 def run(self, ip, vrf):
     addr = Address(addr=ip, type=AddressType.V4)
     if not addr.addr:
         print("No ip address provided")
         return
     with ExitStack() as stack:
         client = stack.enter_context(self._create_agent_client())
         qsfp_client = stack.enter_context(self._create_qsfp_client())
         # Getting the port/agg to VLAN map in order to display them
         vlan_port_map = utils.get_vlan_port_map(client,
                                                 qsfp_client,
                                                 colors=False,
                                                 details=False)
         vlan_aggregate_port_map = utils.get_vlan_aggregate_port_map(client)
         self.printIpRouteDetails(client, addr, vrf,
                                  vlan_aggregate_port_map, vlan_port_map)
Exemple #6
0
 def run(self, ipv4, ipv6):
     with ExitStack() as stack:
         client = stack.enter_context(self._create_agent_client())
         qsfp_client = stack.enter_context(self._create_qsfp_client())
         vlan_port_map = utils.get_vlan_port_map(
             client, qsfp_client, colors=False, details=False
         )
         vlan_aggregate_port_map = utils.get_vlan_aggregate_port_map(client)
         resp = client.getRouteTableDetails()
         if not resp:
             print("No Route Table Details Found")
             return
         for entry in resp:
             if ipv6 and not ipv4 and len(entry.dest.ip.addr) == 4:
                 continue
             if ipv4 and not ipv6 and len(entry.dest.ip.addr) == 16:
                 continue
             printRouteDetailEntry(entry, vlan_aggregate_port_map, vlan_port_map)
    def run(self) -> None:
        ''' fetch data and populate interface summary list '''
        with self._create_agent_client() as agent_client, \
                self._create_qsfp_client() as qsfp_client:

            # Getting the port/agg to VLAN map in order to display them
            vlan_port_map = utils.get_vlan_port_map(agent_client,
                                                    qsfp_client=qsfp_client)
            vlan_aggregate_port_map = utils.get_vlan_aggregate_port_map(
                agent_client)

            interface_summary: List[Interface] = []
            for interface in agent_client.getAllInterfaces().values():
                # build the addresses variable for this interface
                addresses = '\n'.join([
                    self.convert_address(address.ip.addr) + '/' +
                    str(address.prefixLength) for address in interface.address
                ])
                # build the ports variable for this interface
                ports: str = ''
                if interface.vlanId in vlan_port_map.keys():
                    for root_port in sorted(
                            vlan_port_map[interface.vlanId].keys(),
                            key=self.sort_key,
                    ):
                        port_list = vlan_port_map[interface.vlanId][root_port]
                        ports += ' '.join(port_list) + '\n'
                vlan = interface.vlanId
                interface_name = interface.interfaceName
                mtu = interface.mtu
                # check if aggregate
                if vlan in vlan_aggregate_port_map.keys():
                    interface_name = (
                        f'{interface.interfaceName}\n({vlan_aggregate_port_map[vlan]})'
                    )
                interface_summary.append(
                    Interface(
                        vlan=vlan,
                        name=interface_name,
                        mtu=mtu,
                        addresses=addresses,
                        ports=ports,
                    ))
            self.print_table(interface_summary)
Exemple #8
0
def get_interface_summary(agent_client, qsfp_client) -> List[Interface]:
    # Getting the port/agg to VLAN map in order to display them
    vlan_port_map = utils.get_vlan_port_map(agent_client,
                                            qsfp_client=qsfp_client)
    vlan_aggregate_port_map = utils.get_vlan_aggregate_port_map(agent_client)

    interface_summary: List[Interface] = []
    for interface in agent_client.getAllInterfaces().values():
        # build the addresses variable for this interface
        addresses = '\n'.join([
            convert_address(address.ip.addr) + '/' + str(address.prefixLength)
            for address in interface.address
        ])
        # build the ports variable for this interface
        ports: str = ''
        if interface.vlanId in vlan_port_map.keys():
            for root_port in sorted(
                    vlan_port_map[interface.vlanId].keys(),
                    key=sort_key,
            ):
                port_list = vlan_port_map[interface.vlanId][root_port]
                ports += ' '.join(port_list) + '\n'
        vlan = interface.vlanId
        interface_name = interface.interfaceName
        mtu = interface.mtu
        # check if aggregate
        if vlan in vlan_aggregate_port_map.keys():
            interface_name = (
                f'{interface.interfaceName}\n({vlan_aggregate_port_map[vlan]})'
            )
        interface_summary.append(
            Interface(
                vlan=vlan,
                name=interface_name,
                mtu=mtu,
                addresses=addresses,
                ports=ports,
            ))
    return interface_summary