def save_config(connection, path, config_name): """ Saves config file with new content. Returns empty string for valid flask response and error message otherwise. """ new_content = request.values.get('content', '') root_passwd = request.values.get('root_passwd', '') if new_content: try: f = connection.get_file(os.path.join(path, config_name), 'w') except Exception as e: logger.exception(e) return 'Error while opening file %s.<br>%s' % (config_name, e) else: f.write(new_content) f.close() logger.info('%s was successfully saved.' % config_name) elif not new_content: msg = 'Attempting for writing of empty content to %s.' % config_name logger.error(msg) return msg else: return 'Invalid root password.' return ''
def get_data_path(connection): """ Tries to get data path from /etc/fstab and then from moosefs_tool.ini. Returns empty if it fails. """ path = '' try: logger.info('Getting data path from /etc/fstab.') f = connection.get_file('/etc/fstab', 'r') for line in f.readlines(): if line.startswith('mfsmount') and 'mfsmeta' not in line: path = line.split()[1] logger.info('Data path %s was got successfully.' % path) except IOError: logger.exception( mfs_exceptions.DataPathGettingFailed( 'Cannot read /etc/fstab file.')) except IndexError: logger.exception( mfs_exceptions.DataPathGettingFailed('Cannot parse /etc/fstab.')) except Exception as e: logger.exception( mfs_exceptions.DataPathGettingFailed('Unresolved exception:\n%s' % e)) if not path: logger.info('Getting data path from %s.' % \ config_helper.DEFAULT_MFSTOOL_CONFIG_PATH) path = config_helper.moose_options.get('data_path', '') if path: logger.info('Data path %s was got successfully.' % path) return path
def get_data_path(connection): """ Tries to get data path from /etc/fstab and than from moosefs_tool.ini. Returns empty if it fails. """ path = '' try: logger.info('Getting data path from /etc/fstab.') f = connection.get_file('/etc/fstab', 'r') for line in f.readlines(): if 'fuse' in line and 'mfsmount' in line: path = line.split()[1] logger.info('Data path %s was got successfully.' % path) except IOError: logger.exception(mfs_exceptions.DataPathGettingFailed( 'Cannot read /etc/fstab file.')) except IndexError: logger.exception(mfs_exceptions.DataPathGettingFailed( 'Cannot parse /etc/fstab.')) except Exception as e: logger.exception(mfs_exceptions.DataPathGettingFailed( 'Unresolved exception:\n%s' % e)) if not path: logger.info('Getting data path from moosefs_tool.ini.') path = roots.get('data_path', '') if path: logger.info('Data path %s was got successfully.' % path) return path
def get_data_path(connection): """ Tries to get data path from /etc/fstab and then from moosefs_tool.ini. Returns empty if it fails. """ path = '' try: logger.info('Getting data path from /etc/fstab.') f = connection.get_file('/etc/fstab', 'r') for line in f.readlines(): if line.startswith('mfsmount') and 'mfsmeta' not in line: path = line.split()[1] logger.info('Data path %s was got successfully.' % path) except IOError: logger.exception(mfs_exceptions.DataPathGettingFailed( 'Cannot read /etc/fstab file.')) except IndexError: logger.exception(mfs_exceptions.DataPathGettingFailed( 'Cannot parse /etc/fstab.')) except Exception as e: logger.exception(mfs_exceptions.DataPathGettingFailed( 'Unresolved exception:\n%s' % e)) if not path: logger.info('Getting data path from %s.' % \ config_helper.DEFAULT_MFSTOOL_CONFIG_PATH) path = config_helper.moose_options.get('data_path', '') if path: logger.info('Data path %s was got successfully.' % path) return path
def create_targz(path_to_archive, source_data, suffix='backup'): """ Returns .tar.gz archive with 'source_data' (file, directory, etc.), stored in 'path_to_archive'. Archive name consists of timestamp in format '%d%m%Y-%H%M%S', suffix and extension 'tar.gz'. E.g.: 05042014_152340_backup.tar.gz """ archive_name = os.path.join(path_to_archive, datetime.datetime.now().strftime("%d-%m-%Y--%H:%M:%S") + \ '_' + suffix + '.tar.gz') try: tar = tarfile.open(archive_name, "w:gz") tar.add(source_data) except Exception as e: logger.exception(e) return str(e) else: logger.info('Backup \"%s\" was successfully created.' % archive_name) tar.close() return ''