示例#1
0
def api_node_tags_delete(nodeid,tag):
    status = "success"
    answ = {"data": {}}
    cloud_api_main.debug_log_print("Change tags", request.data)

    try:
        cloud_api_main.check_user_privilege_node(nodeid)

        if tag == cloud_api_main.tdata.usertag:
            cloud_api_main.add_to_user_problem_msg("you can't remove your own usertag")
            raise cloud_api_main.PrivilegeException("can't remove this tag")

        tags = set((tag,))

        currtags = set(cloud_api_main.get_tags_node(nodeid))

        to_remove = tags.intersection(currtags)

        cloud_api_main.remove_tag_node(to_remove, nodeid)

        answ["data"]["deleted"] = True
    except (cloud_api_main.PrivilegeException, cloud_api_main.NoSuchObjectException) as e:
        status = "fail"
        answ["message"] = repr(e)
        answ["data"]["description"] = cloud_api_main.get_user_problem_msg()

    except Exception as e:
        status = "error"
        answ["message"] = repr(e)
        answ["data"]["description"] = cloud_api_main.get_user_problem_msg()

    answ["status"] = status

    return make_response(jsonify(answ))
示例#2
0
def api_node_set_status(nodeid):
    status = "success"
    answ = {"data": {}}
    try:
        cloud_api_main.check_user_privilege_node(nodeid)
        reqdata = json.loads(request.data)

        wantedstate = reqdata.get("status")
        if not wantedstate:
            cloud_api_main.add_to_user_problem_msg("no status to change to")
            raise cloud_api_main.WrongRequestException("wrong request")

        data = cloud_api_main.change_node_state_cruder(nodeid,wantedstate)
        answ["data"] = data
    except (cloud_api_main.PrivilegeException, cloud_api_main.NoSuchObjectException, cloud_api_main.WrongRequestException) as e:
        status = "fail"
        answ["message"] = repr(e)
        answ["data"]["description"] = cloud_api_main.get_user_problem_msg()
    except BaseException as e:
        status = "error"
        cloud_api_main.debug_log_print(e)
        answ["message"] = repr(e)
        answ["data"]["description"] = cloud_api_main.get_user_problem_msg()

    answ["status"] = status

    return make_response(jsonify(answ))
示例#3
0
def api_node_set_status(nodeid):
    status = "success"
    answ = {"data": {}}
    try:
        cloud_api_main.check_user_privilege_node(nodeid)
        reqdata = json.loads(request.data)

        wantedstate = reqdata.get("status")
        if not wantedstate:
            cloud_api_main.add_to_user_problem_msg("no status to change to")
            raise cloud_api_main.WrongRequestException("wrong request")

        data = cloud_api_main.change_node_state_cruder(nodeid, wantedstate)
        answ["data"] = data
    except (cloud_api_main.PrivilegeException,
            cloud_api_main.NoSuchObjectException,
            cloud_api_main.WrongRequestException) as e:
        status = "fail"
        answ["message"] = repr(e)
        answ["data"]["description"] = cloud_api_main.get_user_problem_msg()
    except BaseException as e:
        status = "error"
        cloud_api_main.debug_log_print(e)
        answ["message"] = repr(e)
        answ["data"]["description"] = cloud_api_main.get_user_problem_msg()

    answ["status"] = status

    return make_response(jsonify(answ))
示例#4
0
def api_node_tags_delete(nodeid, tag):
    status = "success"
    answ = {"data": {}}
    cloud_api_main.debug_log_print("Change tags", request.data)

    try:
        cloud_api_main.check_user_privilege_node(nodeid)

        if tag == cloud_api_main.tdata.usertag:
            cloud_api_main.add_to_user_problem_msg(
                "you can't remove your own usertag")
            raise cloud_api_main.PrivilegeException("can't remove this tag")

        tags = set((tag, ))

        currtags = set(cloud_api_main.get_tags_node(nodeid))

        to_remove = tags.intersection(currtags)

        cloud_api_main.remove_tag_node(to_remove, nodeid)

        answ["data"]["deleted"] = True
    except (cloud_api_main.PrivilegeException,
            cloud_api_main.NoSuchObjectException) as e:
        status = "fail"
        answ["message"] = repr(e)
        answ["data"]["description"] = cloud_api_main.get_user_problem_msg()

    except Exception as e:
        status = "error"
        answ["message"] = repr(e)
        answ["data"]["description"] = cloud_api_main.get_user_problem_msg()

    answ["status"] = status

    return make_response(jsonify(answ))