def getVolume(self, name_or_id, serv=None, _user="", cached=True): VolList=[] if cached : if serv != "" : serv_uuid=afs.LookupUtil[self._CFG.CELL_NAME].getFSUUID(serv,self._CFG) if afsutil.isName(name_or_id) : vol=self.DBManager.getFromCache(Volume,name=name_or_id,serv_uuid=serv_uuid) else : vol=self.DBManager.getFromCache(Volume,vid=name_or_id,serv_uuid=serv_uuid) else : if afsutil.isName(name_or_id) : vol=self.DBManager.getFromCache(Volume,name=name_or_id) else : vol=self.DBManager.getFromCache(Volume,vid=name_or_id) if vol != None : for v in vol : v.ExtAttr=self.getExtVolAttr(v.vid) VolList.append(v) return vol vdictList = self._volDAO.getVolume(name_or_id, serv, _cfg=self._CFG, _user=_user) for vdict in vdictList : vdict["serv_uuid"]=afs.LookupUtil[self._CFG.CELL_NAME].getFSUUID(serv,self._CFG) vdict.pop("serv") self.Logger.debug("getVolume: vdict=%s" % vdict) vol = Volume() vol.setByDict(vdict) # this doesnot work, since RO are not unique. # we would need to write a setListIntoCache method for this #if self._CFG.DB_CACHE : # self.DBManager.setIntoCache(Volume,vol,vid = vol.vid) VolList.append(vol) return VolList
def getVolume(self, name, serv, part): vdict = self._volDAO.getVolume(name, serv, part, self._CFG.CELL_NAME, self._CFG.Token) vol = Volume() vol.setByDict(vdict) self._setIntoCache(vol) return vol
def getVolume(self, name_or_id, serv=None, _user="", cached=False): self.Logger.debug("Entering with name_or_id=%s, serv=%s, cached=%s" % (name_or_id, serv, cached) ) VolList = [] if cached : if serv != None : serv_uuid=afs.LookupUtil[self._CFG.CELL_NAME].getFSUUID(serv,self._CFG,cached=True) # need function in util name_or_ip and name_or_id? if afsutil.isName(name_or_id) : vol=self.DBManager.getFromCache(Volume,name=name_or_id,serv_uuid=serv_uuid) else : vol=self.DBManager.getFromCache(Volume,vid=name_or_id,serv_uuid=serv_uuid) VolList.append(vol) else : if afsutil.isName(name_or_id) : VolList=self.DBManager.getFromCache(Volume,name=name_or_id,mustBeUnique=False) else : VolList=self.DBManager.getFromCache(Volume,vid=name_or_id,mustBeUnique=False) self.Logger.debug("OSDgetVolume: VolList=%s" % VolList) for vol in VolList : vol.ExtAttr=self.getExtVolAttr(vol.vid) vol.OsdAttr=self.DBManager.getFromCache(ExtVolAttr_OSD,vid=vol.vid) return VolList osdExtAttr=ExtVolAttr_OSD() odict=osdExtAttr.getDict() vdictList = self._osdvolDAO.getVolume(name_or_id, serv=serv, _cfg=self._CFG, _user=_user) self.Logger.debug("OSDgetVolume: vdictList=%s" % vdictList) for vdict in vdictList : StorageUsage=self.getStorageUsage([serv,],vdict["vid"]) vdict["blocks_osd_on"]=StorageUsage["storageUsage"]["online"]["Data"] vdict["blocks_osd_off"]=StorageUsage["storageUsage"]["archival"]["Data"] vdict["blocks_fs"]=StorageUsage["storageUsage"]["fileserver"]["Data"] vdict["serv_uuid"]=afs.LookupUtil[self._CFG.CELL_NAME].getFSUUID(vdict["serv"],self._CFG,cached=False) vdict.pop("serv") self.Logger.debug("getVolume: vdict=%s" % vdict) # move stuff to OSD-dict for k in vdict.keys() : if k in odict.keys() : odict[k] = vdict[k] if k == "vid" : continue vdict.pop(k) vol = Volume() # XXX: we need this to ignore the OsdAttr and ExtAttr in the copy-operation. vdict["ignAttrList"]=vol.ignAttrList vol.setByDict(vdict) if odict['osdPolicy'] != 0 : vol.OsdAttr=odict osdExtAttr.setByDict(odict) if self._CFG.DB_CACHE : self.DBManager.setIntoCache(Volume,vol,vid=vol.vid,serv_uuid=serv_uuid,part=vol.part) if odict['osdPolicy'] != 0 : self.DBManager.setIntoCache(ExtVolAttr_OSD,osdExtAttr,vid=osdExtAttr.vid) VolList.append(vol) return VolList
def getVolume(self, name, serv, part, cached=False): if cached : serv_uuid=self.FsS.getUUID(serv) vol=self._getFromCache(name, serv_uuid, part) return vol vdict = self._volDAO.getVolume(name, serv, part, self._CFG.CELL_NAME, self._CFG.Token) vdict["serv_uuid"]=self.FsS.getUUID(serv) vdict.pop("serv") vol = None if vdict: vol = Volume() vol.setByDict(vdict) if self._CFG.DB_CACHE : self._setIntoCache(vol) return vol
def refreshCache(self, serv, part): if not self._CFG.DB_CACHE: raise VolError('Error, no db Cache defined ',None) part = afsutil.canonicalizePartition(part) list = self._volDAO.getVolList( serv, part, self._CFG.CELL_NAME, self._CFG.Token) #Convert into dictionary idVolDict = {} cUpdate = len(list) for el in list: idVolDict[el['vid']] = el session = self.DbSession() res = session.query(Volume).filter(or_(Volume.serv == serv,Volume.servername == serv )).filter(Volume.part == part) flush = 0 for vol in res: flush +=1 if idVolDict.has_key(vol.vid): vol.setByDict(idVolDict[vol.vid]) del idVolDict[vol.vid] else: session.delete(vol) if flush > self._CFG.DB_FLUSH: session.flush() session.flush() # ADD section flush = 0 for key in idVolDict.keys(): flush +=1 vol = Volume() vol.setByDict(idVolDict[key]) session.add(vol) if flush > self._CFG.DB_FLUSH: session.flush() session.flush() session.commit() return cUpdate
if v.get("osdPolicy",0) != 0 : if not afs.defaultConfig.moveOSDVOlumes : print "Skipping %s, because it is an OSD-Volume" % v["name"] continue # check for minSize if minUsage != 0 : if int(v.get("diskused")) < minUsage : print "Skipping %s, because it is smaller than %s" % (v["name"], minUsage) continue # remove osd-attributes from dict, create Obj v.pop("filequota") v.pop("osdPolicy") v["serv_uuid"]=afs.LookupUtil[afs.defaultConfig.CELL_NAME].getFSUUID(v["servername"]) VolObj.setByDict(v) if dstFS == None : minNestingLevel=-1 # NestingLevel should be "spezifizitaet" for p in PS.getProjectsByVolumeName(v["name"]) : if p.NestingLevel < minNestingLevel or minNestingLevel == -1 : minNestingLevel = p.NestingLevel PrjObj=p dstSrv,dstP = PS.getNewVolumeLocation(PrjObj.name,VolObj) if dstSrv == None : sys.stderr.write("found no appropriate location for %s, part of project %s. Skipping\n" % (VolObj.name,PrjObj.name)) continue else : dstSrv = dstFS.servernames[0] parts=FS.getPartitions(dstSrv) if reqDstPart == None : maxFree=0