Refactoring, Removal of most global vars, config default path is ~/ucloud/

This commit is contained in:
ahmadbilalkhalid 2019-12-22 12:26:48 +05:00
commit 04993e4106
23 changed files with 673 additions and 726 deletions

View file

@ -7,6 +7,8 @@ from abc import ABC
from . import logger
from os.path import join as join_path
from ucloud.settings import settings as config
class ImageStorageHandler(ABC):
def __init__(self, image_base, vm_base):
@ -156,3 +158,19 @@ class CEPHBasedImageStorageHandler(ImageStorageHandler):
path = join_path(self.vm_base, path)
command = ["rbd", "info", path]
return self.execute_command(command, report=False)
def get_storage_handler():
__storage_backend = config['storage']['storage_backend']
if __storage_backend == 'filesystem':
return FileSystemBasedImageStorageHandler(
vm_base=config['storage']['vm_dir'],
image_base=config['storage']['image_dir']
)
elif __storage_backend == 'ceph':
return CEPHBasedImageStorageHandler(
vm_base=config['storage']['ceph_vm_pool'],
image_base=config['storage']['ceph_image_pool']
)
else:
raise Exception('Unknown Image Storage Handler')