Пример #1
0
    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())
Пример #2
0
 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())
Пример #3
0
    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())
Пример #4
0
    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())
Пример #5
0
 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)
Пример #6
0
    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)
Пример #7
0
    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
Пример #8
0
 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
Пример #9
0
    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)
Пример #10
0
 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())
Пример #11
0
    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)
Пример #12
0
 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())
Пример #13
0
 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())
Пример #14
0
 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)
Пример #15
0
 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)
Пример #16
0
    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)
Пример #17
0
    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)
Пример #18
0
    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)
Пример #19
0
    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)
Пример #20
0
    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)
Пример #21
0
    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)
Пример #22
0
 def getParsedDic(self):
     try:
         return {
             "ippool":
             ippool_main.getLoader().getIPpoolByID(
                 self.ippool_id).getIPpoolName()
         }
     except GeneralException:
         logException(LOG_DEBUG)
         return {}
Пример #23
0
    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)
Пример #24
0
    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)
Пример #25
0
    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()
Пример #26
0
 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
Пример #27
0
    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)
Пример #28
0
    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)
Пример #29
0
    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)
Пример #30
0
    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)
Пример #31
0
    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)
Пример #32
0
    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)
Пример #33
0
 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)
Пример #34
0
from core.ippool import ippool_main
print str(ippool_main.getLoader().getAllIPpoolNames())
print str(ippool_main.getLoader().getIPpoolByName('test').getInfo())
Пример #35
0
 def __reloadIPpool(self, ippool_id):
     ippool_main.getLoader().reloadIPpoolByID(ippool_id)
Пример #36
0
 def getIPpoolObj(self):
     ippool_id = self.getIPpoolID()
     return ippool_main.getLoader().getIPpoolByID(ippool_id)
Пример #37
0
    def changeInit(self,ippool_name):
	self.ippool_name=ippool_name
	self.useGenerateQuery({"ippool":ippool_main.getLoader().getIPpoolByName(self.ippool_name).getIPpoolID()})
Пример #38
0
    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()
Пример #39
0
 def run(self):
     self.exactSearchOnUserAndGroupAttrs(
         "ippool", "ippool",
         lambda x: ippool_main.getLoader().getIPpoolByName(x).getIPpoolID())
Пример #40
0
 def genQueryAuditLogPrepareOldValue(self, attr_name, old_value):
     return ippool_main.getLoader().getIPpoolByID(
         int(old_value)).getIPpoolName()
Пример #41
0
 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()
Пример #42
0
    def run(self):
	self.exactSearchOnUserAndGroupAttrs("ippool","ippool",lambda x:ippool_main.getLoader().getIPpoolByName(x).getIPpoolID())
Пример #43
0
    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)
Пример #44
0
 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)
Пример #45
0
    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"])
Пример #46
0
    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()
Пример #47
0
    def getParsedDic(self):
	try:
	    return {"ippool":ippool_main.getLoader().getIPpoolByID(self.ippool_id).getIPpoolName()}
	except GeneralException:
	    logException(LOG_DEBUG)
	    return {}
Пример #48
0
 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
Пример #49
0
 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()})
Пример #50
0
 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()