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


Python etcd.EtcdKeyNotFound方法代码示例

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


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

示例1: read_dir_index

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdKeyNotFound [as 别名]
def read_dir_index(self, key_type, key, user=None, batchid=None):
        """Reads a directory from keystore

        Returns None if the directory doesn't exist. Otherwise,
        returns the full directory content (as returned by the etcd
        lib) and associated modification index

        """
        user, batchid = self.infer_user_and_alloc_id(user, batchid, key_type)

        key_path = self.get_key_path(key_type, key, user, batchid)
        try:
            val = self.keyval_client.read(key_path, recurse = True)
        except etcd.EtcdKeyNotFound as e:
            return None, e.payload['index']

        return val, max(val.modifiedIndex,
                        val.etcd_index) 
开发者ID:cea-hpc,项目名称:pcocc,代码行数:20,代码来源:Batch.py

示例2: test_get_profile_no_tags_or_rules

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdKeyNotFound [as 别名]
def test_get_profile_no_tags_or_rules(self):
        """
        Test getting a named profile that exists, but has no tags or rules.
        """

        def mock_read(path):
            result = Mock(spec=EtcdResult)
            if path == TEST_PROFILE_PATH:
                return result
            else:
                raise EtcdKeyNotFound()
        self.etcd_client.read.side_effect = mock_read

        profile = self.datastore.get_profile("TEST")
        assert_equal(profile.name, "TEST")
        assert_set_equal(set(), profile.tags)
        assert_equal([], profile.rules.inbound_rules)
        assert_equal([], profile.rules.outbound_rules) 
开发者ID:projectcalico,项目名称:libcalico,代码行数:20,代码来源:test_datastore.py

示例3: mock_read_2_node_peers

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdKeyNotFound [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

示例4: test_assign_not_in_pools

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdKeyNotFound [as 别名]
def test_assign_not_in_pools(self):
        """
        Test assign_ip() when address is not in configured pools.
        """

        def m_get_ip_pools(self, version, ipam, include_disabled):
            assert ipam
            assert not include_disabled
            return [IPPool("10.11.0.0/16"), IPPool("192.168.0.0/16")]

        # block doesn't exist.
        self.m_etcd_client.read.side_effect = EtcdKeyNotFound()

        with patch("pycalico.datastore.DatastoreClient.get_ip_pools",
                   m_get_ip_pools):
            ip0 = IPAddress("10.12.12.55")
            assert_raises(PoolNotFound, self.client.assign_ip, ip0, None, {},
                          host=TEST_HOST)

        # Verify we did not write anything.
        assert_false(self.m_etcd_client.write.called)
        assert_false(self.m_etcd_client.update.called) 
开发者ID:projectcalico,项目名称:libcalico,代码行数:24,代码来源:test_ipam.py

示例5: test_release_block_affinity_empty_cas_error

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdKeyNotFound [as 别名]
def test_release_block_affinity_empty_cas_error(self):
        """
        Test _release_block_affinity() when the block is empty and we hit
        CAS errors.
        """

        block = _test_block_empty_v4()
        m_result0 = Mock(spec=EtcdResult)
        m_result0.value = block.to_json()
        m_result0.key = "my/block/key"
        m_result0.modifiedIndex = 123
        self.m_etcd_client.read.return_value = m_result0

        self.m_etcd_client.delete.side_effect = [EtcdCompareFailed(),  # 1. Fail
                                                 EtcdCompareFailed(),  # 2. Fail
                                                 None,                 # 3. Delete block
                                                 EtcdKeyNotFound]      # 4. Delete key
        self.client._release_block_affinity("test_host1", block.cidr)
        self.m_etcd_client.delete.assert_has_calls([
                call(m_result0.key, prevIndex=m_result0.modifiedIndex),
                call(m_result0.key, prevIndex=m_result0.modifiedIndex),
                call(m_result0.key, prevIndex=m_result0.modifiedIndex),
                call("/calico/ipam/v2/host/test_host1/ipv4/block/%s" %
                     str(BLOCK_V4_1).replace("/", "-"))
            ]) 
开发者ID:projectcalico,项目名称:libcalico,代码行数:27,代码来源:test_ipam.py

示例6: _ensure_cluster_guid

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdKeyNotFound [as 别名]
def _ensure_cluster_guid(self, key):
        """
        Ensures a globally unique cluster GUID.  Write it idempotently into the
        datastore. The prevExist=False creates the value (safely with CaS)
        if it doesn't exist.
        """
        try:
            self.etcd_client.read(key)
        except etcd.EtcdKeyNotFound:
            guid = uuid.uuid4()
            guid_string = guid.get_hex()
            try:
                self.etcd_client.write(key, guid_string, prevExist=False)
            except etcd.EtcdAlreadyExist:
                # ignore
                pass 
开发者ID:projectcalico,项目名称:libcalico,代码行数:18,代码来源:datastore.py

示例7: get_per_host_config

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdKeyNotFound [as 别名]
def get_per_host_config(self, hostname, config_param):
        """
        Get a raw (string) per-host config parameter from etcd.
        :param hostname: The name of the host.
        :param config_param: The name of the config parameter (e.g.
               "LogSeverityFile").
        :return: string value or None if config wasn't present.
        """
        config_key = HOST_CONFIG_KEY_PATH % {
            "hostname": hostname,
            "config_param": config_param,
        }
        try:
            return self.etcd_client.read(config_key).value
        except etcd.EtcdKeyNotFound:
            return None 
开发者ID:projectcalico,项目名称:libcalico,代码行数:18,代码来源:datastore.py

示例8: set_per_host_config

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdKeyNotFound [as 别名]
def set_per_host_config(self, hostname, config_param, value):
        """
        Write a raw (string) per-host config parameter to etcd.
        :param hostname: The name of the host who's config should be updated.
        :param config_param: The name of the parameter (e.g.
               "LogSeverityFile").
        :param value: The raw string value to set, or None to delete the key.
        """
        config_key = HOST_CONFIG_KEY_PATH % {
            "hostname": hostname,
            "config_param": config_param,
        }
        if value is not None:
            self.etcd_client.write(config_key, value)
        else:
            try:
                self.etcd_client.delete(config_key)
            except etcd.EtcdKeyNotFound:
                pass 
开发者ID:projectcalico,项目名称:libcalico,代码行数:21,代码来源:datastore.py

示例9: remove_host

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdKeyNotFound [as 别名]
def remove_host(self, hostname):
        """
        Remove a Calico host.
        :param hostname: The name of the host to remove.
        :return: nothing.
        """
        # Remove the host BGP tree.
        bgp_host_path = BGP_HOST_PATH % {"hostname": hostname}
        try:
            self.etcd_client.delete(bgp_host_path, dir=True, recursive=True)
        except etcd.EtcdKeyNotFound:
            pass

        # Remove the host calico tree.
        host_path = HOST_PATH % {"hostname": hostname}
        try:
            self.etcd_client.delete(host_path, dir=True, recursive=True)
        except etcd.EtcdKeyNotFound:
            pass 
开发者ID:projectcalico,项目名称:libcalico,代码行数:21,代码来源:datastore.py

示例10: get_hostnames_from_ips

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdKeyNotFound [as 别名]
def get_hostnames_from_ips(self, ip_list):
        """
        Get the hostnames that are using the given IPs as their calico node IPs.
        :param ip_list: The list of IPs to get hostnames for.
        :return: A dictionary of {IP:hostname} the hosts that own the given IPs.
        """
        try:
            hosts = self.etcd_client.read(BGP_HOSTS_PATH, recursive=True)
            host_ips = hosts.leaves
        except etcd.EtcdKeyNotFound:
            # No BGP hosts currently configured in etcd, so no host owns the IP
            raise KeyError("No BGP host configurations found.")

        ip_host_dict = {}

        # Loop through key-value pairs to find IP addresses
        for host_ip in host_ips:
            # Check for the ipv4 or ipv6 address key values
            host_match = HOSTNAME_IP_DATASTORE_RE.match(host_ip.key)
            if host_match and host_ip.value in ip_list:
                # Pull the hostname from the datastore key string
                hostname = host_match.group(1)
                ip_host_dict[host_ip.value] = hostname

        return ip_host_dict 
开发者ID:projectcalico,项目名称:libcalico,代码行数:27,代码来源:datastore.py

示例11: get_ip_pool_config

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdKeyNotFound [as 别名]
def get_ip_pool_config(self, version, cidr):
        """
        Get the configuration for the given pool.

        :param version: 4 for IPv4, 6 for IPv6
        :param pool: IPNetwork object representing the pool
        :return: An IPPool object.
        """
        assert version in (4, 6)
        assert isinstance(cidr, IPNetwork)

        # Normalize to CIDR format (i.e. 10.1.1.1/8 goes to 10.0.0.0/8)
        cidr = cidr.cidr

        key = IP_POOL_KEY % {"version": str(version),
                             "pool": str(cidr).replace("/", "-")}

        try:
            data = self.etcd_client.read(key).value
        except etcd.EtcdKeyNotFound:
            # Re-raise with a better error message.
            raise KeyError("%s is not a configured IP pool." % cidr)

        return IPPool.from_json(data) 
开发者ID:projectcalico,项目名称:libcalico,代码行数:26,代码来源:datastore.py

示例12: remove_ip_pool

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdKeyNotFound [as 别名]
def remove_ip_pool(self, version, cidr):
        """
        Delete the given CIDR range from the list of pools.  If the pool does
        not exist, raise a KeyError.

        :param version: 4 for IPv4, 6 for IPv6
        :param cidr: IPNetwork object representing the pool
        :return: None
        """
        assert version in (4, 6)
        assert isinstance(cidr, IPNetwork)

        # Normalize to CIDR format (i.e. 10.1.1.1/8 goes to 10.0.0.0/8)
        cidr = cidr.cidr

        key = IP_POOL_KEY % {"version": str(version),
                             "pool": str(cidr).replace("/", "-")}
        try:
            self.etcd_client.delete(key)
        except etcd.EtcdKeyNotFound:
            # Re-raise with a better error message.
            raise KeyError("%s is not a configured IP pool." % cidr) 
开发者ID:projectcalico,项目名称:libcalico,代码行数:24,代码来源:datastore.py

示例13: policy_exists

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdKeyNotFound [as 别名]
def policy_exists(self, tier_name, policy_name):
        """
        Check if a policy exists.

        :param tier_name: The name of the tier in which to search
        for this policy.
        :param policy_name: The name of the policy to search for.
        :return: True if the profile exists, false otherwise.
        """
        profile_path = POLICY_PATH % {"tier_name": tier_name,
                                      "policy_name": policy_name}
        try:
            _ = self.etcd_client.read(profile_path)
        except etcd.EtcdKeyNotFound:
            return False
        else:
            return True 
开发者ID:projectcalico,项目名称:libcalico,代码行数:19,代码来源:datastore.py

示例14: get_policy_tier_metadata

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdKeyNotFound [as 别名]
def get_policy_tier_metadata(self, tier_name):
        """
        Retrieves the metadata for the given policy tier if it exists.
        If no tier with the given name exists, a KeyError is raised.

        :param tier_name: Name of the tier for which to get metadata.
        :return: Dictionary of tier metadata.
        """
        path = TIER_PATH % {"tier_name": tier_name}
        try:
            result = self.etcd_client.read(path + "/metadata")
            metadata = json.loads(result.value)
        except etcd.EtcdKeyNotFound:
            raise KeyError("Tier '%s' does not exist" % tier_name)
        else:
            return metadata 
开发者ID:projectcalico,项目名称:libcalico,代码行数:18,代码来源:datastore.py

示例15: get_policy

# 需要导入模块: import etcd [as 别名]
# 或者: from etcd import EtcdKeyNotFound [as 别名]
def get_policy(self, tier_name, policy_name):
        """
        Returns the policy with a given group and name.

        :param tier_name: name of the tier from which to get this policy.
        :param policy_name: name of the policy to retrieve.
        :return: nothing.
        """
        policy_path = POLICY_PATH % {"tier_name": tier_name,
                                     "policy_name": policy_name}
        try:
            result = self.etcd_client.read(policy_path)
            policy = Policy(tier_name, policy_name)
            policy.selector = result["selector"]
            policy.rules = result["rules"]
        except etcd.EtcdKeyNotFound:
            raise KeyError("%s/%s is not a configured policy." % \
                    (tier_name, policy_name))
        else:
            return policy 
开发者ID:projectcalico,项目名称:libcalico,代码行数:22,代码来源:datastore.py


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