Exemplo n.º 1
0
def update_worker_status():
    """
    Update the worker status to the master as well as container info.
    """

    threading.Timer(5, update_worker_status).start()
    """
    Get machine status by calling a unix command and fetch for load average
    """

    content = Services.get_machine_status(Setting, CRole.WORKER)
    content[Definition.REST.get_str_docker(
    )] = DockerService.get_containers_status()
    content[Definition.REST.get_str_local_imgs(
    )] = DockerService.get_local_images()

    s_content = bytes(json.dumps(content), 'utf-8')

    html = urllib3.PoolManager()
    try:
        r = html.request('PUT',
                         Definition.Master.get_str_check_master(
                             Setting.get_master_addr(),
                             Setting.get_master_port(), Setting.get_token()),
                         body=s_content)

        if r.status != 200:
            SysOut.err_string("Cannot update worker status to the master!")
        else:
            SysOut.debug_string("Reports status to master node complete.")

    except Exception as e:
        SysOut.err_string("Master is not available!")
        print(e)
Exemplo n.º 2
0
    def on_get(self, req, res):
        """
        GET: /status?token={None}
        """
        if not Definition.get_str_token() in req.params:
            format_response_string(res, falcon.HTTP_401, "Token is required")
            return

        if req.params[Definition.get_str_token()] == Setting.get_token():
            result = LService.get_machine_status(Setting, CRole.MASTER)
            format_response_string(res, falcon.HTTP_200, str(result))

        else:
            format_response_string(res, falcon.HTTP_401, "Invalid token ID")
Exemplo n.º 3
0
    def on_get(self, req, res):
        """
        GET: /status?token={None}
        """
        if not Definition.get_str_token() in req.params:
            res.body = "Token is required."
            res.content_type = "String"
            res.status = falcon.HTTP_401
            return

        if req.params[Definition.get_str_token()] == Setting.get_token():

            result = LService.get_machine_status(Setting, CRole.MASTER)

            res.body = str(result)
            res.content_type = "String"
            res.status = falcon.HTTP_200
        else:
            res.body = "Invalid token ID."
            res.content_type = "String"
            res.status = falcon.HTTP_401
Exemplo n.º 4
0
    def on_get(self, req, res):
        """
        GET: /status?token={None}
        """
        if not Definition.get_str_token() in req.params:
            res.body = "Token is required."
            res.content_type = "String"
            res.status = falcon.HTTP_401
            return

        if req.params[Definition.get_str_token()] == Setting.get_token():
            s_content = Services.get_machine_status(Setting, CRole.WORKER)
            s_content[Definition.REST.get_str_docker(
            )] = DockerService.get_containers_status()

            res.body = str(s_content)

            res.content_type = "String"
            res.status = falcon.HTTP_200
        else:
            res.body = "Invalid token ID."
            res.content_type = "String"
            res.status = falcon.HTTP_401