Esempio n. 1
0
    def QueryPacketStat(self, request, context):
        statistics_items = []

        for mac_addr in request.mac_addrs:
            statistics = NicManager_pb2.PacketStat()
            statistics_items.append(statistics)

            nic_name = NicManager.MacAddr2NicName(mac_addr)
            if nic_name == "":
                statistics.errno = ErrNo_pb2.SYS_FAIL
                continue

            class_net_path = os.path.join(util.SYS_CLASS_NET, nic_name)
            if not os.path.exists(class_net_path):
                statistics.errno = ErrNo_pb2.SYS_FAIL
                continue

            try:
                nic_object = NicManager.NicHandle(nic_name)
                statistics.tx_bytes = nic_object.get_tx_bytes()
                statistics.tx_packets = nic_object.get_tx_packets()
                statistics.tx_dropped = nic_object.get_tx_dropped()
                statistics.tx_errors = nic_object.get_tx_errors()
                statistics.rx_bytes = nic_object.get_rx_bytes()
                statistics.rx_packets = nic_object.get_rx_packets()
                statistics.rx_dropped = nic_object.get_rx_dropped()
                statistics.rx_errors = nic_object.get_rx_errors()

                statistics.errno = ErrNo_pb2.SYS_OK
            except net_agentd_exception.NetAgentException:
                statistics.errno = ErrNo_pb2.SYS_FAIL
                logging.error("%s QueryPacketStat failed" % nic_name)

        return NicManager_pb2.PacketStatQueryReply(
                                   packet_stats=statistics_items)
Esempio n. 2
0
    def get_uplink_port_name(self):
        uplink_port_name = ""

        try:
            phy_nics_list_uuid = []
            interface_list = self.get_interface_list()
            for interface in interface_list:
                nic_object = NicManager.NicHandle(interface)
                if nic_object.get_nic_type() == NicManager.NicType.PHYSICAL:
                    phy_nics_list_uuid.append(
                        self.get_interface_uuid(interface))

            if len(phy_nics_list_uuid) == 0:
                logging.info("have no uplink port")
            if len(phy_nics_list_uuid) == 1:
                uplink_port_name = self.get_interface_name_by_uuid(
                    phy_nics_list_uuid[0])
            if len(phy_nics_list_uuid) > 1:
                bond_port = []
                port_list = self.get_port_list()
                for port in port_list:
                    interface_uuid_list = self.get_interface_of_port(port)
                    for interface_uuid in interface_uuid_list:
                        if interface_uuid in phy_nics_list_uuid:
                            bond_port.append(port)

                if len(bond_port) != 1:
                    logging.error("too much uplink port")
                else:
                    uplink_port_name = bond_port[0]
        except:
            logging.error("get_uplink_port failed")

        return uplink_port_name
Esempio n. 3
0
    def QueryNicInfo(self, request, context):
        nic_infos = []

        for nic_name in request.nic_names:
            class_net_path = os.path.join(util.SYS_CLASS_NET, nic_name)
            if os.path.exists(class_net_path):
                try:
                    nic_object = NicManager.NicHandle(nic_name)
                    nic_info = NicManager_pb2.NicInfo()

                    nic_info.nic_name = nic_name
                    nic_info.description = nic_object.get_description()
                    nic_info.mac_address = nic_object.get_mac_address()
                    nic_info.speed = nic_object.get_speed()
                    nic_info.operstate = nic_object.get_operstate()
                    nic_info.mtu = nic_object.get_mtu()
                    nic_info.driver_name = nic_object.get_driver_name()
                    nic_info.numa = nic_object.get_numa()
                    nic_info.nic_address = nic_object.get_nic_address()
                    nic_info.carrier = nic_object.get_carrier()
                    nic_info.duplex = nic_object.get_duplex()

                    nic_info.errno = ErrNo_pb2.SYS_OK
                except net_agentd_exception.NetAgentException:
                    nic_info.errno = ErrNo_pb2.SYS_FAIL
                    logging.error("%s QueryNicList failed" % nic_name)

                nic_infos.append(nic_info)

            else:
                logging.error("%s doesnt exist" % nic_name)

        return NicManager_pb2.NicInfoQueryReply(nic_infos=nic_infos)
Esempio n. 4
0
    def StopNic(self, request, context):
        errno = ErrNo_pb2.SYS_FAIL

        try:
            nic_object = NicManager.NicHandle(request.nic_name)
            nic_object.stop_nic()
            errno = ErrNo_pb2.SYS_OK
        except:
            logging.error(traceback.format_exc())
            logging.error("StopNic failed")

        return NicManager_pb2.NicStopReply(errno=errno)
Esempio n. 5
0
    def set_bond_uplink_port(self, conf):
        for nic in conf.nic_names:
            nic_object = NicManager.NicHandle(nic)
            if nic_object.get_nic_type(
            ) != NicManager.NicType.PHYSICAL or nic_object.is_nic_free(
            ) is False:
                raise net_agentd_exception.NetAgentException(
                    "nic is in use or not physical nic")

        if conf.lacp is True:
            self.set_dynamic_bond(conf)
        else:
            self.set_static_bond(conf)
Esempio n. 6
0
    def set_single_uplink_port(self, nic):
        nic_object = NicManager.NicHandle(nic)
        if nic_object.get_nic_type(
        ) != NicManager.NicType.PHYSICAL or nic_object.is_nic_free() is False:
            raise net_agentd_exception.NetAgentException(
                "nic is in use or not physical nic")

        cmd_str = '%s add-port %s %s' % (util.OVS_VSCTL_CMD,
                                         self._vswitch_name, nic)
        cmd = envoy.run(cmd_str)
        if cmd.status_code == 0:
            logging.info('%s success' % cmd_str)
        else:
            raise net_agentd_exception.NetAgentException(
                '%s failed \n%s' % (cmd_str, cmd.std_err))
Esempio n. 7
0
    def ModifyNic(self, request, context):
        errno = ErrNo_pb2.SYS_FAIL

        class_net_path = os.path.join(util.SYS_CLASS_NET, request.nic_name)
        if request.nic_name == "":
            errno = ErrNo_pb2.SYS_FAIL
            return NicManager_pb2.NicModifyReply(errno=errno)
        else:
            if not os.path.exists(class_net_path):
                errno = ErrNo_pb2.SYS_FAIL
                return NicManager_pb2.NicModifyReply(errno=errno)

        nic_object = NicManager.NicHandle(request.nic_name)

        if request.driver_name != "":
            try:
                raw_device = nic_object.get_raw_device()
                new_driver_path = nic_object.get_driver_path_by_driver_name(request.driver_name)
                nic_object.detach_driver()
                nic_object.attach_driver(new_driver_path, raw_device)
                errno = ErrNo_pb2.SYS_OK
            except net_agentd_exception.NetAgentException:
                logging.error(traceback.format_exc())
                logging.error('changer driver failed %s' % request.nic_name)
                errno = ErrNo_pb2.SYS_FAIL
            time.sleep(1)

        if request.mtu != "":
            try:
                nic_object.set_mtu(request.mtu)
                new_mtu = nic_object.get_mtu()
                if new_mtu == request.mtu:
                    errno = ErrNo_pb2.SYS_OK
                else:
                    errno = ErrNo_pb2.SYS_FAIL

            except:
                logging.error(traceback.format_exc())
                logging.error('set mtu failed %s' % request.nic_name)
                errno = ErrNo_pb2.SYS_FAIL

        return NicManager_pb2.NicModifyReply(errno=errno)
Esempio n. 8
0
    def QueryNicList(self, request, context):
        errno = ErrNo_pb2.SYS_FAIL
        nic_names = []
        type = [NicManager_pb2.NicListQueryRequest.ALL_PHY_NIC,
                NicManager_pb2.NicListQueryRequest.FREE_PHY_NIC,
                NicManager_pb2.NicListQueryRequest.VIRTUAL_NIC]

        while True:
            if request.nic_type not in type:
                break

            try:
                nic_names = NicManager.get_nic_list(request.nic_type)
                errno = ErrNo_pb2.SYS_OK
            except net_agentd_exception.NetAgentException:
                logging.error(traceback.format_exc())
                logging.error("QueryNicList failed")

            break

        return NicManager_pb2.NicListQueryReply(nic_names=nic_names, errno=errno)