Exemplo n.º 1
0
def create_project_for_soa(request):
    if request.method == 'POST':
        result, data = login_soa(request)
        if result.get("success"):
            token = request.session.get("passToken")
            auth_url = data.get("auth_url")
            project = data.get("project")
            data = {
                "project": {
                    "name": project.get("name"),
                    "description": project.get("description"),
                    "domain_id": request.session.get("domain_id"),
                    "enabled": True,
                    "is_domain": False,
                }
            }

            keystone = KeystoneRestAPI(auth_url, token)
            result = keystone.create_project(data)
            if result.get("success"):  # 프로젝트 생성 성공
                project_id = result["success"]["project"].get("id")
                try:
                    soac_conn = SOAControlDBConnector.getInstance()
                    params = (auth_url, project_id, project.get("name"))
                    soac_conn.insert(INSERT_SOAC_PROJECT, params)
                except Exception as e:
                    logger.debug("soac 프로젝트 생성 실패(" + project.get("name") +
                                 ")" + str(e))
                    result = {
                        "error": {
                            "title": e.message,
                            "message": "soac db insert project error",
                            "code": 500
                        }
                    }

                try:
                    soam_conn = SOAManagerDBConnector.getInstance()
                    params = (auth_url, project_id, project.get("name"),
                              project.get("description"))
                    soam_conn.insert(INSERT_SOAM_PROJECT, params)
                except Exception as e:
                    logger.debug("soam 프로젝트 생성 실패(" + project.get("name") +
                                 ")" + str(e))
                    result = {
                        "error": {
                            "title": e.message,
                            "message": "soam db insert project error",
                            "code": 500
                        }
                    }

        return JsonResponse(result)
Exemplo n.º 2
0
def create_project(request):
    if request.is_ajax() and request.method == 'POST':
        token = request.session.get('passToken')
        auth_url = request.session.get('auth_url')
        project = json.loads(request.POST.get("project"))

        data = {
            "project": {
                "description": project.get("description"),
                "domain_id": project.get("domain_id"),
                "name": project.get("name"),
                "enabled": project.get("enabled"),
                "is_domain": False,
            }
        }
        keystone = KeystoneRestAPI(auth_url, token)
        result = keystone.create_project(data)
        if result.get("success"):
            project_id = result["success"]["project"].get("id")
            assign = json.loads(request.POST.get("assignList"))
            assign_users = assign.get("users")
            for assign_user in assign_users:
                user_id = assign_user.get("user_id")
                role_id_list = assign_user.get("role_id_list")
                for role_id in role_id_list:
                    assign_result = keystone.assign_role_to_user_on_projects(
                        project_id, user_id, role_id)
                    if assign_result.get("error"):
                        if not result.get("error"):
                            result["error"] = []
                        result["error"].append(assign_result["error"])
            assign_groups = assign.get("groups")
            for assign_group in assign_groups:
                group_id = assign_group.get("group_id")
                role_id_list = assign_group.get("role_id_list")
                for role_id in role_id_list:
                    assign_result = keystone.assign_role_to_group_on_projects(
                        project_id, group_id, role_id)
                    if assign_result.get("error"):
                        if not result.get("error"):
                            result["error"] = []
                        result["error"].append(assign_result["error"])

        return JsonResponse(result)
Exemplo n.º 3
0
def create_user_for_soa(request):
    if request.method == 'POST':
        # try:
            # body_str = request.body.decode('utf-8')
            # r_body = json.loads(body_str)
        # except ValueError as e:
        # result = {"error": {"title": e.message, "message": "json malformed error"}}
        # else:
        auth_url = request.GET.get("auth_url")
        user_name = request.GET.get("user_name")
        password = request.GET.get("pass")
        project_name = request.GET.get("project_name")
        soac_conn = SOAControlDBConnector.getInstance()
        domain = soac_conn.select_one(SELECT_SOAC_DOMAINS, auth_url)
        domain_name = domain.get("domain_name")
        result = common_login(request, auth_url, user_name, password, domain_name, project_name)

        if result.get("success"):
            token = request.session.get("passToken")
            project = json.loads(request.GET.get("project"))
            data = {"project": {
                "description": project.get("description"),
                "domain_id": request.session.get("domain_id"),
                "name": project.get("name"),
                "enabled": True,
                "is_domain": False,
            }}
            keystone = KeystoneRestAPI(auth_url, token)
            result = keystone.create_project(data)
            if result.get("success"):  # 프로젝트 생성 성공
                soam_conn = SOAManagerDBConnector.getInstance()
                domain = soam_conn.select_one(SELECT_SOAM_DOMAIN, auth_url)
                params = (domain.get("domain_id"), result["success"]["project"].get("id"), project.get("name"), project.get("description"))
                soam_conn.insert(INSERT_SOAM_PROJECT, params)

                params = (auth_url, result["success"]["project"].get("id"), project.get("name"))
                soac_conn.insert(INSERT_SOAC_PROJECT, params)

        return JsonResponse(result)