Пример #1
0
def servers():
    """
    This function will return the list of servers for the specified
    server id.
    """
    res = []
    try:
        """Return a JSON document listing the server groups for the user"""
        driver = get_driver(PG_DEFAULT_DRIVER)

        from pgadmin.browser.server_groups.servers import\
            server_icon_and_background

        for server in Server.query.filter_by(user_id=current_user.id):
            manager = driver.connection_manager(server.id)
            conn = manager.connection()
            connected = conn.connected()

            res.append({
                "value": server.id,
                "label": server.name,
                "image": server_icon_and_background(connected, manager,
                                                    server),
                "_id": server.id,
                "connected": connected,
            })

    except Exception as e:
        app.logger.exception(e)

    return make_json_response(data=res)
Пример #2
0
def servers():
    """
    This function will return the list of servers for the specified
    server id.
    """
    res = {}
    auto_detected_server = None
    try:
        """Return a JSON document listing the server groups for the user"""
        driver = get_driver(PG_DEFAULT_DRIVER)

        from pgadmin.browser.server_groups.servers import\
            server_icon_and_background

        for server in Server.query.filter(
                or_(Server.user_id == current_user.id, Server.shared)):

            shared_server = SharedServer.query.filter_by(
                name=server.name,
                user_id=current_user.id,
                servergroup_id=server.servergroup_id).first()

            if server.discovery_id:
                auto_detected_server = server.name

            if shared_server and shared_server.name == auto_detected_server:
                continue

            manager = driver.connection_manager(server.id)
            conn = manager.connection()
            connected = conn.connected()
            server_info = {
                "value": server.id,
                "label": server.name,
                "image": server_icon_and_background(connected, manager,
                                                    server),
                "_id": server.id,
                "connected": connected
            }

            if server.servers.name in res:
                res[server.servers.name].append(server_info)
            else:
                res[server.servers.name] = [server_info]

    except Exception as e:
        app.logger.exception(e)

    return make_json_response(data=res)