Disks Service
This commit is contained in:
parent
271007044a
commit
7f5b5209a1
10 changed files with 256 additions and 0 deletions
31
backend/disks/disk.py
Normal file
31
backend/disks/disk.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import pathlib
|
||||
import threading
|
||||
import weakref
|
||||
|
||||
import disk_paths
|
||||
import disk_utils
|
||||
|
||||
DICTIONARY_LOCK = threading.Lock()
|
||||
DISK_LOCKS = weakref.WeakValueDictionary()
|
||||
|
||||
def create_disk(request):
|
||||
paths = disk_paths.DiskPaths(request)
|
||||
workstation = request['workstation']
|
||||
|
||||
with disk_lock(paths):
|
||||
if not paths.target_path.exists():
|
||||
disk_utils.create_os_disk(paths)
|
||||
|
||||
if workstation['cpu'] == 'ARM' and not paths.nvram_target_path.exists():
|
||||
disk_utils.create_nvram_disk(paths)
|
||||
|
||||
def delete_disk(request):
|
||||
paths = disk_paths.DiskPaths(request)
|
||||
|
||||
with disk_lock(paths):
|
||||
paths.target_path.unlink(missing_ok=True)
|
||||
paths.nvram_target_path.unlink(missing_ok=True)
|
||||
|
||||
def disk_lock(paths):
|
||||
with DICTIONARY_LOCK:
|
||||
return DISK_LOCKS.setdefault(paths.target_filename, threading.Lock())
|
||||
Loading…
Add table
Add a link
Reference in a new issue