class BoothEnv(object): def __init__(self, report_processor, env_data): self.__report_processor = report_processor self.__name = env_data["name"] if "config_file" in env_data: self.__config = GhostFile( file_role=env_file_role_codes.BOOTH_CONFIG, content=env_data["config_file"]["content"] ) self.__key_path = env_data["key_path"] self.__key = GhostFile(file_role=env_file_role_codes.BOOTH_KEY, content=env_data["key_file"]["content"]) else: self.__config = RealFile( file_role=env_file_role_codes.BOOTH_CONFIG, file_path=get_config_file_name(env_data["name"]) ) self.__set_key_path(get_key_path(env_data["name"])) def __set_key_path(self, path): self.__key_path = path self.__key = RealFile(file_role=env_file_role_codes.BOOTH_KEY, file_path=path) def command_expect_live_env(self): if not self.__config.is_live: raise LibraryError(common_reports.live_environment_required(["--booth-conf", "--booth-key"])) def set_key_path(self, path): if not self.__config.is_live: raise AssertionError("Set path of keyfile is supported only in live environment") self.__set_key_path(path) @property def name(self): return self.__name @property def key_path(self): return self.__key_path def get_config_content(self): return self.__config.read() def create_config(self, content, can_overwrite_existing=False): self.__config.assert_no_conflict_with_existing(self.__report_processor, can_overwrite_existing) self.__config.write(content) def create_key(self, key_content, can_overwrite_existing=False): self.__key.assert_no_conflict_with_existing(self.__report_processor, can_overwrite_existing) self.__key.write(key_content, set_keyfile_access, is_binary=True) def push_config(self, content): self.__config.write(content) def remove_key(self): self.__key.remove(silence_no_existence=True) def remove_config(self): self.__config.remove() def export(self): return {} if self.__config.is_live else {"config_file": self.__config.export(), "key_file": self.__key.export()}
class PacemakerEnv(object): def __init__(self): """ callable get_cib should return cib as lxml tree """ self.__authkey = RealFile( file_role=env_file_role_codes.PACEMAKER_AUTHKEY, file_path=settings.pacemaker_authkey_file, ) @property def has_authkey(self): return self.__authkey.exists def get_authkey_content(self): return self.__authkey.read()
class PacemakerEnv: def __init__(self): """ callable get_cib should return cib as lxml tree """ self.__authkey = RealFile( file_role=env_file_role_codes.PACEMAKER_AUTHKEY, file_path=settings.pacemaker_authkey_file, is_binary=True, ) @property def has_authkey(self): return self.__authkey.exists def get_authkey_content(self): return self.__authkey.read()
class BoothEnv(object): def __init__(self, report_processor, env_data): self.__report_processor = report_processor self.__name = env_data["name"] if "config_file" in env_data: self.__config = GhostFile( file_role=env_file_role_codes.BOOTH_CONFIG, content=env_data["config_file"]["content"]) self.__key_path = env_data["key_path"] self.__key = GhostFile(file_role=env_file_role_codes.BOOTH_KEY, content=env_data["key_file"]["content"], is_binary=True) else: self.__config = RealFile( file_role=env_file_role_codes.BOOTH_CONFIG, file_path=get_config_file_name(env_data["name"]), ) self.__set_key_path(get_key_path(env_data["name"])) def __set_key_path(self, path): self.__key_path = path self.__key = RealFile(file_role=env_file_role_codes.BOOTH_KEY, file_path=path, is_binary=True) def command_expect_live_env(self): if not self.__config.is_live: raise LibraryError( common_reports.live_environment_required([ "BOOTH_CONF", "BOOTH_KEY", ])) def set_key_path(self, path): if not self.__config.is_live: raise AssertionError( "Set path of keyfile is supported only in live environment") self.__set_key_path(path) @property def name(self): return self.__name @property def key_path(self): return self.__key_path def get_config_content(self): return self.__config.read() def create_config(self, content, can_overwrite_existing=False): self.__config.assert_no_conflict_with_existing(self.__report_processor, can_overwrite_existing) self.__config.write(content) def create_key(self, key_content, can_overwrite_existing=False): self.__key.assert_no_conflict_with_existing(self.__report_processor, can_overwrite_existing) self.__key.write(key_content, set_keyfile_access) def push_config(self, content): self.__config.write(content) def remove_key(self): self.__key.remove(silence_no_existence=True) def remove_config(self): self.__config.remove() def export(self): return {} if self.__config.is_live else { "config_file": self.__config.export(), "key_file": self.__key.export(), }