def run(self, serverState, request, response): target_str=request.getParam('user') userhandler = UserHandler() target_user_obj=userhandler.getUserFromString(target_str) if target_user_obj is None: raise ServerCommandError("User %s doesn't exist"%target_str) userhandler.deleteUser(target_user_obj) response.add('Deleted user %s'%target_str)
def run(self, serverState, request, response): target_str = request.getParam('user') userhandler = UserHandler() target_user_obj = userhandler.getUserFromString(target_str) if target_user_obj is None: raise ServerCommandError("User %s doesn't exist" % target_str) userhandler.deleteUser(target_user_obj) response.add('Deleted user %s' % target_str)
def run(self, serverState, request, response): user = request.getParam('user') password = request.getParam('password') userhandler = UserHandler() try: userhandler.addUser(user, password, UserLevel.REGULAR_USER) except UserError as e: raise cpc.util.CpcError("Error adding user: %s" % str(e)) response.add('Created user %s' % user)
def run(self, serverState, request, response): user=request.getParam('user') password=request.getParam('password') userhandler = UserHandler() try: userhandler.addUser(user,password, UserLevel.REGULAR_USER) except UserError as e: raise cpc.util.CpcError("Error adding user: %s"%str(e)) response.add('Created user %s'%user)
def run(self, serverState, request, response): user = request.getParam('user') userhandler = UserHandler() try: user_obj = userhandler.getUserFromString(user) user_obj.demote() response.add('Demoted user %s to level %s' % (user, user_obj.getUserlevelAsString())) except UserError as e: raise cpc.util.CpcError("Error demoting user: %s" % str(e))
def run(self, serverState, request, response): user=request.getParam('user') userhandler = UserHandler() try: user_obj = userhandler.getUserFromString(user) user_obj.demote() response.add('Demoted user %s to level %s'%( user, user_obj.getUserlevelAsString())) except UserError as e: raise cpc.util.CpcError("Error demoting user: %s"%str(e))
def run(self, serverState, request, response): name=request.getParam('name') prj=self.getProject(request, serverState) prjName=prj.getName() usrhandler = UserHandler() target_user=usrhandler.getUserFromString(name) if target_user is None: raise ProjectServerCommandException("User %s doesn't exist"%name) usrhandler.addUserToProject(target_user, prjName) response.add("Granted access to user %s on project %s"%(name, prjName)) log.info("Granted access to %s on project %s"%(name, prjName))
def run(self, serverState, request, response): user=request.getParam('user') password=request.getParam('password') userhandler = UserHandler() user_obj = userhandler.validateUser(user,password) if user_obj is None: raise cpc.util.CpcError("Invalid user/pass") request.session.reset() request.session['default_project_name'] = None request.session['user'] = user_obj response.add('Logged in as %s'%user)
def run(self, serverState, request, response): user = request.getParam('user') password = request.getParam('password') userhandler = UserHandler() user_obj = userhandler.validateUser(user, password) if user_obj is None: raise cpc.util.CpcError("Invalid user/pass") request.session.reset() request.session['default_project_name'] = None request.session['user'] = user_obj response.add('Logged in as %s' % user)
def run(self, serverState, request, response): name = request.getParam('name') prj = self.getProject(request, serverState) prjName = prj.getName() usrhandler = UserHandler() target_user = usrhandler.getUserFromString(name) if target_user is None: raise ProjectServerCommandException("User %s doesn't exist" % name) usrhandler.addUserToProject(target_user, prjName) response.add("Granted access to user %s on project %s" % (name, prjName)) log.info("Granted access to %s on project %s" % (name, prjName))
def run(self, serverState, request, response): projectName = request.getParam("project") user = self.getUser(request) if (request.haveFile("projectFile")): projectBundle = request.getFile('projectFile') try: serverState.getProjectList().add(projectName) UserHandler().addUserToProject(user, projectName) extractPath = "%s/%s" % (ServerConf().getRunDir(), projectName) tar = tarfile.open(fileobj=projectBundle, mode="r") tar.extractall(path=extractPath) tar.close() del (tar) serverState.readProjectState(projectName) gc.collect() except: response.add("No project file provided", status="ERROR") return response.add("Project restored as %s" % projectName) log.info("Project load %s" % (projectName)) else: response.add("No project file provided", status="ERROR") log.info("Project load %s failed" % (projectName))
def run(self, serverState, request, response): toList = request.getParam('type') retstr = "" if toList == "queue": list = serverState.getCmdQueue().list() queue = [] for cmd in list: queue.append(cmd.toJSON()) running = [] cmds = serverState.getRunningCmdList().getCmdList() for cmd in cmds: running.append(cmd.toJSON()) retstr = {"queue": queue, "running": running} elif toList == "running": running = [] cmds = serverState.getRunningCmdList().getCmdList() for cmd in cmds: running.append(cmd.toJSON()) retstr = running elif toList == "heartbeats": heartbeats = serverState.getRunningCmdList().toJSON() #.list() retstr = heartbeats elif toList == "users": retstr = UserHandler().getUsersAsList() elif toList == "modules": retstr = getModulesList() else: raise ServerCommandError("Unknown item to list: '%s'" % toList) response.add(retstr) log.info("Listed %s" % toList)
def run(self, serverState, request, response): user = self.getUser(request) if user.isSuperuser(): lst = lst = serverState.getProjectList().list() else: lst = UserHandler().getProjectListForUser(user) response.add(lst) log.info("Listed %d projects" % (len(lst)))
def run(self, serverState, request, response): name = request.getParam('name') user = self.getUser(request) serverState.getProjectList().add(name) request.session.set("default_project_name", name) UserHandler().addUserToProject(user, name) response.add("Project created: %s" % name) log.info("Started new project %s" % (name)) gc.collect()
def run(self, serverState, request, response): name = request.getParam('name') user = self.getUser(request) #serverState.getProjectList().setDefault(name) # get the project to check whether it exists project = serverState.getProjectList().get(name) if not UserHandler().userAccessToProject(user, name): raise UserError("You don't have access to this project") request.session.set("default_project_name", name) response.add("Changed to project: %s" % name) log.info("Changed to project: %s" % name)
def run(self, serverState, request, response): prj = self.getProject(request, serverState) name = prj.getName() delDir = request.hasParam('delete-dir') msg = " and its directory %s" % prj.getBasedir() if delDir else "" serverState.getProjectList().delete(prj, delDir) UserHandler().wipeAccessToProject(name) if (('default_project_name' in request.session) and (name == request.session['default_project_name'])): request.session['default_project_name'] = None del prj gc.collect() response.add("Project deleted: %s%s." % (name, msg)) log.info("Deleted project %s" % (name))
def getProject(self, request, serverState, only_explicit=False): """Get a named or default project""" #get the user user = self.getUser(request) #is the project specified explicitly? if request.hasParam('project'): prjName = request.getParam('project') else: if only_explicit: return None prjName = request.session.get('default_project_name', None) if prjName is None: raise cpc.util.exception.CpcError("No project selected") #we check this at every command, as it may change project = serverState.getProjectList().get(prjName) if not UserHandler().userAccessToProject(user, prjName): raise UserError("You don't have access to this project") return project
def run(self, serverState, request, response): ret_dict = {} # handle project status user = self.getUser(request) explicit_project = self.getProject(request, serverState, only_explicit=True) if explicit_project is not None: projects = [explicit_project.getName()] else: if user.isSuperuser(): projects = lst = serverState.getProjectList().list() else: projects = UserHandler().getProjectListForUser(user) ret_prj_dict = {} for prj_str in projects: ret_prj_dict[prj_str] = dict() queue = {'queue': [], 'running': []} state_count = {} err_list = [] warn_list = [] prj_obj = serverState.getProjectList().get(prj_str) # we iterate over the childred rather than calling _traverseInstance # here to avoid the project itself being counted as an instance for child in prj_obj.getSubValueIterList(): self._traverseInstance(prj_obj.getSubValue([child]), state_count, queue, err_list, warn_list) ret_prj_dict[prj_str]['states'] = state_count ret_prj_dict[prj_str]['queue'] = queue ret_prj_dict[prj_str]['errors'] = err_list ret_prj_dict[prj_str]['warnings'] = warn_list if prj_str == request.session.get('default_project_name', None): ret_prj_dict[prj_str]['default'] = True ret_dict['projects'] = ret_prj_dict if explicit_project is not None: # client only want info for this project, return with that. response.add("", ret_dict) return # handle network topology = ServerToServerMessage.getNetworkTopology() if not topology: log.error("Cannot get network topology.") return numWorkers = 0 numServers = 0 numLocalWorkers = len( WorkerStateHandler.getConnectedWorkers(serverState.workerStates)) numNotConnectedLocalServers = 0 numLocalServers = 0 for id, node in ServerConf().getNodes().nodes.iteritems(): if node.isConnected(): numLocalServers += 1 else: numNotConnectedLocalServers += 1 for name, node in topology.nodes.iteritems(): numWorkers += len(node.workerStates) numServers += 1 numWorkers += numLocalWorkers ret_dict['network'] = { 'workers': numWorkers, 'servers': numServers, 'local_workers': numLocalWorkers, 'local_servers': numLocalServers, 'not_connected_local_servers': numNotConnectedLocalServers } response.add("", ret_dict)