def getServersInfo(serverNameInfo,clusterName): sum = 0 online = 0 serversInfo = [] servers = [] sum = len(serverNameInfo) totalSpace = Decimal("0.0") usedSpace = Decimal("0.0") strs = str(clusterName) + "_servers" message = Globals.mc.get(strs) if message is not None: serversInfo = message else: for server in serverNameInfo: serverName = str(server.name) servers.append(serverName) if Utils.isOnline(serverName) == True: cmd = 'python ' + Globals.BACKEND_SCRIPT + 'get_server_bricks.py' status,message = Utils.executeOnServer(serverName, cmd) if status == 0: if message.strip() != '[]': message = message.replace("['",'') message = message.replace("']",'') info = message.split(':') usedSpace = usedSpace + Decimal(info[2]) totalSpace = totalSpace + Decimal(info[3]) online = online + 1 serversInfo.append(online) serversInfo.append(sum) serversInfo.append(usedSpace) serversInfo.append(totalSpace) serversInfo.append(servers) return serversInfo
def getNeofsStatus(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: commandWithArgs = "sh " + Globals.BACKEND_SCRIPT + "neofs_status.sh" status, message = Utils.executeOnServer(serverName, commandWithArgs) responseDom = XmlHandler.ResponseXml() tasksTag = responseDom.appendTagRoute("responseStatus") tasksTag.appendChild(responseDom.createTag("status", message)) logger.info("Get neofs mount status: " + message) return tasksTag.toxml() except Exception, e: code, reval = "22202", "Error when get neofs status on server:" + str(e)
def getOnlineServer(cluster_id): server_name_info = db.select('server_info',where='cluster_id=$cluster_id' ,what="name",vars=locals()) servers = [] for server in server_name_info: if Utils.isOnline(server.name) == True: serverName = server.name servers.append(serverName.strip()) return servers
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)
def getServer(clusterName, serverName): status, cluster_info, server_info = get_server(clusterName, serverName) code = None reval = None if status == "-1": code, reval = "20052", "No cluster " + clusterName elif status == "-2": code, reval = "20054", "No server " + serverName + " 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, []) logger.error(reval) raise web.HTTPError(status="400 Bad Request", data=result) try: serverName = str(serverName) message = Globals.mc.get(serverName + "_server") if message is not None: logger.info("Get server[" + serverName + "]'s details from memcache:" + message) return message cmd = "python " + Globals.BACKEND_SCRIPT + "get_server_details.py" status, message = Utils.executeOnServer(serverName, cmd) if status == -1: code, reval = "26104", message elif status == -2: code, reval = "26059", "Error when using pub key to connect remote server " + serverName + "." + message elif status == 1: code, reval = "22002", "error when getting details from server " + serverName + "." + message if code is not None: result = Utils.errorCode(code, reval, []) logger.error(reval) raise web.HTTPError(status="400 Bad Request", data=result) logger.info("Get server[" + serverName + "]'s details by executing get_server_details.py:" + message) return message except Exception, e: code, reval = "22002", "Error when getting servers list:" + str(e) result = Utils.errorCode(code, reval, []) logger.error(reval) raise web.HTTPError(status="400 Bad Request", data=result)
def getVolumesInfo(clusterName): strs = str(clusterName) + "_volumes" message = Globals.mc.get(strs) if message is not None: return message onlineNum = 0 totalNum = 0 volumes = [] cluster_info = Globals.db.select('cluster_info',where='name=$clusterName',what='*',vars=locals()) clusterid = cluster_info[0].id server_info = Globals.db.select('server_info', where='cluster_id=$clusterid',vars=locals()) for server in server_info: if Utils.isOnline(str(server.name)) == False: continue status, message = Utils.executeOnServer(str(server.name), 'gluster volume list') if message.strip() != 'No volumes present in cluster': volumeList = message.split('\n') if len(volumeList) != 0: onlineNum = 0 totalNum = 0 volumes = [] for v in volumeList: if v.strip() != '': cmd = "python " + Globals.BACKEND_SCRIPT + "get_volumes.py " + v status,message = Utils.executeOnServer(str(server.name), cmd) totalNum += 1 volumes.append(v) if status == 0: weblog = xml.etree.ElementTree.fromstring(message) for entry in weblog.findall('status'): status = entry.text if status.strip().lower() == 'online': onlineNum += 1 clusterVolumeInfo = [] clusterVolumeInfo.append(onlineNum) clusterVolumeInfo.append(totalNum) clusterVolumeInfo.append(volumes) return clusterVolumeInfo
def operationServer(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: data = web.input() operationName = data.operation if operationName == "mount": commandWithArgs = "sh " + Globals.BACKEND_SCRIPT + "neofs_setup.sh " + serverName status, message = Utils.executeOnServer(serverName, commandWithArgs) return "" elif operationName == "umount": commandWithArgs = "sh " + Globals.BACKEND_SCRIPT + "neofs_teardown.sh " + serverName status, message = Utils.executeOnServer(serverName, commandWithArgs) return "" elif operationName == "remount": commandWithArgs = "sh " + Globals.BACKEND_SCRIPT + "neofs_teardown.sh " + serverName status, message = Utils.executeOnServer(serverName, commandWithArgs) commandWithArgs = "sh " + Globals.BACKEND_SCRIPT + "neofs_setup.sh " + serverName status, message = Utils.executeOnServer(serverName, commandWithArgs) return "" else: return "22200", "Error no such operation on server" except Exception, e: code, reval = "22201", "Error when operation a cluster:" + str(e)
def getServers(clusterName, details="true"): code = None reval = None status, cluster_info, server_info = get_servers(clusterName) if status == "-1": code, reval = "20052", "No cluster " + clusterName + "." result = Utils.errorCode(code, reval, []) logger.error(reval) raise web.HTTPError(status="400 Bad Request", data=result) if status == "-2": web.HTTPError(status="200 OK") logger.info("Servers list is None") return "<servers></servers>" try: responseDom = XmlHandler.ResponseXml() serversTag = responseDom.appendTagRoute("servers") if details.lower() != "true": for server in server_info: glusterServerTag = responseDom.createTag("glusterServer") glusterServerTag.appendChild(responseDom.createTag("name", server.name)) glusterServerTag.appendChild(responseDom.createTag("id", server.id)) serversTag.appendChild(glusterServerTag) web.HTTPError(status="200 OK") logger.info("Get servers's name list - 200 OK") return serversTag.toxml() else: retval = "" cmd = "python " + Globals.BACKEND_SCRIPT + "get_server_details.py 2>/dev/null" offline = [] for server in server_info: if Utils.isOnline(server.name) == False: offline.append(server.name) else: serverName = str(server.name) message = Globals.mc.get(serverName + "_server") if message is not None: retval += message else: status, message = Utils.executeOnServer(server.name, cmd) if status == -1: code, reval = "26104", message elif status == -2: code, reval = ( "26059", "Error when using pub key to connect remote server " + server.name + "." + message, ) elif status == 1: code, reval = ( "22002", "error when getting details from server " + server.name + "." + message, ) if code is not None: result = Utils.errorCode(code, reval, []) web.HTTPError(status="400 Bad Request", data="") logger.error(reval) return result retval += message result = "" if len(offline): for server in offline: serverxml = "<glusterServer><name>" + server + "</name><status>OFFLINE</status></glusterServer>" result += serverxml retval += result if (retval is not None) and (retval.strip() is not ""): web.HTTPError(status="200 OK") logger.info("Get servers's details info:" + retval) return "<servers>" + retval + "</servers>" except Exception, e: code, reval = "22002", "Error when getting servers list:" + str(e) result = Utils.errorCode(code, reval, []) logger.error(reval) raise web.HTTPError(status="400 Bad Request", data=result)
serverName = data.serverName except Exception, e: code, reval = "22010", "Error when getting servers list:serverName is required" + str(e) logger.error(reval) result = Utils.errorCode(code, reval, []) raise web.HTTPError(status="400 Bad Request", data=result) status, clusterid, serverid = get_server(clusterName, serverName) params = [] params.append(clusterName) params.append(serverName) if status == "-1": code, reval = "20052", "No cluster " + clusterName + "." elif serverid is not None: code, reval = "20104", "server " + serverName + " is already in cluster " + clusterName + "." elif not Utils.isOnline(serverName): code, reval = "22008", 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: server_info = Globals.db.select("server_info", what="*", where="name=$serverName", vars=locals()) if len(server_info) > 0: code, reval = ( "22001", "Error when adding server " + serverName + " to cluster " + clusterName + ". server "