Exemplo n.º 1
0
    def getFileServer(self,name_or_ip,**kw):
        """
        Retrieve Fileserver Object by hostname or IP  or uuid and update DBCache, if enabled 
        """
        self.Logger.debug("Entering getFileServer with kw=%s" % kw)
        uuid=kw.get("uuid","")
        cached=kw.get("cached","")
        _user=kw.get("_user","")

        DNSInfo=afs.LookupUtil[self._CFG.CELL_NAME].getDNSInfo(name_or_ip)
        if DNSInfo["ipaddrs"][0] in self._CFG.ignoreIPList :
            return None
        if uuid != "" :
            if uuid != afs.LookupUtil[self._CFG.CELL_NAME].getFSUUID(name_or_ip,self._CFG, cached) :
                uuid=afs.LookupUtil[self._CFG.CELL_NAME].getFSUUID(name_or_ip,self._CFG, cached)
        else :
            uuid=afs.LookupUtil[self._CFG.CELL_NAME].getFSUUID(name_or_ip,self._CFG, cached)
         
        if cached :
            this_FileServer=self.DBManager.getFromCache(FileServer,uuid=uuid)
            if this_FileServer == None : # it's not in the cache. Log it and get it from live-system
                self.Logger.warn("getFileServer: FS with uuid=%s not in DB." % uuid)
            else :
                this_FileServer.parts = self.getPartitionsByUUID(uuid,name_or_ip=this_FileServer.servernames[0],cached=cached)
                return this_FileServer

        this_FileServer = FileServer()
        # get DNS-info about server
        DNSInfo = afs.LookupUtil[self._CFG.CELL_NAME].getDNSInfo(name_or_ip)
        this_FileServer.servernames = DNSInfo["names"]
        this_FileServer.ipaddrs = DNSInfo["ipaddrs"]
        # UUID
        this_FileServer.uuid=uuid
        this_FileServer.version,this_FileServer.builddate=self._rxDAO.getVersionandBuildDate(this_FileServer.servernames[0], 7000, _cfg=self._CFG, _user=_user)
        # Partitions
        this_FileServer.parts = self.getPartitions(name_or_ip,cached=cached)
        if self._CFG.DB_CACHE :
            self.DBManager.setIntoCache(FileServer,this_FileServer,uuid=this_FileServer.uuid)
            for p in this_FileServer.parts  :
                part=Partition()
                self.Logger.debug("Setting part to %s" % this_FileServer.parts[p])
                part.setByDict(this_FileServer.parts[p])
                part.serv_uuid=this_FileServer.uuid
                self.DBManager.setIntoCache(Partition,part,serv_uuid=this_FileServer.uuid,name=p)

        # Projects
        # these we get directly from the DB_Cache
        
        this_FileServer.projects = []
        self.Logger.debug("getFileServerByUUID: returning: %s" % this_FileServer)
        return this_FileServer
Exemplo n.º 2
0
    def get_fileserver(self, name_or_ip, **kw):
        """
        Retrieve Fileserver Object by hostname or IP or uuid
        and update DBCache, if enabled 
        """
        self.Logger.debug("get_fileserver: called with name_or_ip=%s, kw=%s"\
            % (name_or_ip, kw))
        uuid = kw.get("uuid", "")
        cached = kw.get("cached", True)
        _user = kw.get("_user", "")

        dns_info = afs.LOOKUP_UTIL[self._CFG.cell].get_dns_info(name_or_ip)
        if dns_info["ipaddrs"][0] in self._CFG.ignoreIPList :
            return None
        if uuid != "" :
            if uuid != afs.LOOKUP_UTIL[self._CFG.cell].get_fsuuid(name_or_ip, \
                self._CFG, cached) :
                uuid = afs.LOOKUP_UTIL[self._CFG.cell].get_fsuuid(name_or_ip, \
                    self._CFG, cached)
        else :
            uuid = afs.LOOKUP_UTIL[self._CFG.cell].get_fsuuid(name_or_ip, \
                self._CFG, cached)
         
        self.Logger.debug("uuid=%s" % uuid)
        if cached :
            this_fileserver = self.DBManager.get_from_cache(FileServer, \
                 uuid=uuid)
            if this_fileserver == None : # not in the cache. 
                self.Logger.warn("get_fileserver: FS with name_or_ip=%s, uuid=%s not in DB or outdated."\
                    % (name_or_ip, uuid))
            else :
                this_fileserver.ExtAttr = self.DBManager.get_from_cache(ExtFileServAttr, \
			must_be_unique=True, fileserver_uuid=uuid)
                if this_fileserver.ExtAttr == None :
                    this_fileserver.ExtAttr = ExtFileServAttr()
                this_fileserver.parts = []
                try :
                    for part in self.DBManager.get_from_cache(Partition, \
                        must_be_unique=False, fileserver_uuid=uuid) :
                        part.ExtAttr = self.DBManager.get_from_cache(ExtPartAttr, \
                            must_be_unique=True, fileserver_uuid=uuid, name=part.name)
                        if part.ExtAttr == None :
                            part.ExtAttr = ExtPartAttr()
                        # XXX if there's no entry, fix default value of projectIDS
                        this_fileserver.parts.append(part)
                    return this_fileserver
                except TypeError : # no info from DB, let's pass onto live-system
                    self.Logger.warn("get_fileserver: Partition info about FS with uuid=%s not in DB. Maybe it has no partitions ?"\
                         % uuid)
                    return this_fileserver

        this_fileserver = FileServer()
        this_fileserver.servernames = dns_info["names"]
        this_fileserver.ipaddrs = dns_info["ipaddrs"]
        # UUID
        this_fileserver.uuid = uuid
        try :
            this_fileserver.version, this_fileserver.build_date = \
                self._rxLLA.getVersionandBuildDate(this_fileserver.servernames[0], \
                7000, _cfg=self._CFG, _user=_user)
        except :
            self.Logger.error("get_fileserver: cannot get information from fileserver %s. Is it up? Returning dummy-info" % this_fileserver.servernames[0])
            this_fileserver.version = -1
            this_fileserver.build_date = -1
            this_fileserver.parts = []
            return this_fileserver

        # update cache
        if self._CFG.DB_CACHE :
            self.DBManager.set_into_cache(FileServer, this_fileserver, \
                 uuid=this_fileserver.uuid)
            
        # Partitions
        this_fileserver.parts = []
        for part in self._fsLLA.get_partitions(this_fileserver, \
            _cfg=self._CFG, _user=_user) :
            part.fileserver_uuid = uuid
            part.ExtAttr = ExtPartAttr()
            part.ExtAttr.name = part.name
            part.ExtAttr.fileserver_uuid = uuid
            this_fileserver.parts.append(part)
            # update cache
            if self._CFG.DB_CACHE :
                self.DBManager.set_into_cache(Partition, part, fileserver_uuid=\
                    uuid, name=part.name)
                self.DBManager.set_into_cache(ExtPartAttr, part.ExtAttr, fileserver_uuid=\
                    uuid, name=part.name)
        self.Logger.debug("get_fileserver: returning: %s" % this_fileserver)
        if kw.get("async", True) :
            self.task_results[kw["_thread_name"]] = this_fileserver
        else : 
            return this_fileserver