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 get_object(self, obj_or_param) : """ return an object, regardless of what was the input (object or unique parameters) unique paramter is name_or_id (either volume name or volume id) """ if isinstance(obj_or_param, Volume) : this_Volume = obj_or_param else : this_Volume = Volume() if misc.is_name(obj_or_param) : this_Volume.name = obj_or_param else : this_Volume.vid = obj_or_param return this_Volume
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
# only get the most specific one PrjObj=PS.getProjectsByVolumeName(VolumeName)[0] if afs.defaultConfig.ProjectName != None : thisPrjObj=PS.getProjectByName(afs.defaultConfig.ProjectName) if thisPrjObj == None : myParser.error("Project \"%s\" does not exist" % afs.defaultConfig.ProjectName) if thisPrjObj.id != PrjObj.id : if not afs.defaultConfig.force : myParser.error("VolumeName \"%s\" not matched by given Project \"%s\"\n" % (VolumeName,afs.defaultConfig.ProjectName)) sys.exit(1) PrjObj = thisPrjObj if not PrjObj : sys.stderr.write("Cannot guess Project for volume %s" % VolumeName) VolObj=Volume() VolObj.name=VolumeName VolObj.type=VolumeType if VolObj.type == "RW" : RWServ,RWPart=(PS.getNewVolumeLocation(PrjObj.name,VolObj)) print "Creating new volume %s of type %s on %s %s with size %d" % (VolObj.name, VolObj.type, RWServ,RWPart,VolSize) VD.create(VolObj.name,RWServ,RWPart,VolSize) print "Creating accompanying RO" VlD.addsite(VolObj.name,RWServ,RWPart) # XXX it's a bit shitty, but we have to release after each addsite for now, since we get the locations from vos examine atm and not from vos listvldb VD.release(VolObj.name) for i in range(1,PrjObj.minnum_ro) : print "Creating additional RO-copy number %s" % i ROServ,ROPart=(PS.getNewVolumeLocation(PrjObj.name,VolObj)) VlD.addsite(VolObj.name,ROServ,ROPart) VD.release(VolObj.name)
if not afs.defaultConfig.dpart in dstFS.parts : sys.stderr.write("Partition %s does not exist on server %s\n" % (afs.defaultConfig.dpart, afs.defaultConfig.dsrv)) sys.exit(2) else : reqDstPart=afs.defaultConfig.dpart else : reqDstPart=None else : dstFS=None if afs.defaultConfig.dpart != None : sys.stderr.write("Warning: ignoring given dpart=%s, because no dsrv has been specified.\n" % afs.defaultConfig.dpart) # XXX we should handle everything internally with bytes untilFree=parseHumanWriteableSize(afs.defaultConfig.untilfree)/1024 minUsage=parseHumanWriteableSize(afs.defaultConfig.minVolumeUsage)/1024 VolObj = Volume() movedVolcount=0 for srcP in srcParts : print "Processing Partition %s...." % srcP # check if partition is freed enough parts=FS.getPartitions(afs.defaultConfig.ssrv) if parts[srcP]["free"] > untilFree and untilFree > 0 : print "already %s Bytes free on spart %s." % (afs.util.afsutil.humanReadableSize(parts[srcP]["free"]),srcP ) continue # get list of volumes to move srcVolList=FS.getVolList(srcFS.servernames[0],srcP,cached=False) # get RW Volumes : RWVols=[] solitaryROVols=[] for v in srcVolList : if "type" in v.keys() :
def get_volume_list(rc, output, outerr, parseParamList, Logger) : if rc : raise FileServerLLAError("Error",outerr) # first line gives Name, ID, Type, Used and Status volList = [] dateT=datetime.datetime(1970, 1, 1) i = 0 while i < len(output): while output[i] != "BEGIN_OF_ENTRY": i = i+1 if i >= len(output): break if i >= len(output): break #Beginnig block splits = output[i].split() if splits[0] == "BEGIN_OF_ENTRY": vol = Volume() splits = output[i+1].split() # Invalid volume, something wrong if splits[0] != 'name': #vol['valid'] = False if splits[0] == 'id': vol.vid = int(splits[1]) splits = output[i+2].split() if splits[0] == 'serv': vol.servername = splits[1] splits = output[i+3].split() if splits[0] == 'part': vol.part = misc.canonicalize_partition(splits[1]) splits = output[i+4].split() if splits[0] == 'status': vol.status = splits[1] while output[i] != "END_OF_ENTRY": i = i+1 # Valid volume else: vol.vid = "UNSET" try: vol.name = splits[1] splits = output[i+2].split() vol.vid = int(splits[1]) splits = output[i+3].split() except : # XXX Here we need a flag to show that parsing was not complete # or a list of Volumes which need to be reparsed. # this will be in the return-code while output[i] != "END_OF_ENTRY": i = i+1 Logger.error("Cannot parse name of volume with id=%s! Skipping." % vol.vid) continue if len(splits) > 2: vol.servername = splits[2] else: #Only ip is available vol.servername = splits[1] splits = output[i+4].split() vol.partition = misc.canonicalize_partition(splits[1]) splits = output[i+5].split() vol.status = splits[1] if vol.status != "OK" : while output[i] != "END_OF_ENTRY": i = i+1 continue splits = output[i+6].split() vol.backup_id = int(splits[1]) splits = output[i+7].split() vol.parent_id = int(splits[1]) splits = output[i+8].split() vol.clone_id = int(splits[1]) splits = output[i+9].split() vol.in_use = splits[1] splits = output[i+10].split() vol.needs_salvage = splits[1] splits = output[i+11].split() vol.destroy_me = splits[1] splits = output[i+12].split() vol.type = splits[1] splits = output[i+13].split() vol.creation_date = dateT.fromtimestamp(float(splits[1])) splits = output[i+14].split() vol.access_date = dateT.fromtimestamp(float(splits[1])) splits = output[i+15].split() vol.update_date = dateT.fromtimestamp(float(splits[1])) splits = output[i+16].split() vol.backup_date = dateT.fromtimestamp(float(splits[1])) splits = output[i+17].split() vol.copy_date = dateT.fromtimestamp(float(splits[1])) splits = output[i+18].split() vol.flags = splits[1] splits = output[i+19].split() vol.diskused = int(splits[1]) splits = output[i+20].split() vol.maxquota = int(splits[1]) splits = output[i+21].split() vol.minquota = int(splits[1]) splits = output[i+22].split() vol.filecount = int(splits[1]) splits = output[i+23].split() vol.day_use = int(splits[1]) splits = output[i+24].split() vol.week_use = int(splits[1]) splits = output[i+25].split() vol.spare2 = splits[1] splits = output[i+26].split() vol.spare3 = splits[1] i = i+26 volList.append(vol) return volList