Exemplo n.º 1
0
 def process_event(self, event):
     mtd = getattr(self.monitor, '{Type}_{Action}'.format(**event), None)
     if mtd:
         mtd(self.cli, **event)
     else:
         logger.debug('no processor to handle %s_%s', event['Type'],
                      event['Action'])
Exemplo n.º 2
0
    def delete(self, service_name):
        logger.debug("delete %s service", service_name)
        if not self.exists(service_name):  # not exists, just return.
            logger.error('try delete %s but not exists', service_name)
            return

        self.configurations[service_name].delete()
        del self.configurations[service_name]  # set service name to empty.
Exemplo n.º 3
0
 def run(self):
     '''
     watch docker event.
     '''
     for event in self.events:
         event_obj = json.loads(
             event.decode('utf-8'))  # docker event encoded in json-format.
         logger.debug('docker event: {}'.format(event_obj))
         self.process_event(event_obj)
Exemplo n.º 4
0
    def load_all(cls, client):
        logger.debug('load all containers.')

        ret = {}

        containers = client.containers.list()
        for container in containers:
            logger.debug('get container %s %s', container.id, container.name)
            obj = cls(container)
            ret[obj.id] = obj

        return ret
Exemplo n.º 5
0
    def __init__(self, container):
        self.name = container.name
        self.image = container.image.tags
        self.id = container.id

        port_mappings = container.ports
        self.port = 0
        for key in port_mappings:
            ports = port_mappings[key]
            for port in ports:
                logger.debug('%s -> %s', key, port['HostPort'])
                if '0.0.0.0' == port['HostIp']:
                    self.port = int(port['HostPort'])

        self.is_running = 'running' == container.status
        self.svc_name = self.get_service_name(container)
        self.auth_backend = self.get_auth_backend(container)
Exemplo n.º 6
0
def generate_to_fp(svc_obj, template, fp):
    logger.debug('generate configure of %s', svc_obj.name)

    auth_backends = svc_obj.auth_backend or config.get('auth.backend')
    need_auth = auth_backends and not svc_obj.auth_bypass and not svc_obj.is_authorize_backend

    if need_auth:
        logger.info('use auth backends: %s', auth_backends)

    params = {'svc': svc_obj,
        'auth': {
            'backend': auth_backends,
            'bypass': not need_auth
        }
    }

    if config.getboolean('template.debug', False):
        logger.debug(template.render(params))

    template.stream(params).dump(fp)
Exemplo n.º 7
0
    def __init__(self, configuration_path=None, nginx_pid_file=None):
        if not nginx_pid_file:
            nginx_pid_file = self.__get_default_nginx_pid()
            logger.info('nginx_pid_file is empty, use default pid file %s',
                        nginx_pid_file)

        if not configuration_path:
            configuration_path = self.__get_default_nginx_conf()
            logger.info(
                'configuration_path is empty, use default configure path %s',
                configuration_path)

        logger.debug("nginx configuration path is %s", configuration_path)
        logger.debug('nginx pid file is %s', nginx_pid_file)

        self.nginx_pid = self.__get_master_pid_from(nginx_pid_file)
        self.configuration_path = configuration_path
        self.configurations = {}

        self.__load_config()
        self.__dump_config()
Exemplo n.º 8
0
 def decode(self, svc):
     logger.debug("try decode %s", svc)
     mapper = json.loads(svc)
     return Service(**mapper)
Exemplo n.º 9
0
 def reload(self):
     try:
         logger.debug("Reload nginx pid %d", self.nginx_pid)
         kill(self.nginx_pid, SIGHUP)
     except Exception as e:
         raise e
Exemplo n.º 10
0
 def delete_host(self, node_id=None, container_id=None):
     logger.debug('delete host of %s %s', node_id, container_id)
     self.hosts = [
         x for x in self.hosts if not self.filter(x, node_id, container_id)
     ]