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


Python helper.not_found_response函数代码示例

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


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


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