Ejemplo n.º 1
0
Archivo: nic.py Proyecto: nirs/vdsm
def speed(nic_name):
    """Return the nic speed if it is a legal value, 0 otherwise."""
    interface = iface(nic_name)
    if interface.is_oper_up():
        if dpdk.is_dpdk(nic_name):
            return dpdk.speed(nic_name)
        try:
            return read_speed_using_sysfs(nic_name)
        except Exception:
            logging.debug('cannot read %s speed', nic_name)
    return 0
Ejemplo n.º 2
0
def speed(nic_name):
    """Return the nic speed if it is a legal value, 0 otherwise."""
    interface = iface(nic_name)
    if interface.is_oper_up():
        if dpdk.is_dpdk(nic_name):
            return dpdk.speed(nic_name)
        try:
            return read_speed_using_sysfs(nic_name)
        except Exception:
            logging.debug('cannot read %s speed', nic_name)
    return 0
Ejemplo n.º 3
0
def _generate_iface_stats(interface):
    stats = interface.statistics()
    speed = 0
    if interface.type() == iface.Type.NIC:
        speed = nic.speed(interface.device)
    elif interface.type() == iface.Type.BOND:
        speed = bond.speed(interface.device)
    elif interface.type() == iface.Type.VLAN:
        speed = vlan.speed(interface.device)
    elif interface.type() == iface.Type.DPDK:
        speed = dpdk.speed(interface.device)

    stats['speed'] = speed
    stats['duplex'] = nic.duplex(interface.device)

    return stats
Ejemplo n.º 4
0
def report():
    stats = {}
    for iface_properties in iface.list():
        i = iface.iface(iface_properties['name'])
        stats[i.device] = i.statistics()

        speed = 0
        if i.type() == iface.Type.NIC:
            speed = nic.speed(i.device)
        elif i.type() == iface.Type.BOND:
            speed = bond.speed(i.device)
        elif i.type() == iface.Type.VLAN:
            speed = vlan.speed(i.device)
        elif i.type() == iface.Type.DPDK:
            speed = dpdk.speed(i.device)

        stats[i.device]['speed'] = speed
        stats[i.device]['duplex'] = nic.duplex(i.device)

    return stats
Ejemplo n.º 5
0
def speed(nic_name):
    """Returns the nic speed if it is a legal value, nicName refers to a
    nic and nic is UP, 0 otherwise."""
    try:
        if dpdk.is_dpdk(nic_name) and operstate(nic_name) == OPERSTATE_UP:
            return dpdk.speed(nic_name)
        if operstate(nic_name) == OPERSTATE_UP:
            with io.open('/sys/class/net/%s/speed' % nic_name) as speedFile:
                s = int(speedFile.read())
            # the device may have been disabled/downed after checking
            # so we validate the return value as sysfs may return
            # special values to indicate the device is down/disabled
            if s not in (2**16 - 1, 2**32 - 1) and s > 0:
                return s
    except IOError as ose:
        if ose.errno == errno.EINVAL:
            return _ibHackedSpeed(nic_name)
        else:
            logging.exception('cannot read %s nic speed', nic_name)
    except Exception:
        logging.exception('cannot read %s speed', nic_name)
    return 0
Ejemplo n.º 6
0
Archivo: nics.py Proyecto: EdDev/vdsm
def speed(nic_name):
    """Returns the nic speed if it is a legal value, nicName refers to a
    nic and nic is UP, 0 otherwise."""
    try:
        if dpdk.is_dpdk(nic_name) and operstate(nic_name) == OPERSTATE_UP:
            return dpdk.speed(nic_name)
        if operstate(nic_name) == OPERSTATE_UP:
            with io.open('/sys/class/net/%s/speed' % nic_name) as speedFile:
                s = int(speedFile.read())
            # the device may have been disabled/downed after checking
            # so we validate the return value as sysfs may return
            # special values to indicate the device is down/disabled
            if s not in (2 ** 16 - 1, 2 ** 32 - 1) and s > 0:
                return s
    except IOError as ose:
        if ose.errno == errno.EINVAL:
            return _ibHackedSpeed(nic_name)
        else:
            logging.exception('cannot read %s nic speed', nic_name)
    except Exception:
        logging.exception('cannot read %s speed', nic_name)
    return 0