Ejemplo n.º 1
0
def Cat(file_path):
    try:
        if not os.path.isfile(file_path):
            raise store_exception.StoreDiskManagerSysfsError(
                'file %s missing' % (file_path))
        return cat(file_path).strip()
    except OSError as e:
        logging.error('failed to cat %s' % (file_path))
        raise store_exception.StoreDiskManagerSysfsError('%s' % (e))
    except UnicodeDecodeError:
        logging.error('failed to cat %s' % (file_path))
        return ''
Ejemplo n.º 2
0
    def get_rx_errors(self):
        rx_errors = ""

        if self._class_net_path is not None:
            try:
                path = os.path.join(self._class_net_path, "statistics/rx_errors")
                rx_errors = sys_util.cat(path).strip()
            except:
                logging.error("%s get rx_errors failed" % self._nic_name)
        else:
            raise net_agentd_exception.NetAgentException("%s doesnt exist" % self._nic_name)

        return rx_errors
Ejemplo n.º 3
0
    def get_duplex(self):
        duplex = ""

        if self._class_net_path is not None:
            try:
                path = os.path.join(self._class_net_path, "duplex")
                duplex = sys_util.cat(path).strip()
            except:
                logging.error("%s get duplex failed" % self._nic_name)
        else:
            raise net_agentd_exception.NetAgentException("%s doesnt exist" % self._nic_name)

        return duplex
Ejemplo n.º 4
0
    def get_tx_dropped(self):
        tx_dropped = ""

        if self._class_net_path is not None:
            try:
                path = os.path.join(self._class_net_path, "statistics/tx_dropped")
                tx_dropped = sys_util.cat(path).strip()
            except:
                logging.error("%s get tx_dropped failed" % self._nic_name)
        else:
            raise net_agentd_exception.NetAgentException("%s doesnt exist" % self._nic_name)

        return tx_dropped
Ejemplo n.º 5
0
    def get_carrier(self):
        carrier = ""

        if self._class_net_path is not None:
            try:
                path = os.path.join(self._class_net_path, "carrier")
                carrier = sys_util.cat(path).strip()
            except:
                logging.error("%s get carrier failed" % self._nic_name)
        else:
            raise net_agentd_exception.NetAgentException("%s doesnt exist" % self._nic_name)

        return carrier
Ejemplo n.º 6
0
    def get_mtu(self):
        mtu = ""

        if self._class_net_path is not None:
            try:
                path = os.path.join(self._class_net_path, "mtu")
                mtu = sys_util.cat(path).strip()
            except:
                raise net_agentd_exception.NetAgentException("%s get mtu failed" % self._nic_name)
        else:
            raise net_agentd_exception.NetAgentException("%s doesnt exist" % self._nic_name)

        return mtu
Ejemplo n.º 7
0
    def get_mac_address(self):
        mac_address = ""

        if self._class_net_path is not None:
            try:
                path = os.path.join(self._class_net_path, "address")
                mac_address = sys_util.cat(path).strip()
            except:
                logging.error("%s get mac address failed" % self._nic_name)
        else:
            raise net_agentd_exception.NetAgentException("%s doesnt exist" % self._nic_name)

        return mac_address
Ejemplo n.º 8
0
    def get_numa(self):
        numa = ""

        if self._class_net_path is not None:
            try:
                numa_node_path = os.path.join(self._class_net_path, "device/numa_node")
                if os.path.exists(numa_node_path):
                    numa = sys_util.cat(numa_node_path).strip()
            except:
                logging.error("%s get numa failed" % self._nic_name)
        else:
            raise net_agentd_exception.NetAgentException("%s doesnt exist" % self._nic_name)

        return numa
Ejemplo n.º 9
0
    def test_file_op(self):
        import tempfile
        import os

        (lvl, tmp) = tempfile.mkstemp(prefix=__name__, text=True)

        randstr = _genrandstr(120)
        echo(tmp, randstr)
        c = cat(tmp)
        print(randstr)
        print(c)
        if c.strip() == randstr:
            print("ok")
            assert 1
        else:
            print("not match")
            assert 0

        if os.path.isfile(tmp):
            os.remove(tmp)