Exemple #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
Exemple #2
0
 def __init__(self, conf_file):
     # load conf
     self._load_conf(conf_file)
     # control service
     self._control_service = control.ControlService(
         net.get_hostip(), int(self._conf_dict['control']['port']),
         self._conf_dict)
Exemple #3
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
Exemple #4
0
 def __init__(self, conf_file):
     # load conf
     self._load_conf(conf_file)
     # control service
     self._control_service = control.ControlService(
         net.get_hostip(), int(self._conf_dict['control']['port']),
         self._conf_dict
     )
Exemple #5
0
 def __init__(self, conf_file):
     # load conf
     self._load_conf(conf_file)
     # control service
     ipaddr = net.get_hostip()
     port = int(self._conf_dict['control']['port'])
     # control service which control msg sending and receiving.
     self._control_service = control.ControlService(ipaddr, port,
                                                    self._conf_dict)
     log.info('ip:{0}, port:{1}'.format(ipaddr, port))
     self._stop_heart_beat = False
Exemple #6
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()
Exemple #7
0
 def __init__(self, ip, port, confdict):
     msgcenter.IMessageCenter.__init__(self, ip, port)
     # service.BaseService.__init__(self)
     # status, 0 inited, 1 running 2 stopping, 3 stopped
     self._confdict = confdict
     self._status = service.ServiceStatus()
     self._status.set_status(self._status.INITED)
     self._type_man = msg.CMsgType()
     self._type_man.register_types(settings.MSG_TYPE2NUM)
     self._executor = executor.ExecutionService(
         int(self._confdict['control']['queue_exec_thdnum']),
         int(self._confdict['control']['queue_delay_exe_thdnum']))
     self._agent_ipport = (ip, port)
     self._master_ipport = (net.get_hostip(
         self._confdict['control']['master_ip']),
                            int(self._confdict['control']['master_port']))
     self._last_heartbeat = -1
Exemple #8
0
 def __init__(self, ip, port, confdict):
     msgcenter.IMessageCenter.__init__(self, ip, port)
     # service.BaseService.__init__(self)
     # status, 0 inited, 1 running 2 stopping, 3 stopped
     self._confdict = confdict
     self._status = service.ServiceStatus()
     self._status.set_status(self._status.INITED)
     self._type_man = msg.CMsgType()
     self._type_man.register_types(settings.MSG_TYPE2NUM)
     self._executor = executor.ExecutionService(
         int(self._confdict['control']['queue_exec_thdnum']),
         int(self._confdict['control']['queue_delay_exe_thdnum'])
     )
     self._agent_ipport = (ip, port)
     self._master_ipport = (
         net.get_hostip(self._confdict['control']['master_ip']),
         int(self._confdict['control']['master_port'])
     )
     self._last_heartbeat = -1
Exemple #9
0
    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