Esempio n. 1
0
def get_available_project_scopes(request):
    if request.is_ajax() and request.method == 'POST':
        token = request.session.get('passToken')
        domain_name = request.session.get("domain_name")
        project_name = request.session.get("project_name")
        auth_url = request.session.get("auth_url")

        try:
            keystone = KeystoneRestAPI(auth_url, token)
        except Unauthorized as e:
            return JsonResponse({
                "error": {
                    "title": e.message,
                    "message": e.details,
                    "code": 401
                }
            })

        # conn = SOAControlDBConnector.getInstance()
        # try:
        #     select_domains = conn.select(SELECT_DOMAINS)  # TODO: 도메인 리스트는 가져왔는데 권한에따라 도메인 리스트가 달라져야할지?
        # except Exception as e:
        #     result = {"error": {"message": str(e), "title": "에러"}}
        #     return JsonResponse(result)

        result = keystone.get_available_project_scopes()
        if result.get("success"):
            projects = result.get("success").get("projects")
            for project in projects:
                if project.get("name") == project_name:
                    project["click"] = True

        return JsonResponse(result)
Esempio n. 2
0
def get_available_domain_scopes(request):
    if request.is_ajax() and request.method == 'POST':
        token = request.session.get('passToken')
        domain_name = request.session.get("domain_name")
        domain_id = request.session.get("domain_id")
        auth_url = request.session.get("auth_url")
        try:
            keystone = KeystoneRestAPI(auth_url, token)
            result = keystone.get_available_domain_scopes()
        except Unauthorized as e:
            request.session["error"] = {
                "title": e.message,
                "message": e.details
            }
            return JsonResponse({
                "error": {
                    "title": e.message,
                    "message": e.details,
                    "code": 401
                }
            })
        if result.get("success"):
            if len(result["success"].get("domains")) == 0:
                domain = {"name": domain_name, "click": True}
                if domain_id:
                    domain["id"] = domain_id
                result.get("success").get("domains").append(domain)
            else:
                domains = result.get("success").get("domains")
                for domain in domains:
                    if domain.get("name") == domain_name:
                        domain["click"] = True

        return JsonResponse(result)
Esempio n. 3
0
def get_project_list(request):
    if request.is_ajax() and request.method == 'POST':
        pass
    else:
        project_name = request.session.get("project_name")
        auth_url = request.session.get("auth_url")
        token = request.session.get('passToken')
        domain_id = request.session.get('domain_id')
        if not token:
            return redirect("/dashboard/domains/?next=/dashboard/identity")
        keystone = KeystoneRestAPI(auth_url, token)
        data = None
        if domain_id:
            data = {"domain_id": domain_id}
        result = keystone.get_project_list(data)
        if result.get("success"):
            projects = result.get("success").get("projects")
            for project in projects:
                if project.get("name") == project_name:
                    project["click"] = True

            return render(request, 'identity/projects/index.html',
                          {"projects": projects})
        else:
            return render(request, 'identity/projects/index.html',
                          {"error": result.get("error")})
Esempio n. 4
0
def flavor_modal(request):
    data = {}
    auth_url = request.session.get("auth_url")
    token = request.session.get("passToken")
    flavor_id = request.GET.get("flavor_id")
    domain_id = request.session.get("domain_id")

    keystone = KeystoneRestAPI(auth_url, token)

    projects = keystone.get_project_list({"domain_id": domain_id})
    if projects.get("success"):
        data["projects"] = projects["success"].get("projects")

    if flavor_id:
        nova = NovaRestAPI(auth_url, token)
        flavor = nova.get_flavor(flavor_id)
        if flavor.get("success"):
            data["flavor"] = flavor["success"].get("flavor")
            access_projects = nova.get_flavor_access(flavor_id)
            if access_projects.get("success"):
                data["access_projects"] = [
                    project for project in data["projects"] for flavor_access
                    in access_projects["success"].get("flavor_access")
                    if project.get("id") == flavor_access.get("tenant_id")
                ]
                for idx in data["access_projects"]:
                    data["projects"].remove(idx)

    return render(request, 'admin/flavors/modal.html', data)
Esempio n. 5
0
def get_router_list(request):
    # logger.info("get_router_list")
    token = request.session.get('passToken')
    auth_url = request.session.get("auth_url")
    if request.method == 'POST':
        try:
            keystone = KeystoneRestAPI(auth_url, token)
            result_projects = keystone.get_project_list()
            projects = []
            if result_projects.get("success"):
                projects = result_projects["success"].get("projects")

            neutron = NeutronRestAPI(auth_url, token)
            result = neutron.getRouterList()
            if result.get("success"):
                for router in result["success"].get("routers"):
                    if router.get("tenant_id"):
                        for project in projects:
                            if project.get("id") == router.get("tenant_id"):
                                router["project_name"] = project.get("name")
        except Unauthorized as e:
            result = {
                "error": {
                    "title": e.message,
                    "message": e.details,
                    "code": 401
                }
            }
        return JsonResponse(result)
    else:
        token = request.session.get('passToken')
        if not token:
            return redirect(
                "/dashboard/domains/?next=/dashboard/admin/routers")
        return render(request, 'admin/routers/index.html', {})
Esempio n. 6
0
def get_instance_by_id(request):
    token = request.session.get('passToken')
    domain_name = request.session.get("domain_name")
    project_name = request.session.get("project_name")
    description = request.session.get("description")
    auth_url = request.session.get("auth_url")
    vm_id = request.POST.get("vm_id")

    nova = NovaRestAPI(auth_url, token)
    glance = GlanceRestAPI(auth_url, token)
    keystone = KeystoneRestAPI(auth_url, token)

    instance = nova.get_server(vm_id)
    flavor = nova.get_flavor(
        instance.get("success").get("server").get("flavor")["id"])
    if instance.get("success").get("server").get("image"):
        image = glance.get_image(
            instance.get("success").get("server").get("image").get("id"))
    else:
        image = {"success": {}}

    instance["success"]["server"]["flavor"] = flavor.get("success").get(
        "flavor")
    instance["success"]["server"]["image"] = image.get("success")
    instance["success"]["server"]["project_name"] = keystone.get_project(
        instance.get("success").get("server").get("tenant_id")).get(
            "success").get("project").get("name")
    result = instance
    return JsonResponse(result)
Esempio n. 7
0
def get_image_list(request):
    # logger.info("get_instance_list")
    # sess = login("admin", "chiron", "demo", "http://192.168.10.6/identity/v3", 'default')

    token = request.session.get('passToken')
    auth_url = request.session.get("auth_url")
    glance = GlanceRestAPI(auth_url, token)
    keystone = KeystoneRestAPI(auth_url, token)

    resultImageList = glance.get_image_list()
    imageList = resultImageList.get("success").get("images")
    for image in imageList:
        project = keystone.get_project(image.get("owner"))
        if project.get("success"):
            image["project_name"] = project.get("success").get("project").get(
                "name")

    if request.is_ajax() and request.method == 'POST':
        return JsonResponse(
            {"success": {
                "imageList": [image for image in imageList]
            }})
    else:
        return render(request, 'admin/images/index.html',
                      {'imageList': imageList})
Esempio n. 8
0
def delete_user(request, user_id):
    if request.is_ajax() and request.method == 'POST':
        token = request.session.get('passToken')
        auth_url = request.session.get('auth_url')
        keystone = KeystoneRestAPI(auth_url, token)
        result = keystone.delete_user(user_id)
        return JsonResponse(result)
Esempio n. 9
0
def get_project_list_for_user(request):
    if request.is_ajax() and request.method == 'POST':
        token = request.session.get('passToken')
        user_id = request.session.get("user_id")
        auth_url = request.session.get("auth_url")
        try:
            keystone = KeystoneRestAPI(auth_url, token)
        except Unauthorized as e:
            return JsonResponse({"error": {"title": e.message, "message": e.details, "code": 401}})
        result = keystone.get_project_list_for_user(user_id)
Esempio n. 10
0
def switch_project_with_token(request):
    token = request.session.get("passToken")
    if request.method == 'POST':
        data = json.loads(request.POST.get("data"))
        project_name = data.get("project_name")
        domain_name = request.session.get("domain_name")
        auth_url = request.session.get("auth_url")
        try:
            keystone = KeystoneRestAPI(auth_url, token)
        except Unauthorized as e:
            request.session["error"] = {
                "title": e.message,
                "message": e.details
            }
            return JsonResponse({
                "error": {
                    "title": e.message,
                    "message": e.details,
                    "code": 401
                }
            })
        # result = keystone.get_token_with_scoped_by_token(project_id=project_id)
        result = keystone.get_token_with_scoped_by_token(
            domain_name=domain_name, project_name=project_name)
        if result.get("success"):
            # request.session.set_expiry(SESSION_COOKIE_AGE)
            token = result['success']['token']
            request.session["passToken"] = token
            request.session["project_name"] = project_name

            roles = result["success"].get("roles")
            if roles:
                roles_str = ','.join(role.get("name") for role in roles)
            else:
                roles_str = ""

            user = result["success"].get("user")
            project = result["success"].get("project")
            request.session["user_id"] = user.get("id")
            request.session["user_name"] = user.get("name")
            request.session["project_id"] = project.get("id")

            request.session["roles"] = roles_str
            ctrl_engine = ControlEngine(token=token,
                                        project_id=project.get("id"),
                                        project_name=project_name,
                                        user_id=user.get("id"),
                                        user_name=user.get("name"),
                                        roles=roles_str,
                                        auth_url=auth_url)
            request.session["ctrl_header"] = ctrl_engine.get_header()

        return JsonResponse(result)
Esempio n. 11
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)
Esempio n. 12
0
def update_role(request, role_id):
    if request.is_ajax() and request.method == 'POST':
        token = request.session.get('passToken')
        auth_url = request.session.get("auth_url")
        role = json.loads(request.POST.get("role"))
        data = {
            "role": {
                "name": role.get("name"),
            }
        }
        keystone = KeystoneRestAPI(auth_url, token)
        result = keystone.update_role(role_id, data)
        return JsonResponse(result)
Esempio n. 13
0
def create_user_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")
            user_list = data.get("user")

            response_data = {}
            for user in user_list:
                data = {
                    "user": {
                        "default_project_id": user.get("default_project_id"),
                        "name": user.get("name"),
                        "password": user.get("password"),
                        "email": user.get("email"),
                        "domain_id": request.session.get("domain_id"),
                        "enabled": True,
                        "description": u"SOA 관리포털에서 생성"
                    }
                }

                keystone = KeystoneRestAPI(auth_url, token)
                result = keystone.create_user(data)
                if result.get("success"):
                    created_user = result["success"].get("user")

                    params = (auth_url, created_user.get("default_project_id"),
                              created_user.get("id"), created_user.get("name"))

                    try:
                        soa_conn = SOAControlDBConnector.getInstance()
                        soa_conn.insert(INSERT_SOAC_USER, params)
                    except Exception as e:
                        logger.debug("soac 사용자 생성 실패(" +
                                     created_user.get("name") + ")" + str(e))
                        result = {
                            "error": {
                                "title": e.message,
                                "message": "soac db insert user error",
                                "code": 500
                            }
                        }
                        # end except
                    # end if
                response_data[user.get("name")] = result
                # end for
            result = response_data
            # end if
        return JsonResponse(result)
Esempio n. 14
0
def update_group(request, group_id):
    if request.is_ajax() and request.method == 'POST':
        token = request.session.get('passToken')
        auth_url = request.session.get('auth_url')
        group = json.loads(request.POST.get("group"))
        data = {
            "group": {
                "description": group.get("description"),
                "domain_id": group.get("domain_id"),
                "name": group.get("name"),
            }
        }
        keystone = KeystoneRestAPI(auth_url, token)
        result = keystone.update_group(group_id, data)
        return JsonResponse(result)
Esempio n. 15
0
def get_user_by_id(request, user_id):
    token = request.session.get('passToken')
    auth_url = request.session.get("auth_url")
    if request.is_ajax() and request.method == 'POST':
        pass
    else:
        if not token:
            return redirect("/dashboard/domains/?next=/dashboard/identity/users/" + user_id + "/detail")
        keystone = KeystoneRestAPI(auth_url, token)
        result = keystone.get_user(user_id)
        if result.get("success"):
            user = result.get("success")
            return render(request, 'identity/users/info.html', user)
        else:
            return render(request, 'identity/users/info.html', result)
Esempio n. 16
0
def update_user(request, user_id):
    if request.is_ajax() and request.method == 'POST':
        token = request.session.get('passToken')
        auth_url = request.session.get('auth_url')
        keystone = KeystoneRestAPI(auth_url, token)
        user = json.loads(request.POST.get("user"))
        data = {
            "user": {
                k: v
                for k, v in user.items()
                if v is not None
            }
        }
        result = keystone.update_user(user_id, data)
        return JsonResponse(result)
Esempio n. 17
0
def get_group_list(request):
    if request.is_ajax() and request.method == 'POST':
        pass
    else:
        auth_url = request.session.get("auth_url")
        token = request.session.get('passToken')
        keystone = KeystoneRestAPI(auth_url, token)
        result = keystone.get_group_list()
        if result.get("success"):
            groups = result.get("success").get("groups")

            return render(request, 'identity/groups/index.html',
                          {"groups": groups})
        else:
            return render(request, 'identity/groups/index.html',
                          {"error": result.get("error")})
Esempio n. 18
0
def check_domain(request):
    try:
        result = KeystoneRestAPI.check_status(request.POST.get("auth_url"))
        result["domain_key"] = request.POST.get("domain_key")
    except Exception as e:
        result = {"version": {"status": "error"}}
    return JsonResponse({"success": result})
Esempio n. 19
0
def get_role_list(request):
    if request.is_ajax() and request.method == 'POST':
        pass
    else:
        token = request.session.get('passToken')
        auth_url = request.session.get("auth_url")
        keystone = KeystoneRestAPI(auth_url, token)
        result = keystone.get_role_list()
        if not token:
            return redirect(
                "/dashboard/domains/?next=/dashboard/identity/roles")
        if result.get("success"):
            return render(request, 'identity/roles/index.html',
                          result.get("success"))
        else:
            return render(request, 'identity/roles/index.html', result)
Esempio n. 20
0
def get_network_list(request):
    # logger.info("get_network_list")
    token = request.session.get('passToken')
    auth_url = request.session.get("auth_url")
    if request.method == "GET":
        if not token:
            return redirect(
                "/dashboard/domains/?next=/dashboard/admin/networks")
    neutron = NeutronRestAPI(auth_url, token)
    query = {}
    if request.method == "GET" and request.GET.get("project_id"):
        query["tenant_id"] = request.GET.get("project_id")
    elif request.method == "POST" and request.POST.get("project_id"):
        query["tenant_id"] = request.POST.get("project_id")
    result = neutron.get_network_list(q=query)

    if result.get("success"):
        keystone = KeystoneRestAPI(auth_url, token)
        projects = keystone.get_project_list(fields={"fields": ["id", "name"]})
        subnets = neutron.get_subnet_list(fields=["id", "name", "cidr"])
        for network in result["success"].get("networks"):
            # project id로 project_name 추가
            if projects.get("success"):
                for project in projects["success"].get("projects"):
                    if project.get("id") == network.get("tenant_id"):
                        network["project_name"] = project.get("name")
            # project id로 project_name 추가끝
            # subnet id로 subnetList 추가
            if subnets.get("success"):
                network["subnets"] = [
                    subnet for subnet_id in network.get("subnets")
                    for subnet in subnets["success"].get("subnets")
                    if subnet.get("id") == subnet_id
                ]
            # subnet id로 subnetList 추가끝
        result = result.get("success")
    if request.is_ajax():
        return JsonResponse(result)
    else:
        if request.method == "GET":
            try:
                soam_sync = bool(
                    config.get("SETTINGS", "PORTAL_SYNC") == "True")
            except Exception as e:
                soam_sync = False
            result["sync"] = soam_sync  # TODO: soam sync delete
            return render(request, 'admin/networks/index.html', result)
Esempio n. 21
0
def alarms(request):
    """
    알람 수신
    :param request:
    :return:
    """
    if request.method == 'POST':
        logger.debug("[POST] alarm\n{}".format(request.body))
        data = json.loads(request.body)
        sendto = data.get("sendto")
        subject = data.get("subject")
        recovery_info = data.get("message")
        message = json.dumps(recovery_info)
        data = (
            subject,
            message,
            sendto
        )
        conn = SOAControlDBConnector()

        domain = conn.select_one(SELECT_DOMAINS_ONE_BY_AUTH_URL, recovery_info.get("auth_url"))
        db_user = domain.get("db_user")
        db_pass = domain.get("db_password")
        db_ip = domain.get("db_ip")
        db_port = domain.get("db_port")
        auth_url = domain.get("auth_url")
        d_conn = SOAControlDomainDBConnector(db_nm="soacgui", db_user=db_user, db_pass=db_pass, db_ip=db_ip, db_port=db_port)
        d_conn.insert(INSERT_ALARM, data)
        err_msg_list = []
        domain["os_admin_id"] = "admin"
        domain["os_admin_pass"] = "******"
        result_token = KeystoneRestAPI.get_token(auth_url, domain.get("os_admin_id"), domain.get("os_admin_pass"), domain.get("domain_name"), recovery_info.get("project_name"))
        if result_token.get("success"):
            if recovery_info.get("server"):
                nova = NovaRestAPI(auth_url, result_token["success"].get("token"))
                vm_id = recovery_info["server"].get("vm_id")
                result_is_exist_vm = nova.get_server(vm_id, ["id", "name"])
                if result_is_exist_vm.get("error") and result_is_exist_vm["error"].get("code") == 404:
                    message = "not Found vm(" + vm_id + ")"
                    data = (subject, message, sendto)
                    conn.insert(INSERT_ALARM, data)
                    return JsonResponse({"result": message})
                ctrl_header = get_ctrl_header_for_recorvery(auth_url, result_token["success"])
                result = recover_vm(recovery_info["server"], ctrl_header, domain)
                if result.get("success"):
                    recovery_info["recovery"] = True
                    conn.insert(INSERT_ALARM, (
                        subject, json.dumps(recovery_info), sendto
                    ))
                elif result.get("error"):
                    err_msg_list = result["error"]
        else:
            err_msg_list.append(result_token.get("error"))
        if len(err_msg_list) > 0:
            data = (
                subject, json.dumps(err_msg_list), sendto
            )
            d_conn.insert(INSERT_ALARM, data)
    return JsonResponse({"result": True})
Esempio n. 22
0
def get_volume_by_id(request, volume_id):
    # logger.info("get_volume_by_id")
    token = request.session.get('passToken')
    auth_url = request.session.get("auth_url")
    if not token:
        return redirect("/dashboard/domains/?next=/dashboard/admin/volumes/" + volume_id)
    cinder = CinderRestAPI(auth_url, token)
    keystone = KeystoneRestAPI(auth_url, token)
    result_volume = cinder.get_volume_by_id(volume_id)
    volume = result_volume.get("success").get("volume")
    result_project = keystone.get_project(volume.get("os-vol-tenant-attr:tenant_id"))
    if result_project.get("success"):
        project = result_project["success"].get("project")
        volume["project_name"] = project.get("name")
    volume["host"] = volume.get("os-vol-host-attr:host")
    volume["type"] = volume.get("volume_type")
    return render(request, 'admin/volumes/info.html', {'volume': volume})
Esempio n. 23
0
def get_user_list(request):
    if request.is_ajax() and request.method == 'POST':
        pass
    else:
        token = request.session.get('passToken')
        auth_url = request.session.get("auth_url")
        domain_id = request.session.get("domain_id")
        if not token:
            return redirect("/dashboard/domains/?next=/dashboard/identity/users")
        keystone = KeystoneRestAPI(auth_url, token)
        data = None
        if domain_id:
            data = {"domain_id": domain_id}
        result = keystone.get_user_list(data)
        if result.get("success"):
            result = result.get("success")
        return render(request, 'identity/users/index.html', result)
Esempio n. 24
0
def delete_project(request, project_id):
    if request.is_ajax() and request.method == 'POST':
        token = request.session.get('passToken')
        auth_url = request.session.get('auth_url')
        keystone = KeystoneRestAPI(auth_url, token)
        result = keystone.delete_project(project_id)
        try:
            soac_conn = SOAControlDBConnector.getInstance()
            params = (request.session.get("domain_name"), project_id)
            project = soac_conn.select_one(
                SELECT_SOAC_PROJECT_LIST + "AND PROJECT_ID = %s", )
            if project:
                soam_conn = SOAManagerDBConnector.getInstance()
                soam_conn.update(DELETE_SOAM_PROJECT, params)
        except Exception as e:
            pass
        return JsonResponse(result)
Esempio n. 25
0
def get_project_by_id(request, project_id):
    if request.is_ajax() and request.method == 'POST':
        pass
    else:
        token = request.session.get('passToken')
        if not token:
            return redirect(
                "/dashboard/domains/?next=/dashboard/identity/projects/" +
                project_id + "/detail")
        auth_url = request.session.get("auth_url")
        keystone = KeystoneRestAPI(auth_url, token)
        result = keystone.get_project(project_id)
        if result.get("success"):
            project = result.get("success")
            return render(request, 'identity/projects/info.html', project)
        else:
            return render(request, 'identity/projects/info.html',
                          {"error": result.get("error")})
Esempio n. 26
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)
Esempio n. 27
0
def retrieve_service_list(request):
    # logger.info("retrieve_service_list")
    pattern = re.compile(
        "http://([\\d]{1,3}.[\\d]{1,3}.[\\d]{1,3}.[\\d]{1,3})")
    token = request.session.get('passToken')
    auth_url = request.session.get("auth_url")
    keystone = KeystoneRestAPI(auth_url, token)
    result = keystone.get_service_list()
    if result.get("success"):
        service_list = result["success"].get("services")
        for service in service_list:
            matcher = pattern.match(service["links"]["self"])
            if matcher:
                service["host"] = matcher.group(1)
    else:
        service_list = result
    if not token:
        return redirect("/dashboard/domains/?next=/dashboard/admin/info")
    return render(request, 'admin/info/index.html', {"services": service_list})
Esempio n. 28
0
def get_domain_list(request):
    if request.is_ajax() and request.method == 'POST':
        token = request.session.get('passToken')
        domain_name = request.session.get("domain_name")
        auth_url = request.session.get("auth_url")
        try:
            keystone = KeystoneRestAPI(auth_url, token)
            result = keystone.get_domain_list()
        except Unauthorized as e:
            request.session["error"] = {
                "title": e.message,
                "message": e.details
            }
            return JsonResponse({
                "error": {
                    "title": e.message,
                    "message": e.details,
                    "code": 401
                }
            })
        if result.get("success"):
            domains = result.get("success").get("domains")
            removeDomain = None
            for domain in domains:
                if domain.get("name") == domain_name:
                    domain["click"] = True
                if domain.get("name") == "heat":
                    removeDomain = domain
            if removeDomain:
                domains.remove(removeDomain)

        if result.get("error"):
            if result["error"].get("code") == 403:
                result["success"] = {
                    "domains": [{
                        "name": domain_name,
                        "id": domain_name,
                        "click": True
                    }]
                }

        return JsonResponse(result)
Esempio n. 29
0
def role_modal(request):
    token = request.session.get('passToken')
    auth_url = request.session.get("auth_url")
    modal_title = request.GET.get("modal_title")
    role_id = request.GET.get("role_id")
    domain_id = request.session.get("domain_id")
    domain_name = request.session.get("domain_name")
    data = {
        "modal_title": modal_title,
        "input_domain_id": domain_id,
        "input_domain_name": domain_name,
    }
    if role_id:
        data["role_id"] = role_id
        keystone = KeystoneRestAPI(auth_url, token)
        result = keystone.get_role(role_id)
        if result.get("success"):
            role = result["success"].get("role")
            data["role_name"] = role.get("name")
    return render(request, 'identity/roles/modal.html', data)
Esempio n. 30
0
def create_user(request):
    if request.is_ajax() and request.method == 'POST':
        token = request.session.get('passToken')
        auth_url = request.session.get('auth_url')
        keystone = KeystoneRestAPI(auth_url, token)
        user = json.loads(request.POST.get("user"))
        data = {
            "user": {
                k: v
                for k, v in user.items()
                if v is not None and k not in ["role_id", "domain_name"]
            }
        }
        result = keystone.create_user(data)
        if result.get("success") and user.get("default_project_id"):
            created_user = result["success"].get("user")
            a_result = keystone.assign_role_to_user_on_projects(user.get("default_project_id"), created_user.get("id"), user.get("role_id"))
            if a_result.get("error"):
                result["error"] = a_result["error"]
        return JsonResponse(result)