'Connect to the Docker server.'

def connect(self, version=None):

    if (hasattr(docker, 'from_env') and (version is not None)):
        ret = docker.from_env()
    else:
        ret = self.__connect_old(version=version)
    try:
        ret.version()
    except requests.exceptions.ConnectionError as e:
        logger.debug(("docker    plugin    -    Can't    connect    to    the    Docker    server    (%s)" % e))
        return None
    except docker.errors.APIError as e:
        if (version is None):
            logger.debug(('docker    plugin    -    Docker    API    error    (%s)' % e))
            version = re.search('(?:server    API    version|server)\\:\\    (.*)\\)".*\\)', str(e))
            if version:
                logger.debug(('docker    plugin    -    Try    connection    with    Docker    API    version    %s' % version.group(1)))
                ret = self.connect(version=version.group(1))
            else:
                logger.debug('docker    plugin    -    Can    not    retreive    Docker    server    version')
                ret = None
        else:
            logger.error(('docker    plugin    -    Docker    API    error    (%s)' % e))
            ret = None
    except Exception as e:
        logger.error(("docker    plugin    -    Can't    connect    to    the    Docker    server    (%s)" % e))
        ret = None
    if (ret is None):
        logger.debug('docker    plugin    -    Docker    plugin    is    disable    because    an    error    has    been    detected')
    return ret
