示例#1
0
    def get_fsuuid(self, name_or_ip, _user = "", cached = True) :
        """
        returns UUID of a fileserver, which is used as key for server-entries
        in other tables. This does not silently update the Cache
        """
        self._logger.debug("get_fsuuid: called with %s" % name_or_ip)
        if cached :
        # local Cache first
            if name_or_ip in self.memory_cache["fsuuids"].keys() :
                return self.memory_cache["fsuuids"][name_or_ip]
            else :
                name_or_ip = self.get_dns_info(name_or_ip)["names"][0] 
                if name_or_ip in self.memory_cache["fsuuids"].keys() :
                    return self.memory_cache["fsuuids"][name_or_ip]
        # then DB
            if  self._config.DB_CACHE:
                from afs.util.DBManager import DBManager
                from afs.model.FileServer import FileServer
                self._logger.debug("looking up FSUUID in DB_Cache for serv=%s" \
                     % name_or_ip)
                dns_info = self.get_dns_info(name_or_ip)
                this_dbmanager = DBManager(self._config)
                fileserver = this_dbmanager.get_from_cache_by_list_element(\
                    FileServer, FileServer.servernames_js, \
                    dns_info["names"][0])
                if fileserver != None :
                    # store it in memory_cache 
                    self.memory_cache["fsuuids"][fileserver.servernames[0]] = \
                        fileserver.uuid 
                    self.memory_cache["fsuuids"][fileserver.ipaddrs[0]] = \
                        fileserver.uuid
                    return fileserver.uuid

        # not found in local cache and not in DB Cache, get it from live-system
            
        from afs.lla.VLDBLLA import VLDBLLA
        dns_info = self.get_dns_info(name_or_ip)
        uuid = ""
        _vl_lla = VLDBLLA()

        uuid = _vl_lla.get_fileserver_uuid(dns_info["names"][0], _user = _user, \
             _cfg = self._config)

        # store it in memory_cache 
        self.memory_cache["fsuuids"][name_or_ip] = uuid                  
        self.memory_cache["fsuuids"][dns_info["names"][0]] = uuid
        self._logger.debug("returning %s" % (uuid))
        return uuid
示例#2
0
    def get_hostname_by_fsuuid(self, uuid, _user = "", cached = True) :
        """
        returns hostname of a fileserver by uuid
        """
        self._logger.debug("called with %s, cached=%s" % (uuid, cached))
        if cached :
            # local Cache first
            for hostname in self.memory_cache["fsuuids"] :
                if not is_name(hostname) : 
                    continue
                if self.memory_cache["fsuuids"][hostname] == uuid :
                    self._logger.debug("returning from local cache: %s" % \
                        hostname)
                    return hostname
            # then DB 
            if self._config.DB_CACHE:
                from afs.util.DBManager import DBManager
                from afs.model.FileServer import FileServer
                this_dbmanager = DBManager(self._config)
                fileserver = this_dbmanager.get_from_cache(FileServer, \
                    uuid = uuid)
                self._logger.debug("looking up hostname in db_cache " + \
                   "for uuid=%s" % uuid)
                if fileserver != None :
                    self.memory_cache["fsuuids"][fileserver.servernames[0]] = \
                        fileserver.uuid
                    return fileserver.servernames[0]

        # not found in local cache and not in DB Cache, or cacheing disabled.
        # get it from live-system
        from afs.lla.VLDBLLA import VLDBLLA
        _vl_lla = VLDBLLA()
        name_or_ip = None
        for fileserver in _vl_lla.getFsServList(\
            _cfg = self._config, _user="" ) :
            if fileserver['uuid'] == uuid :
                name_or_ip = fileserver['name_or_ip']
        if name_or_ip == None :
            raise LookupUtilError("No Server with uuid=%s " + \
                "registered in live-system" % uuid)
        # store it in memory_cache 
        self._logger.debug("get_hostname_by_fsuuid: got " + \
            " name_or_ip = %s from live-system" % name_or_ip)
        name_or_ip = self.get_dns_info(name_or_ip)["names"][0]
        self.memory_cache["fsuuids"][name_or_ip] = uuid                  
        self._logger.debug("returning: %s" % name_or_ip)
        return name_or_ip