Merge pull request #541 from Ostrokrzew/initconfig

Update API for init config
This commit is contained in:
Robert Baldyga 2020-10-15 10:16:45 +02:00 committed by GitHub
commit ec1d51825a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,12 +18,12 @@ class InitConfig:
self.core_config_lines = [] self.core_config_lines = []
def add_cache(self, cache_id, cache_device: Device, def add_cache(self, cache_id, cache_device: Device,
cache_mode: CacheMode = CacheMode.WT, load=None, extra_flags=""): cache_mode: CacheMode = CacheMode.WT, extra_flags=""):
self.cache_config_lines.append( self.cache_config_lines.append(
CacheConfigLine(cache_id, cache_device, cache_mode, load, extra_flags)) CacheConfigLine(cache_id, cache_device, cache_mode, extra_flags))
def add_core(self, cache_id, core_id, core_device: Device): def add_core(self, cache_id, core_id, core_device: Device, extra_flags=""):
self.core_config_lines.append(CoreConfigLine(cache_id, core_id, core_device)) self.core_config_lines.append(CoreConfigLine(cache_id, core_id, core_device, extra_flags))
def save_config_file(self): def save_config_file(self):
config_lines = [] config_lines = []
@ -39,16 +39,17 @@ class InitConfig:
fs_utils.write_file(opencas_conf_path, '\n'.join(config_lines), False) fs_utils.write_file(opencas_conf_path, '\n'.join(config_lines), False)
@classmethod @classmethod
def create_init_config_from_running_configuration(cls, load: bool = None, extra_flags=""): def create_init_config_from_running_configuration(
cls, cache_extra_flags="", core_extra_flags=""
):
init_conf = cls() init_conf = cls()
for cache in casadm_parser.get_caches(): for cache in casadm_parser.get_caches():
init_conf.add_cache(cache.cache_id, init_conf.add_cache(cache.cache_id,
cache.cache_device, cache.cache_device,
cache.get_cache_mode(), cache.get_cache_mode(),
load, cache_extra_flags)
extra_flags)
for core in casadm_parser.get_cores(cache.cache_id): for core in casadm_parser.get_cores(cache.cache_id):
init_conf.add_core(cache.cache_id, core.core_id, core.core_device) init_conf.add_core(cache.cache_id, core.core_id, core.core_device, core_extra_flags)
init_conf.save_config_file() init_conf.save_config_file()
return init_conf return init_conf
@ -62,36 +63,34 @@ class CacheConfigLine:
header = "[caches]" header = "[caches]"
def __init__(self, cache_id, cache_device: Device, def __init__(self, cache_id, cache_device: Device,
cache_mode: CacheMode, load=None, extra_flags=""): cache_mode: CacheMode, extra_flags=""):
self.cache_id = cache_id self.cache_id = cache_id
self.cache_device = cache_device self.cache_device = cache_device
self.load = load
self.cache_mode = cache_mode self.cache_mode = cache_mode
self.extra_flags = extra_flags self.extra_flags = extra_flags
def __str__(self): def __str__(self):
cache_symlink = self.cache_device.get_device_link("/dev/disk/by-id") cache_symlink = self.cache_device.get_device_link("/dev/disk/by-id")
cache_device_path = cache_symlink.full_path if cache_symlink is not None \ cache_device_path = (
else self.cache_device.system_path cache_symlink.full_path if cache_symlink is not None else self.cache_device.system_path
params = [str(self.cache_id), cache_device_path] )
if self.load is not None: params = [str(self.cache_id), cache_device_path, self.cache_mode.name, self.extra_flags]
params.append("yes" if self.load else "no")
params.append(self.cache_mode.name)
params.append(self.extra_flags)
return '\t'.join(params) return '\t'.join(params)
class CoreConfigLine: class CoreConfigLine:
header = "[cores]" header = "[cores]"
def __init__(self, cache_id, core_id, core_device: Device): def __init__(self, cache_id, core_id, core_device: Device, extra_flags=""):
self.cache_id = cache_id self.cache_id = cache_id
self.core_id = core_id self.core_id = core_id
self.core_device = core_device self.core_device = core_device
self.extra_flags = extra_flags
def __str__(self): def __str__(self):
core_symlink = self.core_device.get_device_link("/dev/disk/by-id") core_symlink = self.core_device.get_device_link("/dev/disk/by-id")
core_device_path = core_symlink.full_path if core_symlink is not None \ core_device_path = (
else self.core_device.system_path core_symlink.full_path if core_symlink is not None else self.core_device.system_path
params = [str(self.cache_id), str(self.core_id), core_device_path] )
params = [str(self.cache_id), str(self.core_id), core_device_path, self.extra_flags]
return '\t'.join(params) return '\t'.join(params)