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


Python Endpoint.from_json方法代码示例

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


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

示例1: get_endpoints

# 需要导入模块: from pycalico.datastore_datatypes import Endpoint [as 别名]
# 或者: from pycalico.datastore_datatypes.Endpoint import from_json [as 别名]
    def get_endpoints(self, hostname=None, orchestrator_id=None, workload_id=None, endpoint_id=None):
        """
        Optimized function to get endpoint(s).

        Constructs a etcd-path that it as specific as possible given the
        provided criteria, in order to return the smallest etcd tree as
        possible. After querying with the ep_path, it will then compare the
        returned endpoints to the provided criteria, and return all matches.

        :param endpoint_id: The ID of the endpoint
        :param hostname: The hostname that the endpoint lives on.
        :param workload_id: The workload that the endpoint belongs to.
        :param orchestrator_id: The workload that the endpoint belongs to.
        :return: A list of Endpoint Objects which match the criteria, or an
        empty list if none match
        """
        # First build the query string as specific as possible. Note, we want
        # the query to be as specific as possible, so we proceed any variables
        # with known constants e.g. we add '/workload' after the hostname
        # variable.
        if not hostname:
            ep_path = HOSTS_PATH
        elif not orchestrator_id:
            ep_path = HOST_PATH % {"hostname": hostname}
        elif not workload_id:
            ep_path = ORCHESTRATOR_PATH % {"hostname": hostname, "orchestrator_id": orchestrator_id}
        elif not endpoint_id:
            ep_path = WORKLOAD_PATH % {
                "hostname": hostname,
                "orchestrator_id": orchestrator_id,
                "workload_id": workload_id,
            }
        else:
            ep_path = ENDPOINT_PATH % {
                "hostname": hostname,
                "orchestrator_id": orchestrator_id,
                "workload_id": workload_id,
                "endpoint_id": endpoint_id,
            }
        try:
            # Search etcd
            leaves = self.etcd_client.read(ep_path, recursive=True).leaves
        except EtcdKeyNotFound:
            return []

        # Filter through result
        matches = []
        for leaf in leaves:
            endpoint = Endpoint.from_json(leaf.key, leaf.value)

            # If its an endpoint, compare it to search criteria
            if endpoint and endpoint.matches(
                hostname=hostname, orchestrator_id=orchestrator_id, workload_id=workload_id, endpoint_id=endpoint_id
            ):
                matches.append(endpoint)
        return matches
开发者ID:cheuschober,项目名称:libcalico,代码行数:58,代码来源:datastore.py


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