Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support excluding certain directories from quota #10

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions get-quota-your-home/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get_quotas():
return quotas


def reconcile_projfiles(paths, projects_file_path, projid_file_path, min_projid):
def reconcile_projfiles(paths, projects_file_path, projid_file_path, min_projid, exclude_dirs):
"""
Make sure each homedir in paths has an appropriate projid entry.

Expand All @@ -101,9 +101,13 @@ def reconcile_projfiles(paths, projects_file_path, projid_file_path, min_projid)
"""
# Fetch existing home directories
# Sort to provide consistent ordering across runs
homedirs = sorted(
[ent.path for path in paths for ent in os.scandir(path) if ent.is_dir()]
)
homedirs = []
for path in paths:
for ent in os.scandir(path):
if ent.name not in exclude_dirs and ent.is_dir():
homedirs.append(ent.path)

homedirs.sort()
print(homedirs)

# Fetch list of projects in /etc/projid file, assumed to sync'd to /etc/projects file
Expand Down Expand Up @@ -218,6 +222,11 @@ def main():
type=float,
help="Hard quota limit (in GB) to set for all home directories",
)
argparser.add_argument(
"--exclude",
action='append',
help='List of directory names to exclude setting quotas on'
)
args = argparser.parse_args()

# xfs_quota reports in kb
Expand All @@ -227,7 +236,7 @@ def main():

while True:
reconcile_projfiles(
args.paths, args.projects_file, args.projid_file, args.min_projid
args.paths, args.projects_file, args.projid_file, args.min_projid, args.exclude
)
reconcile_quotas(args.projid_file, hard_quota_kb)
time.sleep(args.wait_time)
Expand Down
2 changes: 1 addition & 1 deletion get-quota-your-home/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_reconcile_projids():
for s in homedirs:
os.mkdir(os.path.join(base_dir, s))

reconcile_projfiles([base_dir], projects_file.name, projid_file.name, 1000)
reconcile_projfiles([base_dir], projects_file.name, projid_file.name, 1000, [])

projects_file.flush()
projid_file.flush()
Expand Down
Loading