当前位置: 首页>>代码示例>>Python>>正文


Python etcd.EtcdException方法代码示例

本文整理汇总了Python中etcd.EtcdException方法的典型用法代码示例。如果您正苦于以下问题:Python etcd.EtcdException方法的具体用法?Python etcd.EtcdException怎么用?Python etcd.EtcdException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在etcd的用法示例。


在下文中一共展示了etcd.EtcdException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: lock

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdException [as 别名]
def lock(self, key, expiration=DEFAULT_LOCK_EXPIRATION):
        assert not self.is_canceller_only

        try:
            await (
                self._etcd_client.write(
                    key, {}, prevExist=False, ttl=self._sanity_check_ttl(expiration)
                )
            )
            return True
        except (KeyError, etcd.EtcdKeyError):
            return False
        except etcd.EtcdConnectionFailed:
            logger.exception("Could not get etcd atomic lock as etcd is down")
            return False
        except etcd.EtcdException as ex:
            raise OrchestratorError(ex) 
开发者ID:quay,项目名称:quay,代码行数:19,代码来源:orchestrator.py

示例2: _refresh_machines_cache

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdException [as 别名]
def _refresh_machines_cache(self, updating_cache=False):
        if self._use_proxies:
            self._machines_cache = self._get_machines_cache_from_config()
        else:
            try:
                self._machines_cache = self.machines
            except etcd.EtcdConnectionFailed:
                if updating_cache:
                    raise etcd.EtcdException("Could not get the list of servers, "
                                             "maybe you provided the wrong "
                                             "host(s) to connect to?")
                return

        if self._base_uri not in self._machines_cache:
            self.set_base_uri(self._machines_cache[0])
        self._machines_cache_updated = time.time() 
开发者ID:zalando,项目名称:patroni,代码行数:18,代码来源:etcd.py

示例3: _retry_on_cred_expiry

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdException [as 别名]
def _retry_on_cred_expiry(func):
    """Wraps etcd call to automtically regenerate expired credentials"""
    def _wrapped_func(*args, **kwargs):
        while True:
            try:
                return func(*args, **kwargs)
            except etcd.EtcdException as e:
                args[0]._try_renew_credential(e) # pylint: disable=W0212
    return _wrapped_func 
开发者ID:cea-hpc,项目名称:pcocc,代码行数:11,代码来源:Batch.py

示例4: retry_if_etcd_error

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdException [as 别名]
def retry_if_etcd_error(exception):
    return isinstance(exception, EtcdException) and (not isinstance(exception, EtcdKeyNotFound)) 
开发者ID:laincloud,项目名称:console,代码行数:4,代码来源:utils.py

示例5: get_prefixed_keys

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdException [as 别名]
def get_prefixed_keys(self, prefix):
        assert not self.is_canceller_only

        try:
            etcd_result = await self._etcd_client.read(prefix, recursive=True)
            return {leaf.key: leaf.value for leaf in etcd_result.leaves}
        except etcd.EtcdKeyError:
            raise KeyError
        except etcd.EtcdConnectionFailed as ex:
            raise OrchestratorConnectionError(ex)
        except etcd.EtcdException as ex:
            raise OrchestratorError(ex) 
开发者ID:quay,项目名称:quay,代码行数:14,代码来源:orchestrator.py

示例6: get_key

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdException [as 别名]
def get_key(self, key):
        assert not self.is_canceller_only

        try:
            # Ignore pylint: the value property on EtcdResult is added dynamically using setattr.
            etcd_result = await self._etcd_client.read(key)
            return etcd_result.value
        except etcd.EtcdKeyError:
            raise KeyError
        except etcd.EtcdConnectionFailed as ex:
            raise OrchestratorConnectionError(ex)
        except etcd.EtcdException as ex:
            raise OrchestratorError(ex) 
开发者ID:quay,项目名称:quay,代码行数:15,代码来源:orchestrator.py

示例7: delete_key

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdException [as 别名]
def delete_key(self, key):
        assert not self.is_canceller_only

        try:
            await self._etcd_client.delete(key)
        except etcd.EtcdKeyError:
            raise KeyError
        except etcd.EtcdConnectionFailed as ex:
            raise OrchestratorConnectionError(ex)
        except etcd.EtcdException as ex:
            raise OrchestratorError(ex) 
开发者ID:quay,项目名称:quay,代码行数:13,代码来源:orchestrator.py

示例8: try_cancel_build

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdException [as 别名]
def try_cancel_build(self, build_uuid):
        """
        Writes etcd message to cancel build_uuid.
        """
        logger.debug("Cancelling build %s".format(build_uuid))
        try:
            self._etcd_client.write(
                "{}{}".format(self._cancel_prefix, build_uuid), build_uuid, ttl=60
            )
            return True
        except etcd.EtcdException:
            logger.exception("Failed to write to etcd client %s", build_uuid)
            return False 
开发者ID:quay,项目名称:quay,代码行数:15,代码来源:etcd_canceller.py

示例9: handle_errors

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdException [as 别名]
def handle_errors(fn):
    """
    Decorator function to decorate Datastore API methods to handle common
    exception types and re-raise as datastore specific errors.
    :param fn: The function to decorate.
    :return: The decorated function.
    """
    def wrapped(*args, **kwargs):
        try:
            return fn(*args, **kwargs)
        except etcd.EtcdException as e:
            # Don't leak out etcd exceptions.
            raise DataStoreError("%s: Error accessing etcd (%s).  Is etcd "
                                 "running?" % (fn.__name__, e.message))
    return wrapped 
开发者ID:projectcalico,项目名称:libcalico,代码行数:17,代码来源:datastore.py

示例10: _do_http_request

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdException [as 别名]
def _do_http_request(self, retry, machines_cache, request_executor, method, path, fields=None, **kwargs):
        some_request_failed = False
        for i, base_uri in enumerate(machines_cache):
            if i > 0:
                logger.info("Retrying on %s", base_uri)
            try:
                response = request_executor(method, base_uri + path, fields=fields, **kwargs)
                response.data.decode('utf-8')
                self._check_cluster_id(response)
                if some_request_failed:
                    self.set_base_uri(base_uri)
                    self._refresh_machines_cache()
                return response
            except (HTTPError, HTTPException, socket.error, socket.timeout) as e:
                self.http.clear()
                # switch to the next etcd node because we don't know exactly what happened,
                # whether the key didn't received an update or there is a network problem.
                if not retry and i + 1 < len(machines_cache):
                    self.set_base_uri(machines_cache[i + 1])
                if (isinstance(fields, dict) and fields.get("wait") == "true" and
                        isinstance(e, (ReadTimeoutError, ProtocolError))):
                    logger.debug("Watch timed out.")
                    raise etcd.EtcdWatchTimedOut("Watch timed out: {0}".format(e), cause=e)
                logger.error("Request to server %s failed: %r", base_uri, e)
                logger.info("Reconnection allowed, looking for another server.")
                if not retry:
                    raise etcd.EtcdException('{0} {1} request failed'.format(method, path))
                some_request_failed = True

        raise etcd.EtcdConnectionFailed('No more machines in the cluster') 
开发者ID:zalando,项目名称:patroni,代码行数:32,代码来源:etcd.py

示例11: _load_machines_cache

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdException [as 别名]
def _load_machines_cache(self):
        """This method should fill up `_machines_cache` from scratch.
        It could happen only in two cases:
        1. During class initialization
        2. When all etcd members failed"""

        self._update_machines_cache = True

        if 'srv' not in self._config and 'host' not in self._config and 'hosts' not in self._config:
            raise Exception('Neither srv, hosts, host nor url are defined in etcd section of config')

        machines_cache = self._get_machines_cache_from_config()
        # Can not bootstrap list of etcd-cluster members, giving up
        if not machines_cache:
            raise etcd.EtcdException

        # enforce resolving dns name,they might get new ips
        self._update_dns_cache(self._dns_resolver.remove, machines_cache)

        # The etcd cluster could change its topology over time and depending on how we resolve the initial
        # topology (list of hosts in the Patroni config or DNS records, A or SRV) we might get into the situation
        # the the real topology doesn't match anymore with the topology resolved from the configuration file.
        # In case if the "initial" topology is the same as before we will not override the `_machines_cache`.
        ret = set(machines_cache) != set(self._initial_machines_cache)
        if ret:
            self._initial_machines_cache = self._machines_cache = machines_cache

            # After filling up the initial list of machines_cache we should ask etcd-cluster about actual list
            self._refresh_machines_cache(True)

        self._update_machines_cache = False
        return ret 
开发者ID:zalando,项目名称:patroni,代码行数:34,代码来源:etcd.py

示例12: catch_etcd_errors

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdException [as 别名]
def catch_etcd_errors(func):
        def wrapper(self, *args, **kwargs):
            try:
                retval = func(self, *args, **kwargs) is not None
                self._has_failed = False
                return retval
            except (RetryFailedError, etcd.EtcdException) as e:
                self._handle_exception(e)
                return False
            except Exception as e:
                self._handle_exception(e, raise_ex=EtcdError('unexpected error'))

        return wrapper 
开发者ID:zalando,项目名称:patroni,代码行数:15,代码来源:etcd.py

示例13: watch

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdException [as 别名]
def watch(self, leader_index, timeout):
        if self.__do_not_watch:
            self.__do_not_watch = False
            return True

        if leader_index:
            end_time = time.time() + timeout

            while timeout >= 1:  # when timeout is too small urllib3 doesn't have enough time to connect
                try:
                    self._client.watch(self.leader_path, index=leader_index, timeout=timeout + 0.5)
                    self._has_failed = False
                    # Synchronous work of all cluster members with etcd is less expensive
                    # than reestablishing http connection every time from every replica.
                    return True
                except etcd.EtcdWatchTimedOut:
                    self._has_failed = False
                    return False
                except (etcd.EtcdEventIndexCleared, etcd.EtcdWatcherCleared):  # Watch failed
                    self._has_failed = False
                    return True  # leave the loop, because watch with the same parameters will fail anyway
                except etcd.EtcdException as e:
                    self._handle_exception(e, 'watch', True)

                timeout = end_time - time.time()

        try:
            return super(Etcd, self).watch(None, timeout)
        finally:
            self.event.clear() 
开发者ID:zalando,项目名称:patroni,代码行数:32,代码来源:etcd.py

示例14: etcd_watch

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdException [as 别名]
def etcd_watch(self, key, index=None, timeout=None, recursive=None):
    if timeout == 2.0:
        raise etcd.EtcdWatchTimedOut
    elif timeout == 5.0:
        return etcd.EtcdResult('delete', {})
    elif 5 < timeout <= 10.0:
        raise etcd.EtcdException
    elif timeout == 20.0:
        raise etcd.EtcdEventIndexCleared 
开发者ID:zalando,项目名称:patroni,代码行数:11,代码来源:test_etcd.py

示例15: test_api_execute

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdException [as 别名]
def test_api_execute(self, mock_machines):
        mock_machines.__get__ = Mock(return_value=['http://localhost:4001', 'http://localhost:2379'])
        self.assertRaises(ValueError, self.client.api_execute, '', '')
        self.client._base_uri = 'http://localhost:4001'
        self.assertRaises(etcd.EtcdException, self.client.api_execute, '/', 'POST', timeout=0)
        self.client._base_uri = 'http://localhost:4001'
        rtry = Retry(deadline=10, max_delay=1, max_tries=-1, retry_exceptions=(etcd.EtcdLeaderElectionInProgress,))
        rtry(self.client.api_execute, '/', 'POST', timeout=0, params={'retry': rtry})
        self.client._machines_cache_updated = 0
        self.client.api_execute('/', 'POST', timeout=0)
        self.client._machines_cache = [self.client._base_uri]
        self.assertRaises(etcd.EtcdWatchTimedOut, self.client.api_execute, '/timeout', 'POST', params={'wait': 'true'})
        self.assertRaises(etcd.EtcdWatchTimedOut, self.client.api_execute, '/timeout', 'POST', params={'wait': 'true'})
        self.assertRaises(etcd.EtcdException, self.client.api_execute, '/', '')

        with patch.object(Client, '_calculate_timeouts', Mock(side_effect=[(1, 1, 0), (1, 1, 0), (0, 1, 0)])),\
                patch.object(Client, '_load_machines_cache', Mock(side_effect=Exception)):
            self.client.http.request = Mock(side_effect=socket.error)
            self.assertRaises(etcd.EtcdException, rtry, self.client.api_execute, '/', 'GET', params={'retry': rtry})

        with patch.object(Client, '_calculate_timeouts', Mock(side_effect=[(1, 1, 0), (1, 1, 0), (0, 1, 0)])),\
                patch.object(Client, '_load_machines_cache', Mock(return_value=True)):
            self.assertRaises(etcd.EtcdException, rtry, self.client.api_execute, '/', 'GET', params={'retry': rtry})

        with patch.object(Client, '_do_http_request', Mock(side_effect=etcd.EtcdException)):
            self.client._read_timeout = 0.01
            self.assertRaises(etcd.EtcdException, self.client.api_execute, '/', 'GET') 
开发者ID:zalando,项目名称:patroni,代码行数:29,代码来源:test_etcd.py


注:本文中的etcd.EtcdException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。