Exemplo n.º 1
0
    def refresh_container_list():
        all_cnames = dict()

        tnow = datetime.datetime.now(pytz.utc)
        tmin = datetime.datetime(datetime.MINYEAR, 1, 1, tzinfo=pytz.utc)
        exp = APIContainer.EXPIRE_SECS
        stop_responded_before = (tnow - datetime.timedelta(seconds=exp)) if (
            exp > 0) else tmin

        for c in BaseContainer.api_containers(allcontainers=True):
            cid = c['Id']
            cont = APIContainer(cid)
            cname = cont.get_name()
            api_name = cont.get_api_name()
            APIContainer.log_debug("examining container %s (%s), api:%r", cid,
                                   cname, api_name)
            if api_name is None:
                continue

            c_is_active = cont.is_running() or cont.is_restarting()
            if not c_is_active:
                cont.delete()
                continue

            APIContainer.register_api_container(api_name, cname)
            last_ping = APIContainer._get_last_ping(cname)
            if (last_ping is not None) and c_is_active and (
                    last_ping < stop_responded_before):
                APIContainer.log_warn(
                    "Terminating possibly unresponsive container %s.",
                    cont.debug_str())
                cont.kill()
                cont.delete()
            all_cnames[cname] = cid

        # delete ping entries for non existent containers
        for cname in APIContainer.PINGS.keys():
            if cname not in all_cnames:
                del APIContainer.PINGS[cname]

        # delete non existent containers from container list
        dellist = []
        for (api_name, clist) in APIContainer.API_CONTAINERS.iteritems():
            clist[:] = [x for x in clist if x in all_cnames]
            if len(clist) == 0:
                dellist.append(api_name)

        for api_name in dellist:
            del APIContainer.API_CONTAINERS[api_name]
Exemplo n.º 2
0
    def refresh_container_list():
        all_cnames = dict()

        tnow = datetime.datetime.now(pytz.utc)
        tmin = datetime.datetime(datetime.MINYEAR, 1, 1, tzinfo=pytz.utc)
        exp = APIContainer.EXPIRE_SECS
        stop_responded_before = (tnow - datetime.timedelta(seconds=exp)) if (exp > 0) else tmin

        for c in BaseContainer.api_containers(allcontainers=True):
            cid = c['Id']
            cont = APIContainer(cid)
            cname = cont.get_name()
            api_name = cont.get_api_name()
            APIContainer.log_debug("examining container %s (%s), api:%r", cid, cname, api_name)
            if api_name is None:
                continue

            c_is_active = cont.is_running() or cont.is_restarting()
            if not c_is_active:
                cont.delete()
                continue

            APIContainer.register_api_container(api_name, cname)
            last_ping = APIContainer._get_last_ping(cname)
            if (last_ping is not None) and c_is_active and (last_ping < stop_responded_before):
                APIContainer.log_warn("Terminating possibly unresponsive container %s.", cont.debug_str())
                cont.kill()
                cont.delete()
            all_cnames[cname] = cid

        # delete ping entries for non existent containers
        for cname in APIContainer.PINGS.keys():
            if cname not in all_cnames:
                del APIContainer.PINGS[cname]

        # delete non existent containers from container list
        dellist = []
        for (api_name, clist) in APIContainer.API_CONTAINERS.iteritems():
            clist[:] = [x for x in clist if x in all_cnames]
            if len(clist) == 0:
                dellist.append(api_name)

        for api_name in dellist:
            del APIContainer.API_CONTAINERS[api_name]