Exemplo n.º 1
0
def removeServerFromCluster(clusterName, serverName):
    code = None
    reval = None
    params = []
    params.append(clusterName)
    params.append(serverName)
    status, clusterid, server_id = get_server(clusterName, serverName)
    if status == "-1":
        code, reval = "20052", "No cluster " + clusterName + "."
    elif status == "-2":
        code, reval = "20054", "server " + serverName + " is not in cluster " + clusterName
    elif Utils.isOnline(serverName) == False:
        code, reval = "22008", "Server " + serverName + " is not online"
    if code is not None:
        result = Utils.errorCode(code, reval, params)
        logger.error(reval)
        raise web.HTTPError(status="400 Bad Request", data=result)
    try:
        servers = Globals.db.select("server_info", what="*", where="cluster_id=$clusterid", vars=locals())
        if len(servers) == 0:
            logger.info("This server[" + serverName + "] not contained in table server_info")
            return ""
        if len(servers) == 1:
            Globals.db.delete("server_info", where="id=$server_id", vars=locals())
            logger.info("delete server[" + serverName + "] from table server_info")
            return ""
        for server in servers:
            if (Utils.getIPByName(server.name) != Utils.getIPByName(serverName)) and (
                server.name.strip() != serverName
            ):
                break

        if Utils.isLocalHost(serverName):
            status, ip = Utils.getLocal_IP()
        else:
            ip = Utils.getIPByName(serverName)
        status, msg = Utils.executeOnServer(server.name, "gluster --mode=script peer detach " + ip)
        if status == -1:
            code, reval = (
                "26104",
                "error when connecting to remote host " + serverName + " from localhost " + server.name + "." + msg,
            )
        elif status == -2:
            code, reval = "26059", "Error when using pub key to connect remote server " + serverName + "." + msg
        elif status == 1:
            code, reval = "22014", 'Error when executing "gluster --mode=script peer detach ' + ip + '"' + msg
        if code is not None:
            result = Utils.errorCode(code, reval, params)
            web.HTTPError(status="400 Bad Request", data="")
            logger.error(reval)
            return result
        Globals.db.delete("server_info", where="id=$server_id", vars=locals())
        return ""
    except Exception, e:
        code, reval = "22101", "failed to remove server " + serverName + "." + str(e)
        logger.error(reval)
        result = Utils.errorCode(code, reval, params)
        raise web.HTTPError(status="400 Bad Request", data=result)
Exemplo n.º 2
0
def migrateBrick(clusterName, volumeName):
    autoCommit = False
    try:
        data = web.input()
        serverName, code, reval = isPathExist(clusterName, volumeName, data)
        if code == 0:
            source = data.source
            target = data.target
            server_dir = target.split(":")
            target = Utils.getIPByName(server_dir[0].strip()) + ":" + server_dir[1]
            commandWithArgs = "gluster volume replace-brick " + volumeName + " " + source + " " + target + " start"
            status, message = Utils.executeOnServer(serverName, commandWithArgs)
            if status != 0:
                code, reval = "23012", "Error when migrate a brick:" + message
            else:
                description = "Brick Migration on volume [" + volumeName + "] from [" + source + "] to [" + target + "]"
                reference = volumeName + "#" + source + "#" + target
                operation_id = 2
                db.insert(
                    "task_info",
                    description=description,
                    reference=reference,
                    operation_id=operation_id,
                    cluster_name=clusterName,
                )
                autoCommit_str = data.autoCommit
                if autoCommit_str is not None:
                    if autoCommit_str == "true":
                        autoCommit = True
                    else:
                        autoCommit = False
                        logger.info(description)
                        return ""
    except Exception, e:
        if str(e) == "'autoCommit'":
            return ""
        code, reval = "23012", "Error when migrate a brick:" + str(e)
Exemplo n.º 3
0
         except:
             pass
         Globals.db.insert("server_info", name=serverName, cluster_id=clusterid)
         if status is not "0":
             web.HTTPError(status="400 Bad Request", data="")
             logger.error("Error when installing pubKey on server[" + serverName + "]: " + output)
             return Utils.errorCode(status, output, [])
     logger.info("Add the first server[" + serverName + "] to cluster[" + clusterName + "] successfully!")
     return ""
 status, output = Utils.installPubKey(serverName)
 if status is not "0":
     web.HTTPError(status="400 Bad Request", data="")
     logger.error("Error when installing pubKey on server[" + serverName + "]: " + output)
     return Utils.errorCode(status, output, [])
 server = server_info[0]
 status, output = Utils.executeOnServer(server.name, "gluster peer probe " + Utils.getIPByName(serverName))
 if status == -1:
     code, reval = (
         "26104",
         "error when connecting to remote host " + serverName + " from localhost " + server.name + "." + output,
     )
 elif status == -2:
     code, reval = "26059", "Error when using pub key to connect remote server " + serverName + "." + output
 elif status == 1:
     code, reval = (
         "22013",
         'Error when executing "gluster peer probe ' + Utils.getIPByName(serverName) + '"' + output,
     )
 if code is not None:
     params = []
     params.append(clusterName)