def craft_client():
    if utils.is_running_in_docker():
        return DockerContainersInterface()

    if not os.path.exists('/run/.containerenv'):
        # NB. CRIO is not fast enough when it comes to creating
        # the mark file after container start.
        # anyway let's try to connect to containerd first when
        # the mark is absent and if it fails because of the socket
        # absence make another attempt after the timeout to detect
        # a ct engine hoping CRIO has created the file finally.
        try:
            return ContainerdContainersInterface(
                ctr.ContainerdContainersInterface.craft_containerd_peer())
        except LookupError:
            time.sleep(3)

    if not os.path.exists('/run/.containerenv'):
        return ContainerdContainersInterface(
            ctr.ContainerdContainersInterface.craft_containerd_peer())

    try:
        return ContainerdContainersInterface(
            cri.CriContainersInterface.craft_crio_peer())
    except LookupError:
        return PodmanContainersInterface()
def craft_client():
    if utils.is_running_in_docker():
        return DockerContainersInterface()

    if not os.path.exists('/run/.containerenv'):
        return CriContainersInterface(
            cri.CriContainersInterface.craft_containerd_peer())

    try:
        return CriContainersInterface(
            cri.CriContainersInterface.craft_crio_peer())
    except LookupError:
        return PodmanContainersInterface()
Exemplo n.º 3
0
    def __init__(self, config, type_info, unit_names, update_process_list=False):
        self.config = config
        self.type_info = type_info
        self.max_cores = 4
        self.max_old_cores = 3
        self.max_new_cores = 1
        self.all_core_file_list = []
        self.tick_count = 0
        self.fail_status_bits = 0
        self.prev_fail_status_bits = 1
        self.instance_id = INSTANCE_ID_DEFAULT
        self.sandesh_instance = sandesh_global
        self.curr_build_info = None
        self.new_build_info = None
        self.hostip = self.config.hostip
        self.hostname = socket.getfqdn(self.hostip) if self.config.hostname is None \
            else self.config.hostname

        self.collector_chksum = 0
        self.random_collectors = list()
        if config.collectors:
            config.collectors.sort()
            self.collector_chksum = hashlib.md5(("".join(config.collectors)).encode()).hexdigest()
            self.random_collectors = random.sample(config.collectors, len(config.collectors))

        ConnectionState.init(
            self.sandesh_instance, self.hostname,
            self.type_info._module_name, self.instance_id,
            staticmethod(ConnectionState.get_conn_state_cb),
            NodeStatusUVE, NodeStatus, self.type_info._object_table,
            self._get_process_state_cb)
        self.sandesh_instance.init_generator(
            self.type_info._module_name, self.hostname,
            self.type_info._node_type_name, self.instance_id,
            self.random_collectors, self.type_info._module_name,
            ServiceHttpPortMap[self.type_info._module_name],
            ['nodemgr.common.sandesh'] + self.type_info._sandesh_packages,
            config=SandeshConfig.from_parser_arguments(self.config))
        self.sandesh_instance.set_logging_params(
            enable_local_log=self.config.log_local,
            category=self.config.log_category,
            level=self.config.log_level,
            file=self.config.log_file,
            enable_syslog=self.config.use_syslog,
            syslog_facility=self.config.syslog_facility)
        self.logger = self.sandesh_instance.logger()

        event_handlers = {}
        event_handlers['PROCESS_STATE'] = self._event_process_state
        event_handlers['PROCESS_COMMUNICATION'] = self._event_process_communication
        event_handlers['PROCESS_LIST_UPDATE'] = self._update_current_processes
        gevent.signal(signal.SIGHUP, self.nodemgr_sighup_handler)
        self.system_data = LinuxSysData(self.msg_log, self.config.corefile_path)
        if DockerProcessInfoManager and (utils.is_running_in_docker()
                                         or utils.is_running_in_kubepod()):
            self.process_info_manager = DockerProcessInfoManager(
            type_info._module_type, unit_names, event_handlers,
            update_process_list)
        else:
            self.msg_log('Node manager could not detect process manager',
                          SandeshLevel.SYS_ERR)
            exit(-1)

        self.process_state_db = self._get_current_processes()
        for group in self.process_state_db:
            self._send_init_info(group)