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))
def api_node_tags_add(nodeid): status = "success" answ = {"data": {}} cloud_api_main.debug_log_print("Add tags", request.data) try: cloud_api_main.check_user_privilege_node(nodeid) added = [] reqdata = json.loads(request.data) tags = reqdata["tags"] alltags = cloud_api_main.get_tags() if isinstance(tags, basestring): tags = [tags] tags = set(tags) for t in tags: if t not in alltags: cloud_api_main.create_tag(t) cloud_api_main.add_tag_node(t, nodeid) answ["data"]["tags"] = list(tags) 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))
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))
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))
def api_node_tags_change(nodeid): status = "success" answ = {"data": {}} try: cloud_api_main.debug_log_print("Change tags", request.data) cloud_api_main.check_user_privilege_node(nodeid) reqdata = json.loads(request.data) tags = reqdata["tags"] if isinstance(tags, basestring): tags = [tags] tags = set(tags) tags.add(cloud_api_main.tdata.ownertag) alltags = cloud_api_main.get_tags() currtags = set(cloud_api_main.get_tags_node(nodeid)) to_remove = currtags.difference(tags).intersection(alltags) to_add = tags.difference(currtags) for t in to_add: if t not in alltags: cloud_api_main.create_tag(t) cloud_api_main.add_tag_node(t, nodeid) cloud_api_main.remove_tag_node(to_remove, nodeid) answ["data"]["tags"] = cloud_api_main.get_tags_node(nodeid) 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))
def api_node_interfaces_get(nodeid): status = "success" answ = {"data": {}} try: cloud_api_main.check_user_privilege_node(nodeid) data = cloud_api_main.get_interfaces_db(nodeid=nodeid) answ["data"]["interfaces"] = data.values() 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 BaseException as e: status = "error" cloud_api_main.debug_log_print(e) answ["message"] = repr(e) answ["data"]["description"] = cloud_api_main.tdata.extended_error_log answ["status"] = status return make_response(jsonify(answ))
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))