def list_disk_quotas(f, disk_id, spread): account = Factory.get("Account")(db) disk = Factory.get("Disk")(db) disk.find(disk_id) default_quota = disk.get_default_quota() if default_quota is False: logger.debug("Skipping %s, no quotas on disk" % disk.path) return logger.debug("Listing quotas on %s" % disk.path) if default_quota is None: default_quota = '' # Unlimited all_users=False else: all_users=True now = mx.DateTime.now() dq = DiskQuota(db) for row in dq.list_quotas(spread=spread, disk_id=disk.entity_id, all_users=all_users): quota = row['quota'] if row['override_expiration'] and row['override_expiration'] > now: quota = row['override_quota'] if quota is None: quota = default_quota home=account.resolve_homedir(account_name=row['entity_name'], home=row['home'], disk_path=row['path']) f.write("%s:%s:%s\n" % (row['entity_name'], home, quota))
def clear_home(self, spread): """Remove disk quota before clearing home.""" try: homeinfo = self.get_home(spread) except Errors.NotFoundError: pass else: dq = DiskQuota(self._db) dq.clear(homeinfo['homedir_id']) return self.__super.clear_home(spread)
def clear_home(self, spread): """Remove disk quota before clearing home.""" try: homeinfo = self.get_home(spread) except Errors.NotFoundError: pass else: dq = DiskQuota(self._db) dq.clear(homeinfo["homedir_id"]) return self.__super.clear_home(spread)
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']) def_quota = disk.get_default_quota() dq = DiskQuota(self._db) try: info = dq.get_quota(kw['current_id']) except Errors.NotFoundError: pass else: if def_quota is False: # 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
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"]) def_quota = disk.get_default_quota() dq = DiskQuota(self._db) try: info = dq.get_quota(kw["current_id"]) except Errors.NotFoundError: pass else: if def_quota is False: # 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
def _clear_homedir(self, homedir_id): # Since disk_quota has a FK to homedir, we need this override dq = DiskQuota(self._db) dq.clear(homedir_id) return self.__super._clear_homedir(homedir_id)