Ejemplo n.º 1
0
    def __init__(self, _exit, verbose):
        # setup_client
        try:
            # setup client depending if running on linux or using boot2docker (osx/win)
            if sys.platform == 'linux':
                self.client = docker_py.Client(version='auto')
            else:
                # get b2d ip
                self.ip = str(sh.boot2docker.ip()).strip()

                try:
                    # try secure connection first
                    kw = kwargs_from_env(assert_hostname=False)
                    self.client = docker_py.Client(version='auto', **kw)
                except docker_py.errors.DockerException as e:
                    # shit - some weird boot2docker, python, docker-py, requests, and ssl error
                    # https://github.com/docker/docker-py/issues/465
                    if verbose:
                        log.debug(e)
                    log.warn("Cannot connect securely to Docker, trying insecurely")
                    kw = kwargs_from_env(assert_hostname=False)
                    if 'tls' in kw:
                        kw['tls'].verify = False
                    self.client = docker_py.Client(version='auto', **kw)

        except Exception as e:
            if verbose:
                log.error("Could not connect to Docker - try running 'docker info' first")
                if sys.platform != 'linux':
                    log.error("Please ensure you've run 'boot2docker up' and 'boot2docker shellinit' first and have added the ENV VARs it suggests")
            if _exit:
                raise e
Ejemplo n.º 2
0
 def _process_request(self, data):
     try:
         self.request = json.loads(data.decode('utf-8'))
         rpc.add_get_id(self.request)
         log.info("Request - {}".format(self.request))
         if ((self.request['service'] != self.service_short_name) and ((self.request['service']+':latest') != self.service_short_name)):
             log.warn("Service request ({}) sent to wrong service ({})".format(self.request['service'], self.service_short_name))
     except Exception as e:
         _e = rpc.exc_to_json_error(rpc.ParseError(dict(exception=repr(e))))
         return True, _e
     else:
         return False, self.request