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


Python etcd.Client方法代码示例

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


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

示例1: _update_docker_list

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import Client [as 别名]
def _update_docker_list(self):
        """
        Communicate with the etcd service, then update the docker list.
        """
        client = etcd.Client(host=self.etcd_host, port=self.etcd_port)
        try:
            result = client.get('/registry/minions/')
        except Exception:
            logger.error("Can't connect to etcd host %s:%s" % (self.etcd_host,
                self.etcd_port))
            return []

        hosts = []
        for child in result.children:
            hosts.append(child.key.split('/')[-1])
        return sorted(hosts) 
开发者ID:wangtaoking1,项目名称:hummer,代码行数:18,代码来源:schedule.py

示例2: keyval_client

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import Client [as 别名]
def keyval_client(self):
        try:
            return self._keyval_client
        except AttributeError:
            hosts_tuple = [ (host, self._etcd_client_port) for
                            host in self._etcd_servers ]
            random.shuffle(hosts_tuple)
            hosts_tuple = tuple(hosts_tuple)
            logging.debug('Starting etcd client')
            self._keyval_client = etcd.Client(
                host=hosts_tuple,
                ca_cert=self._etcd_ca_cert,
                protocol=self._etcd_protocol,
                allow_reconnect=True,
                read_timeout=10,
                username=self._get_keyval_username(),
                password=self._get_keyval_credential())

            logging.info('Started etcd client')
            self._last_cred_renew = datetime.datetime.utcnow()

            return self._keyval_client 
开发者ID:cea-hpc,项目名称:pcocc,代码行数:24,代码来源:Batch.py

示例3: __init__

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import Client [as 别名]
def __init__(self, config):
        etcd_host = config.get("ETCD_HOST", "127.0.0.1")
        etcd_port = config.get("ETCD_PORT", 2379)
        etcd_ca_cert = config.get("ETCD_CA_CERT", None)
        etcd_auth = config.get("ETCD_CERT_AND_KEY", None)
        if etcd_auth is not None:
            etcd_auth = tuple(etcd_auth)

        etcd_protocol = "http" if etcd_auth is None else "https"
        logger.debug("Connecting to etcd on %s:%s", etcd_host, etcd_port)
        self._cancel_prefix = config.get("ETCD_CANCEL_PREFIX", "cancel/")
        self._etcd_client = etcd.Client(
            host=etcd_host,
            port=etcd_port,
            cert=etcd_auth,
            ca_cert=etcd_ca_cert,
            protocol=etcd_protocol,
            read_timeout=5,
        ) 
开发者ID:quay,项目名称:quay,代码行数:21,代码来源:etcd_canceller.py

示例4: get_services

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import Client [as 别名]
def get_services():

    host, port = get_etcd_addr()
    client = etcd.Client(host=host, port=int(port))
    backends = client.read('/backends', recursive = True)
    services = {}

    for i in backends.children:

        if i.key[1:].count("/") != 2:
            continue

        ignore, service, container = i.key[1:].split("/")
        endpoints = services.setdefault(service, dict(port="", backends=[]))
        if container == "port":
            endpoints["port"] = i.value
            continue
        endpoints["backends"].append(dict(name=container, addr=i.value))
    return services 
开发者ID:jwilder,项目名称:docker-discover,代码行数:21,代码来源:main.py

示例5: test_endpoints_single_override

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import Client [as 别名]
def test_endpoints_single_override(self, m_etcd_client, m_getenv):
        """ Test etcd endpoint overriding with a single endpoint."""
        etcd_env_dict = {
            ETCD_AUTHORITY_ENV   : "127.0.1.1:2380",
            ETCD_SCHEME_ENV      : "https",
            ETCD_ENDPOINTS_ENV   : "http://127.0.0.1:2379",
            ETCD_KEY_FILE_ENV    : "",
            ETCD_CERT_FILE_ENV   : "",
            ETCD_CA_CERT_FILE_ENV: ""
        }

        def m_getenv_return(key, *args):
            return etcd_env_dict[key]
        m_getenv.side_effect = m_getenv_return
        self.etcd_client = Mock(spec=EtcdClient)
        m_etcd_client.return_value = self.etcd_client
        self.datastore = DatastoreClient()
        m_etcd_client.assert_called_once_with(host="127.0.0.1",
                                              port=2379,
                                              protocol="http",
                                              cert=None,
                                              ca_cert=None) 
开发者ID:projectcalico,项目名称:libcalico,代码行数:24,代码来源:test_datastore.py

示例6: test_endpoints_multiple

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import Client [as 别名]
def test_endpoints_multiple(self, m_etcd_client, m_getenv):
        """ Test etcd endpoint overriding with multiple endpoints."""
        etcd_env_dict = {
            ETCD_AUTHORITY_ENV   : "127.0.1.1:2380",
            ETCD_SCHEME_ENV      : "https",
            ETCD_ENDPOINTS_ENV   : "http://127.0.0.1:2379, http://127.0.1.1:2381",
            ETCD_KEY_FILE_ENV    : "",
            ETCD_CERT_FILE_ENV   : "",
            ETCD_CA_CERT_FILE_ENV: ""
        }

        def m_getenv_return(key, *args):
            return etcd_env_dict[key]
        m_getenv.side_effect = m_getenv_return
        self.etcd_client = Mock(spec=EtcdClient)
        m_etcd_client.return_value = self.etcd_client
        self.datastore = DatastoreClient()
        m_etcd_client.assert_called_once_with(host=(("127.0.0.1", 2379),
                                                    ("127.0.1.1", 2381)),
                                              protocol="http",
                                              cert=None,
                                              ca_cert=None,
                                              allow_reconnect=True) 
开发者ID:projectcalico,项目名称:libcalico,代码行数:25,代码来源:test_datastore.py

示例7: test_endpoints_proto_mismatch

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import Client [as 别名]
def test_endpoints_proto_mismatch(self, m_etcd_client, m_getenv):
        """ Test mismatched protocols in etcd endpoints."""
        etcd_env_dict = {
            ETCD_AUTHORITY_ENV   : "127.0.1.1:2380",
            ETCD_SCHEME_ENV      : "https",
            ETCD_ENDPOINTS_ENV   : "http://127.0.0.1:2379, https://127.0.1.1:2381",
            ETCD_KEY_FILE_ENV    : "",
            ETCD_CERT_FILE_ENV   : "",
            ETCD_CA_CERT_FILE_ENV: ""
        }

        def m_getenv_return(key, *args):
            return etcd_env_dict[key]
        m_getenv.side_effect = m_getenv_return
        self.etcd_client = Mock(spec=EtcdClient)
        m_etcd_client.return_value = self.etcd_client
        self.assertRaises(DataStoreError, DatastoreClient)
        self.assertFalse(m_etcd_client.called) 
开发者ID:projectcalico,项目名称:libcalico,代码行数:20,代码来源:test_datastore.py

示例8: test_endpoints_format_invalid

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import Client [as 别名]
def test_endpoints_format_invalid(self, m_etcd_client, m_getenv):
        """ Test invalid format of etcd endpoints."""
        etcd_env_dict = {
            ETCD_AUTHORITY_ENV   : "127.0.1.1:2380",
            ETCD_SCHEME_ENV      : "https",
            ETCD_ENDPOINTS_ENV   : "http:/ /127.0.0.1:2379\, https://127.0.1.1:2381",
            ETCD_KEY_FILE_ENV    : "",
            ETCD_CERT_FILE_ENV   : "",
            ETCD_CA_CERT_FILE_ENV: ""
        }

        def m_getenv_return(key, *args):
            return etcd_env_dict[key]
        m_getenv.side_effect = m_getenv_return
        self.etcd_client = Mock(spec=EtcdClient)
        m_etcd_client.return_value = self.etcd_client
        self.assertRaises(DataStoreError, DatastoreClient)
        self.assertFalse(m_etcd_client.called) 
开发者ID:projectcalico,项目名称:libcalico,代码行数:20,代码来源:test_datastore.py

示例9: test_secure_etcd_bad_scheme

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import Client [as 别名]
def test_secure_etcd_bad_scheme(self, m_isfile, m_access,
                                    m_etcd_client, m_getenv):
        """
        Test validation for secure etcd fails when scheme is unrecognized.
        """
        m_isfile.return_value = True
        m_access.return_value = True
        etcd_env_dict = {
            ETCD_AUTHORITY_ENV   : "127.0.1.1:2380",
            ETCD_SCHEME_ENV      : "htt",
            ETCD_ENDPOINTS_ENV   : "",
            ETCD_KEY_FILE_ENV    : "",
            ETCD_CERT_FILE_ENV   : "",
            ETCD_CA_CERT_FILE_ENV: ""
        }

        def m_getenv_return(key, *args):
            return etcd_env_dict[key]
        m_getenv.side_effect = m_getenv_return
        self.etcd_client = Mock(spec=EtcdClient)
        m_etcd_client.return_value = self.etcd_client
        self.assertRaises(DataStoreError, DatastoreClient)
        self.assertFalse(m_etcd_client.called) 
开发者ID:projectcalico,项目名称:libcalico,代码行数:25,代码来源:test_datastore.py

示例10: test_secure_etcd_missing_cert

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import Client [as 别名]
def test_secure_etcd_missing_cert(self, m_isfile, m_access,
                                      m_etcd_client, m_getenv):
        """
        Test validation for secure etcd fails when key is given but cert is
        not.
        """
        m_isfile.return_value = True
        m_access.return_value = True
        etcd_env_dict = {
            ETCD_AUTHORITY_ENV   : "127.0.1.1:2380",
            ETCD_SCHEME_ENV      : "https",
            ETCD_ENDPOINTS_ENV   : "",
            ETCD_KEY_FILE_ENV    : "/path/to/key_file",
            ETCD_CERT_FILE_ENV   : "",
            ETCD_CA_CERT_FILE_ENV: ""
        }

        def m_getenv_return(key, *args):
            return etcd_env_dict[key]
        m_getenv.side_effect = m_getenv_return
        self.etcd_client = Mock(spec=EtcdClient)
        m_etcd_client.return_value = self.etcd_client
        self.assertRaises(DataStoreError, DatastoreClient)
        self.assertFalse(m_etcd_client.called) 
开发者ID:projectcalico,项目名称:libcalico,代码行数:26,代码来源:test_datastore.py

示例11: test_secure_etcd_missing_key

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import Client [as 别名]
def test_secure_etcd_missing_key(self, m_isfile, m_access,
                                     m_etcd_client, m_getenv):
        """
        Test validation for secure etcd fails when cert is given but key is
        not.
        """
        m_isfile.return_value = True
        m_access.return_value = True
        etcd_env_dict = {
            ETCD_AUTHORITY_ENV   : "127.0.1.1:2380",
            ETCD_SCHEME_ENV      : "https",
            ETCD_ENDPOINTS_ENV   : "",
            ETCD_KEY_FILE_ENV    : "",
            ETCD_CERT_FILE_ENV   : "/path/to/cert_file",
            ETCD_CA_CERT_FILE_ENV: ""
        }

        def m_getenv_return(key, *args):
            return etcd_env_dict[key]
        m_getenv.side_effect = m_getenv_return
        self.etcd_client = Mock(spec=EtcdClient)
        m_etcd_client.return_value = self.etcd_client
        self.assertRaises(DataStoreError, DatastoreClient)
        self.assertFalse(m_etcd_client.called) 
开发者ID:projectcalico,项目名称:libcalico,代码行数:26,代码来源:test_datastore.py

示例12: test_secure_etcd_cert_not_readable

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import Client [as 别名]
def test_secure_etcd_cert_not_readable(self, m_isfile, m_access,
                                           m_etcd_client, m_getenv):
        """
        Test validation for secure etcd fails when cert is not a readable.
        """
        m_isfile.return_value = True
        m_access.side_effect = [True, False]
        etcd_env_dict = {
            ETCD_AUTHORITY_ENV   : "127.0.1.1:2380",
            ETCD_SCHEME_ENV      : "https",
            ETCD_ENDPOINTS_ENV   : "",
            ETCD_KEY_FILE_ENV    : "/path/to/key_file",
            ETCD_CERT_FILE_ENV   : "/path/to/bad_cert",
            ETCD_CA_CERT_FILE_ENV: "/path/to/ca_file"
        }

        def m_getenv_return(key, *args):
            return etcd_env_dict[key]
        m_getenv.side_effect = m_getenv_return

        self.etcd_client = Mock(spec=EtcdClient)
        m_etcd_client.return_value = self.etcd_client
        self.assertRaises(DataStoreError, DatastoreClient)
        self.assertFalse(m_etcd_client.called) 
开发者ID:projectcalico,项目名称:libcalico,代码行数:26,代码来源:test_datastore.py

示例13: test_secure_etcd_ca_not_file

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import Client [as 别名]
def test_secure_etcd_ca_not_file(self, m_isfile, m_access,
                                     m_etcd_client, m_getenv):
        """
        Test validation for secure etcd fails when ca is not a file.
        """
        m_isfile.side_effect = [True, True, False]
        m_access.return_value = True
        etcd_env_dict = {
            ETCD_AUTHORITY_ENV   : "127.0.1.1:2380",
            ETCD_SCHEME_ENV      : "https",
            ETCD_ENDPOINTS_ENV   : "",
            ETCD_KEY_FILE_ENV    : "/path/to/key_file",
            ETCD_CERT_FILE_ENV   : "/path/to/cert_file",
            ETCD_CA_CERT_FILE_ENV: "/path/to/not_readable"
        }

        def m_getenv_return(key, *args):
            return etcd_env_dict[key]
        m_getenv.side_effect = m_getenv_return

        self.etcd_client = Mock(spec=EtcdClient)
        m_etcd_client.return_value = self.etcd_client
        self.assertRaises(DataStoreError, DatastoreClient)
        self.assertFalse(m_etcd_client.called) 
开发者ID:projectcalico,项目名称:libcalico,代码行数:26,代码来源:test_datastore.py

示例14: mock_read_2_node_peers

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import Client [as 别名]
def mock_read_2_node_peers(path):
    """
    EtcdClient mock side effect for read with 2 IPv4 peers.  Assumes host is
    "TEST_HOST" otherwise raises EtcdKeyNotFound.
    """
    result = Mock(spec=EtcdResult)
    if path != TEST_NODE_BGP_PEERS_PATH:
        raise EtcdKeyNotFound()
    children = []
    for ip in ["192.169.3.1", "192.169.5.1"]:
        node = Mock(spec=EtcdResult)
        node.value = "{\"ip\": \"%s\", \"as_num\": \"32245\"}" % ip
        node.key = TEST_NODE_BGP_PEERS_PATH + str(ip)
        children.append(node)
    result.children = iter(children)
    return result 
开发者ID:projectcalico,项目名称:libcalico,代码行数:18,代码来源:test_datastore.py

示例15: mock_read_2_pools

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import Client [as 别名]
def mock_read_2_pools(path, recursive=False):
    """
    EtcdClient mock side effect for read with 2 IPv4 pools.
    """
    result = Mock(spec=EtcdResult)
    assert_equal(path, IPV4_POOLS_PATH)
    assert_true(recursive)
    children = []
    for net, ipam in [("192.168.3.0/24", "true"),
                      ("192.168.5.0/24", "false")]:
        node = Mock(spec=EtcdResult)
        node.value = "{\"cidr\": \"%s\",\"ipam\":%s}" % (net, ipam)
        node.key = IPV4_POOLS_PATH + net.replace("/", "-")
        children.append(node)
    result.leaves = iter(children)
    return result 
开发者ID:projectcalico,项目名称:libcalico,代码行数:18,代码来源:test_datastore.py


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