From 8dce6e5d762192e23591a91af017f513664a2364 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 21 Feb 2019 00:32:10 +0100 Subject: create_disk_images: modify image filenames Include computer name in filename for each disk and use a shorter hash placed immediately after task name. The hash is now based only on student ID and class_name, so it is always the same for each student. This should make images easier to locate in a large directory. --- kpov_judge/create_disk_images.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'kpov_judge') diff --git a/kpov_judge/create_disk_images.py b/kpov_judge/create_disk_images.py index 6777226..2f8fffe 100755 --- a/kpov_judge/create_disk_images.py +++ b/kpov_judge/create_disk_images.py @@ -23,11 +23,11 @@ def get_prepare_disks(db, class_id, task_id): exec(compile(prepare_disks_source, 'prepare_disks.py', 'exec'), globals(), d) return d['prepare_disks'] -def create_snapshot(class_id, task_id, student_id, disk_name, fmt='vmdk', overwrite=True): +def create_snapshot(class_id, task_id, student_id, computer_name, disk_name, fmt='vmdk', overwrite=True): # add a hash to filename to allow multiple students using the same directory - snap_hash = hashlib.sha1((disk_name+class_id+task_id+student_id).encode()).hexdigest()[:4] - snap = '{}-{}-{}.{}'.format( - task_id, disk_name, snap_hash, fmt) + snap_hash = hashlib.sha1((student_id+class_id).encode()).hexdigest()[:3] + snap = '{}-{}-{}-{}.{}'.format( + task_id, snap_hash, computer_name, disk_name, fmt) backing = [] template = disk_name + '.' + fmt @@ -85,7 +85,7 @@ def prepare_task_disks(class_id, task_id, student_id, fmt, computers): g = guestfs.GuestFS() for disk in computer['disks']: lock_fp.write("register " + disk['name'] + '\n') - task_dir, snap, backing = create_snapshot(class_id, task_id, student_id, disk['name'], fmt=fmt) + task_dir, snap, backing = create_snapshot(class_id, task_id, student_id, computer['name'], disk['name'], fmt=fmt) snap_file = os.path.join(settings.STUDENT_DISK_PATH, task_dir, snap) if 'options' in disk: g.add_drive_opts(snap_file, **(disk['options'])) -- cgit v1.2.1