def applySimpleBwLimit(self, user_msg): """ run apply/remove limit script. Name of script is in "pppd_apply_bandwidth_limit" attribute. Parameters ras_ip port limit_rate_kbytes will be passed to script. If ras is on seperate machin, Admin can change the script to apply limit on another ras or change pppd_apply_bandwidth_limit attribute WARNING: return Success even if script fails WARNING: script should not sleep or wait, it should return immediately """ if user_msg["action"] == "apply": try: return launcher_main.getLauncher().system( self.getAttribute("pppd_apply_bandwidth_limit"), [ self.getRasIP(), user_msg["port"], user_msg["rate_kbytes"] ]) except: logException(LOG_ERROR) return False elif user_msg["action"] == "remove": try: return launcher_main.getLauncher().system( self.getAttribute("pppd_remove_bandwidth_limit"), [self.getRasIP(), user_msg["port"]]) except: logException(LOG_ERROR) return False return True
def __loginUser(self, ras_msg): """ called after a user successfully logged in by user part """ return launcher_main.getLauncher().system( self.getAttribute("plan_login"), [self.getRasIP(), ras_msg["mac"], ras_msg["remote_ip"]])
def runIPTables(self, command): ret_val = launcher_main.getLauncher().system(defs.BW_IPTABLES_COMMAND, command.split()) if ret_val != 0: toLog( "iptables command '%s %s' returned non zero value %s" % (defs.BW_IPTABLES_COMMAND, command, ret_val), LOG_DEBUG)
def __getOnlinesFromCLI(self): fd = launcher_main.getLauncher().popen( self.getAttribute("portslave_list_users_command"), [self.getRasIP()]) out_lines = fd.readlines() fd.close() return out_lines
def __killUserOnPort(self, port): try: return launcher_main.getLauncher().system( self.getAttribute("pppd_kill_port_command"), [self.getRasIP(), port]) except: logException(LOG_ERROR)
def __getClientMacAddressFromCLI(self, station_ip): fd = launcher_main.getLauncher().popen( self.getAttribute("pppd_mac_script"), [self.getRasIP(), station_ip]) out_lines = fd.readlines() fd.close() return out_lines
def __doRcmd(self,host,command): """ run command "command" on "host" host """ _in,out,err=launcher_main.getLauncher().popen3(self.getAttribute("cisco_rsh_command"),[host,command]) err_str=self.__readAll(err) if not err_str: self.toLog("RCMD: %s"%err_str,LOG_DEBUG) out_str=self.__readAll(out) map(lambda fd:fd.close(),(_in,out,err)) return out_str
def killUser(self, user_msg): """ kill user, this will call "kill_port_command" attribute, with user port as argument """ try: return launcher_main.getLauncher().system( self.getAttribute("portslave_kill_port_command"), [self.getRasIP(), user_msg["port"]]) except: logException(LOG_ERROR)
def getMailboxUsage(self, username): usage = -1L try: fd = launcher_main.getLauncher().popen( "%smail/mail_usage" % defs.IBS_ADDONS, [username]) usage = fd.readline() fd.close() return long(usage) except: toLog("Can't query user %s mailbox usage: %s" % (username, usage), LOG_DEBUG) return -1
def __rcmd(self, host, command): """ command(str or list): if it's a list all list argument will be passed as arguments """ args = self.__prepareCommandAsArgument(command) _in, out, err = launcher_main.getLauncher().popen3( self.rsh_wrapper, [host] + args) err_str = self.__readAll(err) if err_str: raise RSHException("Host: %s Command %s: %s" % (host, command, err_str)) out_str = self.__readAll(out) map(lambda fd: fd.close(), (_in, out, err)) return out_str
def killUser(self, user_msg): """ kill user, this will call "kill_port_command" attribute, with user ppp interface numbers as argument """ try: mac_ip = user_msg["mac_ip"].upper() try: user_dic = self.onlines[mac_ip] except KeyError: self.toLog("User %s with mac_ip %s wasn't online" % (user_msg["user_id"], user_msg["mac_ip"])) return ret = launcher_main.getLauncher().system( self.getAttribute("plan_kill"), [self.getRasIP(), user_dic["mac"], user_dic["ip"]]) self.__addToWaitings(user_dic["user_id"], user_dic["mac"], user_dic["ip"]) self.__delFromOnlines(mac_ip) self.__sendStopMsg(user_dic["user_id"], user_dic["mac"], user_dic["ip"]) except: logException(LOG_ERROR)
def createMailbox(self, username): ret = launcher_main.getLauncher().system( "%smail/create_mailbox" % defs.IBS_ADDONS, [username]) if not ret: toLog("createMailbox returned non-zero return code %s" % ret, LOG_DEBUG)
def __getInOutFromCLI(self): fd = launcher_main.getLauncher().popen( self.getAttribute("plan_inout_usage"), [self.getRasIP()]) out_lines = fd.readlines() fd.close() return out_lines
def __getInOutsFromCLI(self): fd = launcher_main.getLauncher().popen( self.getAttribute("pppd_inouts_command"), [self.getRasIP()]) out_lines = fd.readlines() fd.close() return out_lines
def getOutput(self,command): fd=launcher_main.getLauncher().popen(defs.BW_TC_COMMAND,command.split()) lines=fd.readlines() fd.close() return "".join(lines)
def runTC(self,command): ret_val=launcher_main.getLauncher().system(defs.BW_TC_COMMAND,command.split()) if ret_val!=0: toLog("tc command '%s %s' returned non zero value %s"%(defs.BW_TC_COMMAND,command,ret_val),LOG_DEBUG)