예제 #1
0
    def update_server_spread(self, obj_or_param):
        """
        update the server spread from the live cell into the DB.
        """
        this_project = self.get_object(obj_or_param)
        self.Logger.debug("update_server_spread called for prj %s" % this_project.name)
        res_dict = {"RW" : [], "RO" : [], "BK" : []}
        VolIDList = self.get_volume_IDs(this_project.name)
        if VolIDList == None : return None
        for v in VolIDList :
            VolGroup = self._VS.get_volume_group(v) 
            for vol_type in res_dict :
                if VolGroup[vol_type] == None : continue
                if not isinstance(VolGroup[vol_type],types.ListType) : 
                    VolGroup[vol_type] = [VolGroup[vol_type],]
                for vol in VolGroup[vol_type] :
                    FSUUID = vol.fileserver_uuid
                    Part = vol.partition

                    thisPrjSPObj = None
                    ResDictIndex = -1
                    for i in range(len(res_dict[vol_type])) :
                        prjspObj = res_dict[vol_type][i]
                        self.Logger.debug("comparing %s,%s,%s with %s,%s,%s" % ( prjspObj.fileserver_uuid, prjspObj.part, prjspObj.vol_type, FSUUID, Part, vol_type) )
                        if prjspObj.fileserver_uuid == FSUUID and prjspObj.part == Part and prjspObj.vol_type == vol_type :
                            thisPrjSPObj=prjspObj
                            ResDictIndex=i
                            break

                    if thisPrjSPObj == None :
                        thisPrjSPObj = ProjectSpread()
                        thisPrjSPObj.project_id = this_project.db_id
                        thisPrjSPObj.part = Part
                        thisPrjSPObj.fileserver_uuid = FSUUID    
                        thisPrjSPObj.vol_type = vol_type
                        thisPrjSPObj.num_vol = 0 
                    
                    thisPrjSPObj.num_vol += 1 
                    if ResDictIndex == -1 :
                        res_dict[vol_type].append(thisPrjSPObj)
                    else :
                        res_dict[vol_type][ResDictIndex] = thisPrjSPObj

        for vol_type in res_dict :
            for thisPrjSPObj in res_dict[vol_type] :
                self.DBManager.set_into_cache(ProjectSpread, thisPrjSPObj, vol_type=vol_type, project_id=thisPrjSPObj.project_id, fileserver_uuid=thisPrjSPObj.fileserver_uuid, part=thisPrjSPObj.part)
        
        self.Logger.debug("update_server_spread: returning %s" % res_dict)
        return res_dict
예제 #2
0
    def getServerSpread(self, prjname, cached = True):
        """
        return dict of lists of ProjectSpread Objects :
        [VolType]=[ProjectSpread]
        """
        thisProject=self.getProjectByName(prjname)
        if not thisProject : return None
        ResDict = {"RW" : [], "RO" : [], "BK" : []}

        if cached :
            for vol_type in ResDict :
                ResDict[vol_type]=self.DBManager.getFromCache(ProjectSpread, mustBeUnique=False, vol_type=vol_type, project_id = thisProject.id)
            return ResDict
              
        VolIDList = self.getVolumeIDs(prjname)
        if VolIDList == None : return None
        for v in VolIDList :
            VolGroup = self._VS.getVolGroup(v) 
            for vol_type in ResDict :
                if VolGroup[vol_type] == None : continue
                for vol in VolGroup[vol_type] :
                    FSUUID = vol.serv_uuid
                    Part = vol.part
                    OSDAttributes = self._VS.getExtVolAttr_OSD(vol.vid)
                    if OSDAttributes == None :
                        OSDAttributes = ExtVolAttr_OSD()
                        v = self._VS.getVolume(vol.vid,cached=True)
                        # satisfy OSD attributes
                        OSDAttributes.blocks_fs = v[0].diskused

                    thisPrjSPObj = None
                    ResDictIndex = -1
                    for i in range(len(ResDict[vol_type])) :
                        prjspObj = ResDict[vol_type][i]
                        self.Logger.debug("comparing %s,%s,%s with %s,%s,%s" % (prjspObj.serv_uuid, prjspObj.part, prjspObj.vol_type, FSUUID, Part, vol_type) )
                        if prjspObj.serv_uuid == FSUUID and prjspObj.part == Part and prjspObj.vol_type == vol_type :
                            thisPrjSPObj=prjspObj
                            ResDictIndex=i
                            break

                    if thisPrjSPObj == None :
                        thisPrjSPObj = ProjectSpread()
                        thisPrjSPObj.project_id = thisProject.id
                        thisPrjSPObj.part = Part
                        thisPrjSPObj.serv_uuid = FSUUID    
                        thisPrjSPObj.vol_type = vol_type
                    
                    thisPrjSPObj.num_vol += 1 
                    thisPrjSPObj.blocks_fs += OSDAttributes.blocks_fs
                    thisPrjSPObj.blocks_osd_on += OSDAttributes.blocks_osd_on
                    thisPrjSPObj.blocks_osd_off += OSDAttributes.blocks_osd_off
                    if ResDictIndex == -1 :
                        ResDict[vol_type].append(thisPrjSPObj)
                    else :
                        ResDict[vol_type][ResDictIndex] = thisPrjSPObj

        if self._CFG.DB_CACHE :
            for vol_type in ResDict :
                for thisPrjSPObj in ResDict[vol_type] :
                    self.DBManager.setIntoCache(ProjectSpread, thisPrjSPObj, vol_type=vol_type, project_id=thisPrjSPObj.project_id, serv_uuid=thisPrjSPObj.serv_uuid, part=thisPrjSPObj.part)
        return ResDict