def has_updates(self) -> bool: """ check if updates are available Returns: True else raise error """ from cmdb.updater import UpdaterModule from cmdb.utils.system_reader import SystemSettingsReader, SectionError try: ssr = SystemSettingsReader(self.setup_database_manager) ssr.get_all_values_from_section('updater') upd_module = UpdaterModule(ssr) new_version = upd_module.get_last_version()['version'] current_version = upd_module.settings.version if new_version > current_version: LOGGER.error( f'Please run an update. There are new updates available.' f'Current Updater Version: {current_version} ' f'Newest Update Version: {new_version}' ) return False except SectionError as err: LOGGER.error(err.message) return False return True
def run_updates(self, version: int, ssr: SystemSettingsReader): from cmdb.updater import UpdaterModule ssr.get_all_values_from_section('updater') updater_instance = UpdaterModule(ssr) versions = updater_instance.__UPDATER_VERSIONS_POOL__ current_version = updater_instance.get_last_version()['version'] for num, file in enumerate(sorted(versions)): if current_version > version: process_bar('Process', len(versions), num + 1) updater_class = load_class( f'cmdb.updater.versions.updater_{current_version}.Update{current_version}' ) updater_instance = updater_class() updater_instance.start_update()
def setup(self) -> SetupStatus: LOGGER.info('SETUP ROUTINE: STARTED...') self.status = SetupRoutine.SetupStatus.RUNNING # check database if not self.__check_database(): self.status = SetupRoutine.SetupStatus.ERROR raise RuntimeError( 'The database managers could not be initialized. Perhaps the database cannot be reached, \ or the database was already initialized.') if self.__is_database_empty(): # init database try: self.__init_database() except Exception as err: self.status = SetupRoutine.SetupStatus.ERROR raise RuntimeError( f'Something went wrong during the initialization of the database. \n Error: {err}' ) # generate keys LOGGER.info('SETUP ROUTINE: Generate rsa key pair') try: self.init_keys() except Exception as err: self.status = SetupRoutine.SetupStatus.ERROR raise RuntimeError( f'Something went wrong during the generation of the rsa keypair. \n Error: {err}' ) # create user management LOGGER.info('SETUP ROUTINE: UserModel management') try: self.__create_user_management() except Exception as err: self.status = SetupRoutine.SetupStatus.ERROR raise RuntimeError( f'Something went wrong during the generation of the user management. \n Error: {err}' ) # create version updater settings try: from cmdb.updater import UpdaterModule from cmdb.updater.updater_settings import UpdateSettings from cmdb.utils.system_reader import SystemSettingsReader from cmdb.utils.system_writer import SystemSettingsWriter system_setting_writer: SystemSettingsWriter = SystemSettingsWriter( self.setup_database_manager) updater_setting_instance = UpdateSettings( **UpdaterModule.get_last_version()) system_setting_writer.write( _id='updater', data=updater_setting_instance.__dict__) except Exception as err: self.status = SetupRoutine.SetupStatus.ERROR raise RuntimeError( f'Something went wrong during the generation of the updater module. \n Error: {err}' ) self.status = SetupRoutine.SetupStatus.FINISHED LOGGER.info('SETUP ROUTINE: FINISHED!') return self.status