def deletePool(self,ippool_name): """ delete a pool using it's "ippool_name" """ self.__deletePoolCheckInput(ippool_name) ippool_obj=ippool_main.getLoader().getIPpoolByName(ippool_name) self.__deletePoolDB(ippool_obj.getIPpoolID()) ippool_main.getLoader().unloadIPpoolByID(ippool_obj.getIPpoolID())
def deletePool(self, ippool_name): """ delete a pool using it's "ippool_name" """ self.__deletePoolCheckInput(ippool_name) ippool_obj = ippool_main.getLoader().getIPpoolByName(ippool_name) self.__deletePoolDB(ippool_obj.getIPpoolID()) ippool_main.getLoader().unloadIPpoolByID(ippool_obj.getIPpoolID())
def addIPtoPool(self,ippool_name,ips): """ add new "ip" to ippool with name "ippool_name" ips(MultiStr): can be a multi string of multiple ips """ self.__addIPtoPoolCheckInput(ippool_name,ips) ippool_obj=ippool_main.getLoader().getIPpoolByName(ippool_name) self.__addIPtoPoolDB(ippool_obj.getIPpoolID(),ips) ippool_main.getLoader().loadIPpoolByID(ippool_obj.getIPpoolID())
def delIPfromPool(self,ippool_name,ips): """ delete "ip" from ippool with name "ippool_name" ips(MultiStr instance): can be a multi string of multiple ips """ self.__delIPfromPoolCheckInput(ippool_name,ips) ippool_obj=ippool_main.getLoader().getIPpoolByName(ippool_name) self.__delIPfromPoolDB(ippool_obj.getIPpoolID(),ips) ippool_main.getLoader().loadIPpoolByID(ippool_obj.getIPpoolID())
def logout(self, instance, ras_msg): if self.user_obj.getInstanceInfo(instance).has_key("ippool_id"): try: ippool_main.getLoader().getIPpoolByID( self.user_obj.getInstanceInfo(instance) ["ippool_id"]).freeIP( self.user_obj.getInstanceInfo(instance)["attrs"] ["ippool_assigned_ip"]) except GeneralException: logException(LOG_DEBUG)
def __updatePoolCheckInput(self,ippool_id,ippool_name,comment): ippool_main.getLoader().checkIPpoolID(ippool_id) ippool_obj=ippool_main.getLoader().getIPpoolByID(ippool_id) if ippool_obj.getIPpoolName()!=ippool_name: if not isValidName(ippool_name): raise GeneralException(errorText("IPPOOL","BAD_IP_POOL_NAME")%ippool_name) if ippool_main.getLoader().ippoolNameExists(ippool_name): raise GeneralException(errorText("IPPOOL","IP_POOL_NAME_ALREADY_EXISTS")%ippool_name)
def addNewPool(self,ippool_name,comment): """ add a new ip pool ippool_name(string): name of new ip pool comment(string): comment about new ippool """ self.__addNewPoolCheckInput(ippool_name,comment) ippool_id=self.__getNewIPpoolID() self.__insertPoolDB(ippool_id,ippool_name,comment) ippool_main.getLoader().loadIPpoolByID(ippool_id) return ippool_id
def addNewPool(self, ippool_name, comment): """ add a new ip pool ippool_name(string): name of new ip pool comment(string): comment about new ippool """ self.__addNewPoolCheckInput(ippool_name, comment) ippool_id = self.__getNewIPpoolID() self.__insertPoolDB(ippool_id, ippool_name, comment) ippool_main.getLoader().loadIPpoolByID(ippool_id) return ippool_id
def __updatePoolCheckInput(self, ippool_id, ippool_name, comment): ippool_main.getLoader().checkIPpoolID(ippool_id) ippool_obj = ippool_main.getLoader().getIPpoolByID(ippool_id) if ippool_obj.getIPpoolName() != ippool_name: if not isValidName(ippool_name): raise GeneralException( errorText("IPPOOL", "BAD_IP_POOL_NAME") % ippool_name) if ippool_main.getLoader().ippoolNameExists(ippool_name): raise GeneralException( errorText("IPPOOL", "IP_POOL_NAME_ALREADY_EXISTS") % ippool_name)
def _reload(self): """ reload ippool obj, and sync that to db """ new_obj = ippool_main.getLoader().getIPpoolObjByID(self.getIPpoolID()) apply(self.__assignBasicVars, new_obj.getBasicVars()) self.getContainer()._reload(new_obj.getContainer().getAllIPs())
def __addNewPoolCheckInput(self, ippool_name, comment): if not isValidName(ippool_name): raise GeneralException( errorText("IPPOOL", "BAD_IP_POOL_NAME") % ippool_name) if ippool_main.getLoader().ippoolNameExists(ippool_name): raise GeneralException( errorText("IPPOOL", "IP_POOL_NAME_ALREADY_EXISTS") % ippool_name)
def delIPfromPool(self, ippool_name, ips): """ delete "ip" from ippool with name "ippool_name" ips(MultiStr instance): can be a multi string of multiple ips """ self.__delIPfromPoolCheckInput(ippool_name, ips) ippool_obj = ippool_main.getLoader().getIPpoolByName(ippool_name) self.__delIPfromPoolDB(ippool_obj.getIPpoolID(), ips) self.__reloadIPpool(ippool_obj.getIPpoolID())
def addIPtoPool(self, ippool_name, ips): """ add new "ip" to ippool with name "ippool_name" ips(MultiStr): can be a multi string of multiple ips """ self.__addIPtoPoolCheckInput(ippool_name, ips) ippool_obj = ippool_main.getLoader().getIPpoolByName(ippool_name) self.__addIPtoPoolDB(ippool_obj.getIPpoolID(), ips) self.__reloadIPpool(ippool_obj.getIPpoolID())
def delIPpoolFromRas(self, ras_ip, ippool_name): """ delete ippool with name "ippool_name" from ras with ip "ras_ip" """ self.__delIPpoolFromRasCheckInput(ras_ip, ippool_name) ras_obj = ras_main.getLoader().getRasByIP(ras_ip) ippool_obj = ippool_main.getLoader().getIPpoolByName(ippool_name) self.__delIPpoolFromRasDB(ras_obj.getRasID(), ippool_obj.getIPpoolID()) self.__reloadRas(ras_obj)
def addIPpoolToRas(self, ras_ip, ippool_name): """ add an ippool to ras """ self.__addIPpoolToRasCheckInput(ras_ip, ippool_name) ras_obj = ras_main.getLoader().getRasByIP(ras_ip) ippool_obj = ippool_main.getLoader().getIPpoolByName(ippool_name) self.__addIPpoolToRasDB(ras_obj.getRasID(), ippool_obj.getIPpoolID()) self.__reloadRas(ras_obj)
def addIPpoolToRas(self,ras_ip,ippool_name): """ add an ippool to ras """ self.__addIPpoolToRasCheckInput(ras_ip,ippool_name) ras_obj=ras_main.getLoader().getRasByIP(ras_ip) ippool_obj=ippool_main.getLoader().getIPpoolByName(ippool_name) self.__addIPpoolToRasDB(ras_obj.getRasID(),ippool_obj.getIPpoolID()) self.__reloadRas(ras_obj)
def __delIPfromPoolCheckInput(self,ippool_name,ips): ippool_obj=ippool_main.getLoader().getIPpoolByName(ippool_name) map(self.__checkIPAddr,ips) def checkIPExistencyInPool(ip): if not ippool_obj.hasIP(ip): raise GeneralException(errorText("IPPOOL","IP_NOT_IN_POOL")%ip) map(checkIPExistencyInPool,ips)
def delIPpoolFromRas(self,ras_ip,ippool_name): """ delete ippool with name "ippool_name" from ras with ip "ras_ip" """ self.__delIPpoolFromRasCheckInput(ras_ip,ippool_name) ras_obj=ras_main.getLoader().getRasByIP(ras_ip) ippool_obj=ippool_main.getLoader().getIPpoolByName(ippool_name) self.__delIPpoolFromRasDB(ras_obj.getRasID(),ippool_obj.getIPpoolID()) self.__reloadRas(ras_obj)
def __addIPtoPoolCheckInput(self,ippool_name,ips): ippool_obj=ippool_main.getLoader().getIPpoolByName(ippool_name) map(self.__checkIPAddr,ips) def checkIPAvailabilityInPool(ip): if ippool_obj.hasIP(ip): raise GeneralException(errorText("IPPOOL","IP_ALREADY_IN_POOL")%ip) map(checkIPAvailabilityInPool,ips)
def __deletePoolCheckInput(self,ippool_name): ippool_obj=ippool_main.getLoader().getIPpoolByName(ippool_name) def checkIPpoolInRas(ras_obj): if ras_obj.hasIPpool(ippool_obj.getIPpoolID()): raise GeneralException(errorText("IPPOOL","IPPOOL_USED_IN_RAS")%ras_obj.getRasIP()) ras_main.getLoader().runOnAllRases(checkIPpoolInRas) self.__checkPoolUsageInUsers(ippool_obj) self.__checkPoolUsageInGroups(ippool_obj)
def __addIPtoPoolCheckInput(self, ippool_name, ips): ippool_obj = ippool_main.getLoader().getIPpoolByName(ippool_name) map(self.__checkIPAddr, ips) def checkIPAvailabilityInPool(ip): if ippool_obj.hasIP(ip): raise GeneralException( errorText("IPPOOL", "IP_ALREADY_IN_POOL") % ip) map(checkIPAvailabilityInPool, ips)
def getParsedDic(self): try: return { "ippool": ippool_main.getLoader().getIPpoolByID( self.ippool_id).getIPpoolName() } except GeneralException: logException(LOG_DEBUG) return {}
def __delIPfromPoolCheckInput(self, ippool_name, ips): ippool_obj = ippool_main.getLoader().getIPpoolByName(ippool_name) for ip in ips: self.__checkIPAddr(ip) if not ippool_obj.hasIP(ip): raise GeneralException( errorText("IPPOOL", "IP_NOT_IN_POOL") % ip) if ippool_obj.isIPUsed(ip): raise GeneralException(errorText("IPPOOL", "IP_IS_USED") % ip)
def __deletePoolCheckInput(self, ippool_name): ippool_obj = ippool_main.getLoader().getIPpoolByName(ippool_name) def checkIPpoolInRas(ras_obj): if ras_obj.hasIPpool(ippool_obj.getIPpoolID()): raise GeneralException( errorText("IPPOOL", "IPPOOL_USED_IN_RAS") % ras_obj.getRasIP()) ras_main.getLoader().runOnAllRases(checkIPpoolInRas) self.__checkPoolUsageInUsers(ippool_obj) self.__checkPoolUsageInGroups(ippool_obj)
def getRasIPpools(self,request): """ return a sorted list of ip pool names """ request.needAuthType(request.ADMIN) request.getAuthNameObj().canDo("GET RAS INFORMATION") request.checkArgs("ras_ip") ippool_ids=ras_main.getLoader().getRasByIP(request["ras_ip"]).getIPpools() ippool_names=map(lambda ippool_id:ippool_main.getLoader().getIPpoolByID(ippool_id).getIPpoolName(),ippool_ids) sorted=SortedList(ippool_names) sorted.sort(0) return sorted.getList()
def getRasIPpools(self, request): """ return a sorted list of ip pool names """ request.needAuthType(request.ADMIN) request.getAuthNameObj().canDo("GET RAS INFORMATION") request.checkArgs("ras_ip") ippool_ids = ras_main.getLoader().getRasByIP( request["ras_ip"]).getIPpools() ippool_names = map( lambda ippool_id: ippool_main.getLoader().getIPpoolByID(ippool_id). getIPpoolName(), ippool_ids) return ippool_names
def _applyIPpool(self, ras_msg): """ apply ip pool to ras_msg or use previously assigned ip of user """ reply = ras_msg.getReplyPacket() if len(self.ippools) == 0 or ras_msg == None or reply.has_key( "Framed-IP-Address"): return for ippool_id in self.ippools: ippool_obj = ippool_main.getLoader().getIPpoolByID(ippool_id) ip = None if ras_msg.hasAttr("re_onlined"): if ras_msg.hasAttr("remote_ip") and ippool_obj.hasIP( ras_msg["remote_ip"]): try: ippool_obj.useIP(ras_msg["remote_ip"] ) #may raise IPpoolFullException except IPpoolFullException: toLog( "IP Conflict Detected on ras level for %s:%s" % (ras_msg["username"], ras_msg["remote_ip"]), LOG_ERROR) raise ip = ras_msg["remote_ip"] elif not ras_msg.hasAttr( "ip_assignment") or ras_msg["ip_assignment"] == True: try: ip = ippool_obj.setIPInPacket(reply) except IPpoolFullException: pass if ip != None: update_msg = ras_msg.createNew(None, None, self) update_msg.setAction("INTERNET_UPDATE") update_msg["update_attrs"] = [ "ippool_id", "ippool_assigned_ip" ] update_msg["ippool_id"] = ippool_id update_msg["ippool_assigned_ip"] = ip update_msg.send() break else: if not ras_msg.hasAttr("re_onlined"): self.toLog("All IP Pools are full", LOG_ERROR)
def login(self,ras_msg): if self.user_obj.getUserAttrs().hasAttr("ippool") and \ self.user_obj.isNormalUser() and \ not self.user_obj.getTypeObj().isPersistentLanClient(self.user_obj.instances): ippool_id=int(self.user_obj.getUserAttrs()["ippool"]) ip=None try: ip=ippool_main.getLoader().getIPpoolByID(ippool_id).setIPInPacket(ras_msg.getReplyPacket()) except GeneralException: #ippool deleted? logException(LOG_DEBUG) except IPpoolFullException: pass if ip!=None: self.__updateInstanceInfo(self.user_obj.instances,ippool_id,ip) if ras_msg.hasAttr("remote_ip"): self.__setRemoteIP(ras_msg)
def _applyIPpool(self,ras_msg): reply=ras_msg.getReplyPacket() if len(self.ippools)==0 or ras_msg==None: return if reply.has_key("Framed-IP-Address"): return for ippool_id in self.ippools: try: ip=ippool_main.getLoader().getIPpoolByID(ippool_id).setIPInPacket(reply) except IPpoolFullException: continue update_msg=ras_msg.createNew(None,None,self) update_msg.setAction("INTERNET_UPDATE") update_msg["update_attrs"]=["ippool_id","ippool_assigned_ip"] update_msg["ippool_id"]=ippool_id update_msg["ippool_assigned_ip"]=ip update_msg.send() break else: self.toLog("All IP Pools are full",LOG_ERROR)
def __delIPpoolFromRasCheckInput(self,ras_ip,ippool_name): ippool_obj=ippool_main.getLoader().getIPpoolByName(ippool_name) if not ras_main.getLoader().getRasByIP(ras_ip).hasIPpool(ippool_obj.getIPpoolID()): raise GeneralException(errorText("RAS","RAS_DONT_HAVE_IPPOOL")%ippool_name)
def updatePool(self,ippool_id,ippool_name,comment): self.__updatePoolCheckInput(ippool_id,ippool_name,comment) self.__updatePoolDB(ippool_id,ippool_name,comment) ippool_main.getLoader().unloadIPpoolByID(ippool_id) ippool_main.getLoader().loadIPpoolByID(ippool_id)
def __addIPpoolToRasCheckInput(self,ras_ip,ippool_name): ippool_obj=ippool_main.getLoader().getIPpoolByName(ippool_name) if ras_main.getLoader().getRasByIP(ras_ip).hasIPpool(ippool_obj.getIPpoolID()): raise GeneralException(errorText("RAS","RAS_ALREADY_HAVE_IPPOOL")%ippool_name)
def __addIPpoolToRasCheckInput(self, ras_ip, ippool_name): ippool_obj = ippool_main.getLoader().getIPpoolByName(ippool_name) if ras_main.getLoader().getRasByIP(ras_ip).hasIPpool( ippool_obj.getIPpoolID()): raise GeneralException( errorText("RAS", "RAS_ALREADY_HAVE_IPPOOL") % ippool_name)
from core.ippool import ippool_main print str(ippool_main.getLoader().getAllIPpoolNames()) print str(ippool_main.getLoader().getIPpoolByName('test').getInfo())
def __reloadIPpool(self, ippool_id): ippool_main.getLoader().reloadIPpoolByID(ippool_id)
def getIPpoolObj(self): ippool_id = self.getIPpoolID() return ippool_main.getLoader().getIPpoolByID(ippool_id)
def changeInit(self,ippool_name): self.ippool_name=ippool_name self.useGenerateQuery({"ippool":ippool_main.getLoader().getIPpoolByName(self.ippool_name).getIPpoolID()})
def getIPpoolNames(self,request): request.needAuthType(request.ADMIN) request.getAuthNameObj().canDo("LIST IPPOOL") sorted=SortedList(ippool_main.getLoader().getAllIPpoolNames()) sorted.sort(False) return sorted.getList()
def run(self): self.exactSearchOnUserAndGroupAttrs( "ippool", "ippool", lambda x: ippool_main.getLoader().getIPpoolByName(x).getIPpoolID())
def genQueryAuditLogPrepareOldValue(self, attr_name, old_value): return ippool_main.getLoader().getIPpoolByID( int(old_value)).getIPpoolName()
def getIPpoolNames(self, request): request.needAuthType(request.ADMIN) request.getAuthNameObj().canDo("LIST IPPOOL") sorted = SortedList(ippool_main.getLoader().getAllIPpoolNames()) sorted.sort(False) return sorted.getList()
def run(self): self.exactSearchOnUserAndGroupAttrs("ippool","ippool",lambda x:ippool_main.getLoader().getIPpoolByName(x).getIPpoolID())
def __addNewPoolCheckInput(self,ippool_name,comment): if not isValidName(ippool_name): raise GeneralException(errorText("IPPOOL","BAD_IP_POOL_NAME")%ippool_name) if ippool_main.getLoader().ippoolNameExists(ippool_name): raise GeneralException(errorText("IPPOOL","IP_POOL_NAME_ALREADY_EXISTS")%ippool_name)
def __delIPpoolFromRasCheckInput(self, ras_ip, ippool_name): ippool_obj = ippool_main.getLoader().getIPpoolByName(ippool_name) if not ras_main.getLoader().getRasByIP(ras_ip).hasIPpool( ippool_obj.getIPpoolID()): raise GeneralException( errorText("RAS", "RAS_DONT_HAVE_IPPOOL") % ippool_name)
def logout(self,instance,ras_msg): if self.user_obj.getInstanceInfo(instance)["attrs"].has_key("ippool_id"): ippool_main.getLoader().getIPpoolByID(self.user_obj.getInstanceInfo(instance)["attrs"]["ippool_id"]).freeIP(self.user_obj.getInstanceInfo(instance)["attrs"]["ippool_assigned_ip"])
def getIPpoolInfo(self,request): request.needAuthType(request.ADMIN) request.getAuthNameObj().canDo("LIST IPPOOL") request.checkArgs("ippool_name") return ippool_main.getLoader().getIPpoolByName(request["ippool_name"]).getInfo()
def getParsedDic(self): try: return {"ippool":ippool_main.getLoader().getIPpoolByID(self.ippool_id).getIPpoolName()} except GeneralException: logException(LOG_DEBUG) return {}
def __updateInstanceInfo(self, instance, ippool_id, ip): instance_info = self.user_obj.getInstanceInfo(instance) instance_info["ippool_id"] = ippool_id instance_info["attrs"]["ippool"] = ippool_main.getLoader( ).getIPpoolByID(ippool_id).getIPpoolName() instance_info["attrs"]["ippool_assigned_ip"] = ip
def changeInit(self, ippool_name): self.ippool_name = ippool_name self.ippool_obj = ippool_main.getLoader().getIPpoolByName( self.ippool_name) self.useGenerateQuery({"ippool": self.ippool_obj.getIPpoolID()})
def getIPpoolInfo(self, request): request.needAuthType(request.ADMIN) request.getAuthNameObj().canDo("LIST IPPOOL") request.checkArgs("ippool_name") return ippool_main.getLoader().getIPpoolByName( request["ippool_name"]).getInfo()