Example #1
0
    def __init__(self, *args, **kw_args):
        """Instantiate the database client.

        All parameters will be passed on
        to pmeth:`etcd3.Client`.
        """
        self._client = etcd3.Client(*args, **kw_args)
Example #2
0
    def __init__(self,
                 opts,
                 encode_keys=None,
                 encode_values=None,
                 raw_keys=False,
                 raw_values=False,
                 unicode_errors=None,
                 **kwargs):
        if not HAS_ETCD_V3:
            raise EtcdLibraryNotInstalled(
                "Don't have etcd3-py, need to install it.")
        log.debug("etcd_util has the libraries needed for etcd v3")

        super().__init__(opts, **kwargs)

        if self.conf.get("etcd.require_v2", True):
            raise IncompatibleEtcdRequirements(
                "Can't create v3 with a v2 requirement")

        self.encode_keys = encode_keys or self.conf.get(
            "etcd.encode_keys", False)
        self.encode_values = encode_values or self.conf.get(
            "etcd.encode_values", True)
        self.raw_keys = raw_keys or self.conf.get("etcd.raw_keys", False)
        self.raw_values = raw_values or self.conf.get("etcd.raw_values", False)
        self.unicode_errors = unicode_errors or self.conf.get(
            "etcd.unicode_errors", "surrogateescape")

        # etcd3-py uses verify instead of ca_cert
        self.xargs["verify"] = self.xargs.pop("ca_cert", None)
        self.client = etcd3.Client(host=self.host,
                                   port=self.port,
                                   **self.xargs)
Example #3
0
 def client(self):
     if self._client is None:
         i = 0
         while i < self.retry_reconnect:
             try:
                 self.rotate()
                 ep = self.current_endpoint()
                 log.info('etcd client using endpoint %s' % ep)
                 self._client = etcd3.Client(host=ep.address,
                                             port=ep.port,
                                             timeout=ep.timeout)
                 self._client.status()
                 break
             except Exception:
                 log.exception('error connecting to etcd')
             i += 1
         if i == self.retry_reconnect:
             raise EtcdConnectionError('failed connecting to etcd '
                                       'after %s retries' % i)
     return self._client
Example #4
0
 def __init__(self, *args, **kw_args):
     """Instantiate the database client."""
     self._client = etcd3.Client(*args, **kw_args)
Example #5
0
 def __init__(self, etcd_cfg: etcd_config):
     self.__client = etcd3.Client(max_retries=3)