Exemplo n.º 1
0
    def set_homedir(self, *args, **kw):
        """Remove quota information when the user is moved to a disk
        without quotas or where the default quota is larger than his
        existing explicit quota."""

        ret = self.__super.set_homedir(*args, **kw)
        if kw.get('current_id') and kw.get('disk_id'):
            disk = Factory.get("Disk")(self._db)
            disk.find(kw['disk_id'])
            has_quota = disk.has_quota()
            def_quota = disk.get_default_quota()
            dq = DiskQuota(self._db)
            try:
                info = dq.get_quota(kw['current_id'])
            except Errors.NotFoundError:
                pass
            else:
                if not has_quota:
                    # No quota on new disk, so remove the quota information.
                    dq.clear(kw['current_id'])
                elif def_quota is None:
                    # No default quota, so keep the quota information.
                    pass
                else:
                    if (info['override_expiration']
                            and DateTime.now() < info['override_expiration']):
                        old_quota = info['override_quota']
                    else:
                        old_quota = info['quota']
                    if old_quota <= def_quota:
                        dq.clear(kw['current_id'])
        return ret
Exemplo n.º 2
0
 def determine_disks(self, account, request_id, profile, fnr):
     disks = []
     spreads = [int(s) for s in profile.get_spreads()]
     try:
         for d_spread in profile.get_disk_spreads():
             if d_spread != self.default_spread:
                 # TBD:  How can all spreads be taken into account?
                 continue
             if d_spread in spreads:
                 try:
                     ah = account.get_home(d_spread)
                     homedir_id = ah['homedir_id']
                     current_disk_id = ah['disk_id']
                 except Errors.NotFoundError:
                     homedir_id, current_disk_id = None, None
                 if self.autostud.disk_tool.get_diskdef_by_diskid(
                         int(current_disk_id)):
                     logger.debug("Already on a student disk")
                     self.br.delete_request(request_id=request_id)
                     self.db.commit()
                     # actually, we remove a bit too much data from
                     # the below dict, but remaining data will be
                     # rebuilt on next run.
                     del (self.fnr2move_student[fnr])
                     raise NextAccount
                 try:
                     new_disk = profile.get_disk(d_spread,
                                                 current_disk_id,
                                                 do_check_move_ok=False)
                     if new_disk == current_disk_id:
                         continue
                     disks.append((new_disk, d_spread))
                     if (self.autostud.disk_tool.using_disk_kvote
                             and homedir_id is not None):
                         from Cerebrum.modules.disk_quota import DiskQuota
                         disk_quota_obj = DiskQuota(self.db)
                         try:
                             cur_quota = disk_quota_obj.get_quota(
                                 homedir_id)
                         except Errors.NotFoundError:
                             cur_quota = None
                         quota = profile.get_disk_kvote(new_disk)
                         if (cur_quota is None
                                 or cur_quota['quota'] != int(quota)):
                             disk_quota_obj.set_quota(homedir_id,
                                                      quota=int(quota))
                 except AutostudError, msg:
                     # Will end up on pending (since we only use one
                     # spread)
                     logger.debug("Error getting disk: %s" % msg)
                     break
     except NextAccount:
         pass  # Stupid python don't have labeled breaks
     return disks