• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python helper.not_found_response函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mimic.util.helper.not_found_response函数的典型用法代码示例。如果您正苦于以下问题:Python not_found_response函数的具体用法?Python not_found_response怎么用?Python not_found_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: delete_node

def delete_node(store, lb_id, node_id, current_timestamp):
    """
    Determines whether the node to be deleted exists in mimic store and
    returns the response code.
    """
    if lb_id in store.lbs:

        _verify_and_update_lb_state(store, lb_id, False, current_timestamp)

        if store.lbs[lb_id]["status"] != "ACTIVE":
            resource = invalid_resource(
                "Load Balancer '{0}' has a status of {1} and is considered "
                "immutable.".format(lb_id, store.lbs[lb_id]["status"]), 422)
            return (resource, 422)

        _verify_and_update_lb_state(store, lb_id,
                                    current_timestamp=current_timestamp)

        if store.lbs[lb_id].get("nodes"):
            for each in store.lbs[lb_id]["nodes"]:
                if each["id"] == node_id:
                    index = store.lbs[lb_id]["nodes"].index(each)
                    del store.lbs[lb_id]["nodes"][index]
                    if not store.lbs[lb_id]["nodes"]:
                        del store.lbs[lb_id]["nodes"]
                    store.lbs[lb_id].update({"nodeCount": len(store.lbs[lb_id].get("nodes", []))})
                    return None, 202

        return not_found_response("node"), 404

    return not_found_response("loadbalancer"), 404
开发者ID:isaacm,项目名称:mimic,代码行数:31,代码来源:loadbalancer.py


示例2: delete_node

    def delete_node(self, lb_id, node_id, current_timestamp):
        """
        Determines whether the node to be deleted exists in the session store,
        deletes the node, and returns the response code.
        """
        if lb_id in self.lbs:

            _verify_and_update_lb_state(self, lb_id, False, current_timestamp)

            if self.lbs[lb_id]["status"] != "ACTIVE":
                # Error message verified as of 2015-04-22
                resource = invalid_resource(
                    "Load Balancer '{0}' has a status of '{1}' and is considered "
                    "immutable.".format(lb_id, self.lbs[lb_id]["status"]), 422)
                return (resource, 422)

            _verify_and_update_lb_state(self, lb_id,
                                        current_timestamp=current_timestamp)

            if _delete_node(self, lb_id, node_id):
                return None, 202
            else:
                return not_found_response("node"), 404

        return not_found_response("loadbalancer"), 404
开发者ID:reaperhulk,项目名称:mimic,代码行数:25,代码来源:clb_objects.py


示例3: add_node

    def add_node(self, node_list, lb_id, current_timestamp):
        """
        Returns the canned response for add nodes
        """
        if lb_id in self.lbs:

            _verify_and_update_lb_state(self, lb_id, False, current_timestamp)

            if self.lbs[lb_id]["status"] != "ACTIVE":
                resource = invalid_resource(
                    "Load Balancer '{0}' has a status of {1} and is considered "
                    "immutable.".format(lb_id, self.lbs[lb_id]["status"]), 422)
                return (resource, 422)

            nodes = _format_nodes_on_lb(node_list)

            if self.lbs[lb_id].get("nodes"):
                for existing_node in self.lbs[lb_id]["nodes"]:
                    for new_node in node_list:
                        if (existing_node["address"] == new_node["address"] and
                                existing_node["port"] == new_node["port"]):
                            resource = invalid_resource(
                                "Duplicate nodes detected. One or more nodes "
                                "already configured on load balancer.", 413)
                            return (resource, 413)

                self.lbs[lb_id]["nodes"] = self.lbs[lb_id]["nodes"] + nodes
            else:
                self.lbs[lb_id]["nodes"] = nodes
                self.lbs[lb_id]["nodeCount"] = len(self.lbs[lb_id]["nodes"])
                _verify_and_update_lb_state(self, lb_id,
                                            current_timestamp=current_timestamp)
            return {"nodes": nodes}, 202

        return not_found_response("loadbalancer"), 404
开发者ID:reaperhulk,项目名称:mimic,代码行数:35,代码来源:clb_objects.py


示例4: del_load_balancer

    def del_load_balancer(self, lb_id, current_timestamp):
        """
        Returns response for a load balancer
         is in building status for 20
        seconds and response code 202, and adds the new lb to ``self.lbs``.
        A loadbalancer, on delete, goes into PENDING-DELETE and remains in DELETED
        status until a nightly job(maybe?)
        """
        if lb_id in self.lbs:

            if self.lbs[lb_id]["status"] == "PENDING-DELETE":
                msg = ("Must provide valid load balancers: {0} are immutable and "
                       "could not be processed.".format(lb_id))
                # Dont doubt this to be 422, it is 400!
                return invalid_resource(msg, 400), 400

            _verify_and_update_lb_state(self, lb_id, True, current_timestamp)

            if any([self.lbs[lb_id]["status"] == "ACTIVE",
                    self.lbs[lb_id]["status"] == "ERROR",
                    self.lbs[lb_id]["status"] == "PENDING-UPDATE"]):
                del self.lbs[lb_id]
                return EMPTY_RESPONSE, 202

            if self.lbs[lb_id]["status"] == "PENDING-DELETE":
                return EMPTY_RESPONSE, 202

            if self.lbs[lb_id]["status"] == "DELETED":
                _verify_and_update_lb_state(self, lb_id,
                                            current_timestamp=current_timestamp)
                msg = "Must provide valid load balancers: {0} could not be found.".format(lb_id)
                # Dont doubt this to be 422, it is 400!
                return invalid_resource(msg, 400), 400

        return not_found_response("loadbalancer"), 404
开发者ID:reaperhulk,项目名称:mimic,代码行数:35,代码来源:clb_objects.py


示例5: list_nodes

    def list_nodes(self, lb_id, current_timestamp):
        """
        Returns the list of nodes remaining on the load balancer
        """
        if lb_id in self.lbs:
            _verify_and_update_lb_state(self, lb_id, False, current_timestamp)
            if lb_id not in self.lbs:
                return not_found_response("loadbalancer"), 404

            if self.lbs[lb_id]["status"] == "DELETED":
                return invalid_resource("The loadbalancer is marked as deleted.", 410), 410
            node_list = []
            if self.lbs[lb_id].get("nodes"):
                node_list = self.lbs[lb_id]["nodes"]
            return {"nodes": node_list}, 200
        else:
            return not_found_response("loadbalancer"), 404
开发者ID:reaperhulk,项目名称:mimic,代码行数:17,代码来源:clb_objects.py


示例6: list_addresses

def list_addresses(server_id):
    """
    Returns the public and private ip address for the given server
    """
    if server_id in s_cache:
        return {'addresses': s_cache[server_id]['addresses']}, 200
    else:
        return not_found_response(), 404
开发者ID:venkateshsampath,项目名称:mimic,代码行数:8,代码来源:nova.py


示例7: list_nodes

    def list_nodes(self, lb_id):
        """
        Returns the list of nodes remaining on the load balancer
        """
        if lb_id in self.lbs:
            self._verify_and_update_lb_state(lb_id, False, self.clock.seconds())
            if lb_id not in self.lbs:
                return not_found_response("loadbalancer"), 404

            if self.lbs[lb_id]["status"] == "DELETED":
                return invalid_resource("The loadbalancer is marked as deleted.", 410), 410

            node_list = [node.as_json()
                         for node in self.lbs[lb_id].nodes]

            return {"nodes": node_list}, 200
        else:
            return not_found_response("loadbalancer"), 404
开发者ID:pratikmallya,项目名称:mimic,代码行数:18,代码来源:clb_objects.py


示例8: update_health_monitor

    def update_health_monitor(self, lb_id, health_monitor):
        """
        Update LB's health monitor setting
        """
        if lb_id not in self.lbs:
            return not_found_response("loadbalancer"), 404

        self.lbs[lb_id].health_monitor = health_monitor["healthMonitor"]
        return EMPTY_RESPONSE, 202
开发者ID:pratikmallya,项目名称:mimic,代码行数:9,代码来源:clb_objects.py


示例9: delete_health_monitor

    def delete_health_monitor(self, lb_id):
        """
        Delete LB's health monitor configuration
        """
        if lb_id not in self.lbs:
            return not_found_response("loadbalancer"), 404

        self.lbs[lb_id].health_monitor = {}
        return EMPTY_RESPONSE, 202
开发者ID:pratikmallya,项目名称:mimic,代码行数:9,代码来源:clb_objects.py


示例10: get_health_monitor

    def get_health_monitor(self, lb_id):
        """
        Return LB's health monitor setting
        """
        if lb_id not in self.lbs:
            return not_found_response("loadbalancer"), 404

        self._verify_and_update_lb_state(lb_id, False, self.clock.seconds())
        return {"healthMonitor": self.lbs[lb_id].health_monitor}, 200
开发者ID:pratikmallya,项目名称:mimic,代码行数:9,代码来源:clb_objects.py


示例11: get_load_balancers

 def get_load_balancers(self, lb_id):
     """
     Returns the load balancers with the given lb id, with response
     code 200. If no load balancers are found returns 404.
     """
     if lb_id in self.lbs:
         self._verify_and_update_lb_state(lb_id, False, self.clock.seconds())
         log.msg(self.lbs[lb_id]["status"])
         return {'loadBalancer': self.lbs[lb_id].full_json()}, 200
     return not_found_response("loadbalancer"), 404
开发者ID:pratikmallya,项目名称:mimic,代码行数:10,代码来源:clb_objects.py


示例12: del_load_balancer

def del_load_balancer(lb_id):
    """
    Returns response for a load balancer that is in building status for 20 seconds
    and response code 202, and adds the new lb to the lb_cache
    """
    if lb_id in lb_cache:
        del lb_cache[lb_id]
        return None, 202
    else:
        return not_found_response(), 404
开发者ID:jirwin,项目名称:mimic,代码行数:10,代码来源:loadbalancer.py


示例13: get_server

def get_server(server_id):
    """
    Verify if the given server_id exists in the server cache. If true, return server
    data else return None
    """
    if server_id in s_cache:
        set_server_state(server_id)
        return {'server': s_cache[server_id]}, 200
    else:
        return not_found_response(), 404
开发者ID:venkateshsampath,项目名称:mimic,代码行数:10,代码来源:nova.py


示例14: get_node

    def get_node(self, lb_id, node_id):
        """
        Returns the node on the load balancer
        """
        if lb_id in self.lbs:
            self._verify_and_update_lb_state(lb_id, False, self.clock.seconds())

            if self.lbs[lb_id]["status"] == "DELETED":
                return (
                    invalid_resource(
                        "The loadbalancer is marked as deleted.", 410),
                    410)

            for each in self.lbs[lb_id].nodes:
                if node_id == each.id:
                    return {"node": each.as_json()}, 200

            return not_found_response("node"), 404

        return not_found_response("loadbalancer"), 404
开发者ID:pratikmallya,项目名称:mimic,代码行数:20,代码来源:clb_objects.py


示例15: get_image

def get_image(image_id):
    """
    Canned response for get image.  The image id provided is substituted in the
    response, if not one of the invalid image ids specified in mimic_presets.
    """
    if (
            image_id in get_presets['servers']['invalid_image_ref'] or
            image_id.endswith('Z')
    ):
        return not_found_response('images'), 404
    return {'image': {'status': 'ACTIVE', 'id': image_id, 'name': 'mimic-test-image'}}, 200
开发者ID:amitgandhinz,项目名称:mimic,代码行数:11,代码来源:nova.py


示例16: list_nodes

def list_nodes(lb_id):
    """
    Returns the list of nodes remaining on the load balancer
    """
    if lb_id in lb_cache:
        node_list = []
        if lb_cache[lb_id].get("nodes"):
            node_list = lb_cache[lb_id]["nodes"]
        return {"nodes": node_list}, 200
    else:
        return not_found_response("loadbalancer"), 404
开发者ID:jirwin,项目名称:mimic,代码行数:11,代码来源:loadbalancer.py


示例17: get_flavor

def get_flavor(flavor_id):
    """
    Canned response for get flavor.
    The flavor id provided is substituted in the response
    """
    if flavor_id in get_presets['servers']['invalid_flavor_ref']:
        return not_found_response('flavors'), 404
    return ({'flavor': {'name': '512MB Standard Instance',
                        'id': flavor_id,
                        'name': 'mimic-test-flavor'}},
            200)
开发者ID:amitgandhinz,项目名称:mimic,代码行数:11,代码来源:nova.py


示例18: get_nodes

    def get_nodes(self, lb_id, node_id, current_timestamp):
        """
        Returns the node on the load balancer
        """
        if lb_id in self.lbs:
            _verify_and_update_lb_state(self, lb_id, False, current_timestamp)

            if self.lbs[lb_id]["status"] == "DELETED":
                return (
                    invalid_resource(
                        "The loadbalancer is marked as deleted.", 410),
                    410)

            if self.lbs[lb_id].get("nodes"):
                for each in self.lbs[lb_id]["nodes"]:
                    if node_id == each["id"]:
                        return {"node": each}, 200
            return not_found_response("node"), 404

        return not_found_response("loadbalancer"), 404
开发者ID:reaperhulk,项目名称:mimic,代码行数:20,代码来源:clb_objects.py


示例19: get_load_balancers

 def get_load_balancers(self, lb_id, current_timestamp):
     """
     Returns the load balancers with the given lb id, with response
     code 200. If no load balancers are found returns 404.
     """
     if lb_id in self.lbs:
         _verify_and_update_lb_state(self, lb_id, False, current_timestamp)
         log.msg(self.lbs[lb_id]["status"])
         new_lb = _lb_without_tenant(self, lb_id)
         return {'loadBalancer': new_lb}, 200
     return not_found_response("loadbalancer"), 404
开发者ID:reaperhulk,项目名称:mimic,代码行数:11,代码来源:clb_objects.py


示例20: add_node

    def add_node(self, node_list, lb_id):
        """
        Add one or more nodes to a load balancer.  Fails if one or more of the
        nodes provided has the same address/port as an existing node.  Also
        fails if adding the nodes would exceed the maximum number of nodes on
        the CLB.

        :param list node_list: a `list` of `dict` containing specification for
            nodes

        :return: a `tuple` of (json response as a dict, http status code)
        """
        if lb_id in self.lbs:
            current_timestamp = self.clock.seconds()
            self._verify_and_update_lb_state(lb_id, False, current_timestamp)

            if self.lbs[lb_id]["status"] != "ACTIVE":
                return considered_immutable_error(
                    self.lbs[lb_id]["status"], lb_id)

            nodes = [Node.from_json(blob) for blob in node_list]

            for existing_node in self.lbs[lb_id].nodes:
                for new_node in nodes:
                    if existing_node.same_as(new_node):
                        resource = invalid_resource(
                            "Duplicate nodes detected. One or more nodes "
                            "already configured on load balancer.", 413)
                        return (resource, 413)

            # If there were no duplicates
            new_nodeCount = len(self.lbs[lb_id].nodes) + len(nodes)
            if new_nodeCount <= self.node_limit:
                self.lbs[lb_id].nodes = self.lbs[lb_id].nodes + nodes
            else:
                resource = invalid_resource(
                    "Nodes must not exceed {0} "
                    "per load balancer.".format(self.node_limit), 413)
                return (resource, 413)

            # Node status will be OFFLINE if health monitor is enabled in CLB
            # ONLINE if health monitor is disabled
            if self.lbs[lb_id].health_monitor != {}:
                for node in nodes:
                    node.status = "OFFLINE"

            self._add_node_created_feeds(nodes)

            self._verify_and_update_lb_state(
                lb_id, current_timestamp=current_timestamp)
            return {"nodes": [node.as_json() for node in nodes]}, 202

        return not_found_response("loadbalancer"), 404
开发者ID:BenjamenMeyer,项目名称:mimic,代码行数:53,代码来源:clb_objects.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python processor.Processor类代码示例发布时间:2022-05-27
下一篇:
Python helper.invalid_resource函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap