コード例 #1
0
    def __init__(self, name, init_this_host=False, iface='eth0'):
        """
        :param name:
            name of the LinuxHost
        :param init_this_host:
            if init_this_host is True, will initialize the object by this linux
            . Otherwise, you need to initialize it by yourself.
        """
        super(self.__class__, self).__init__(name)
        # -1 means initialized
        self._dict_info = {
            'iface': iface,
            'ipaddr': '0.0.0.0',
            'hostname': net.get_local_hostname(),
            'cpu_idle': -1,
            'mem_inuse': -1,  # MB
            'mem_total': -1,
            'net_in': -1,  # kb
            'net_out': -1  # kb
        }

        if init_this_host:
            self._dict_info['ipaddr'] = net.get_hostip()
            cpuinfo = linux.get_cpu_usage(1)
            meminfo = linux.get_meminfo()
            self._dict_info['net_in'] = linux.get_net_recv_speed(
                self._dict_info['iface'], 1)
            self._dict_info['net_out'] = linux.get_net_transmit_speed(
                self._dict_info['iface'], 1)
            # pylint: disable=E1101
            self._dict_info['cpu_idle'] = cpuinfo.idle
            # pylint: disable=E1101
            self._dict_info['mem_inuse'] = meminfo.total - meminfo.free
コード例 #2
0
ファイル: heartbeat.py プロジェクト: legendtkl/CUP
    def __init__(self, name, init_this_host=False, iface='eth0'):
        """
        :param name:
            name of the LinuxHost
        :param init_this_host:
            if init_this_host is True, will initialize the object by this linux
            . Otherwise, you need to initialize it by yourself.
        """
        super(self.__class__, self).__init__(name)
        # -1 means initialized
        self._dict_info = {
            'iface':   iface,
            'ipaddr': '0.0.0.0',
            'hostname': net.get_local_hostname(),
            'cpu_idle': -1,
            'mem_inuse': -1,        # MB
            'mem_total': -1,
            'net_in': -1,        # kb
            'net_out': -1      # kb
        }

        if init_this_host:
            self._dict_info['ipaddr'] = net.get_hostip()
            cpuinfo = linux.get_cpu_usage(1)
            meminfo = linux.get_meminfo()
            self._dict_info['net_in'] = linux.get_net_recv_speed(
                self._dict_info['iface'], 1
            )
            self._dict_info['net_out'] = linux.get_net_transmit_speed(
                self._dict_info['iface'], 1
            )
            # pylint: disable=E1101
            self._dict_info['cpu_idle'] = cpuinfo.idle
            # pylint: disable=E1101
            self._dict_info['mem_inuse'] = meminfo.total - meminfo.free
コード例 #3
0
 def _lost_heartbeat(self):
     hostname = net.get_local_hostname()
     self._hb.refresh(hostname, heartbeat.Device(hostname))
     lost_devices = self._hb.get_lost()
     self._check(hostname, lost_devices, should_in=False)
     time.sleep(6)
     lost_devices = self._hb.get_lost()
     self._check(hostname, lost_devices, should_in=True)
     self._hb.cleanup_oldlost(self._tmpfile)
コード例 #4
0
 def _lost_heartbeat(self):
     hostname = net.get_local_hostname()
     self._hb.refresh(hostname, heartbeat.Device(hostname))
     lost_devices = self._hb.get_lost()
     self._check(hostname, lost_devices, should_in=False)
     time.sleep(6)
     lost_devices = self._hb.get_lost()
     self._check(hostname, lost_devices, should_in=True)
     self._hb.cleanup_oldlost(self._tmpfile)
コード例 #5
0
def test_port_free():
    """test port_listened"""
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.bind((net.get_hostip(), 61113))
    sock.settimeout(1)
    net.set_sock_reusable(sock)
    sock.listen(1)
    ret = net.localport_free(61113)
    unittest.assert_eq(ret, False)
    unittest.assert_eq(net.port_listened(net.get_local_hostname(), 61113),
                       True)
    sock.close()
コード例 #6
0
ファイル: heartbeat.py プロジェクト: shiqianwei0508/CUP
    def __init__(self, name, init_this_host=False, iface='eth0', port=0):
        """
        :param name:
            name of the LinuxHost
        :param init_this_host:
            if init_this_host is True, will initialize the object by this linux
            . Otherwise, you need to initialize it by yourself.
        :exception socket.gaierror :
            if we cannot get the ip of the host, the object construction
            may raise socket.gaierror exception.
            You have to code {try:  catch socket.gaierror as err:}
        """
        Device.__init__(self, name)
        # -1 means initialized
        self._dict_info = {
            'iface': iface,
            'ipaddr': '0.0.0.0',
            'port': 0,
            'hostname': net.get_local_hostname(),
            'cpu_idle': -1,
            'mem_inuse': -1,  # MB
            'mem_total': -1,
            'net_in': -1,  # kb
            'net_out': -1  # kb
        }

        if init_this_host:
            self._dict_info['ipaddr'] = net.get_hostip()
            self._dict_info['port'] = port
            cpuinfo = linux.get_cpu_usage(1)
            meminfo = linux.get_meminfo()
            self._dict_info['net_in'] = linux.get_net_recv_speed(
                self._dict_info['iface'], 1)
            self._dict_info['net_out'] = linux.get_net_transmit_speed(
                self._dict_info['iface'], 1)
            # pylint: disable=E1101
            self._dict_info['cpu_idle'] = cpuinfo.idle
            # pylint: disable=E1101
            self._dict_info['mem_inuse'] = meminfo.total - meminfo.free
            self._dict_info['mem_total'] = meminfo.total