Ejemplo n.º 1
0
def registerESServer(server_id):
    try:
        server = ElasticServer.get(ElasticServer.id == server_id)

        if server.is_registered is True:
            return generateErrorResponse(None, "Server is already registered", [], HttpStatusCodes['BAD_REQUEST'])
        else:
            result = registerServer(server.host,
                                    server.region,
                                    request.json['repository_name'],
                                    request.json['bucket'],
                                    request.json['role_name'],
                                    request.json['account_id'], )
            if result is None:
                return generateErrorResponse(None, "Something went wrong while registering server", [],
                                             HttpStatusCodes['INTERNAL_SERVER_ERROR'])
            else:
                server.is_registered = True
                server.save()
                return generateSuccessResponse(result)

    except Exception:
        return generateErrorResponse(None, "Something went wrong while registering server", [],
                                     HttpStatusCodes['INTERNAL_SERVER_ERROR'])

    return generateSuccessResponse(True)
Ejemplo n.º 2
0
def getSSRepositories(server_id):
    try:
        server = ElasticServer.get(ElasticServer.id == server_id)

        if server.is_registered is False:
            return generateErrorResponse(None, "Server is not registered", [], HttpStatusCodes['BAD_REQUEST'])
        else:
            result = getSnapshotRepositories(server.host)
            if result is None:
                return generateErrorResponse(None, "Something went wrong while getting snapshot repositories", [],
                                             HttpStatusCodes['INTERNAL_SERVER_ERROR'])
            else:
                return generateSuccessResponse(result)

    except Exception:
        return generateErrorResponse(None, "Something went wrong while getting snapshot repositories", [],
                                     HttpStatusCodes['INTERNAL_SERVER_ERROR'])

    return generateSuccessResponse(True)
Ejemplo n.º 3
0
def createESServer():
    try:
        try:
            server = ElasticServer.create(host=request.json['host'], created_at=getCurrentTimeMillis(),
                                          region=request.json['region'])
            server.save()
        except peewee.IntegrityError:
            return generateErrorResponse(None, "Elastic server is already added", [], HttpStatusCodes['BAD_REQUEST'])
    except Exception:
        return generateErrorResponse(None, "Something went wrong while saving server", [],
                                     HttpStatusCodes['INTERNAL_SERVER_ERROR'])
    return generateSuccessResponse(model_to_dict(server))
Ejemplo n.º 4
0
def getServerById():
    if 'id' in request.args:
        id = int(request.args['id'])
    else:
        return generateErrorResponse(None, "No server id field provided. Please specify an id.", [],
                                     HttpStatusCodes['BAD_REQUEST'])
    try:
        server = ElasticServer.get(ElasticServer.id == id)
    except:
        return generateErrorResponse(None, "No server id field provided. Please specify an id.", [],
                                     HttpStatusCodes['BAD_REQUEST'])
    return generateSuccessResponse(model_to_dict(server))
Ejemplo n.º 5
0
def getAllServers():
    servers = []
    for server in ElasticServer.select():
        print(server)
        servers.append(model_to_dict(server))
    return generateSuccessResponse(servers)