diff options
| author | Nataliia S. <81954790+natali-rs1985@users.noreply.github.com> | 2025-08-19 11:04:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-19 11:04:38 +0200 |
| commit | 3bfcf335c5f16a6c814710b01f38342c40f85a8d (patch) | |
| tree | efa1d64693f8851c31b6b1851967fb9e9d6cd2b2 /src/helpers | |
| parent | 96fb2848e61cc5de677d9e6ad7f5c55ae397a698 (diff) | |
| parent | 69cd4845861c88285ab496339f19103dec7a32b6 (diff) | |
| download | vyos-1x-3bfcf335c5f16a6c814710b01f38342c40f85a8d.tar.gz vyos-1x-3bfcf335c5f16a6c814710b01f38342c40f85a8d.zip | |
Merge branch 'current' into T7678
Diffstat (limited to 'src/helpers')
| -rwxr-xr-x | src/helpers/vyos-save-config.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/helpers/vyos-save-config.py b/src/helpers/vyos-save-config.py index adf62b71d..fa1f5625d 100755 --- a/src/helpers/vyos-save-config.py +++ b/src/helpers/vyos-save-config.py @@ -23,15 +23,18 @@ from argparse import ArgumentParser from vyos.config import Config from vyos.remote import urlc -from vyos.component_version import add_system_version +from vyos.component_version import add_system_version_string from vyos.defaults import directories +from vyos.utils.file import write_file_atomic DEFAULT_CONFIG_PATH = os.path.join(directories['config'], 'config.boot') remote_save = None parser = ArgumentParser(description='Save configuration') parser.add_argument('file', type=str, nargs='?', help='Save configuration to file') -parser.add_argument('--write-json-file', type=str, help='Save JSON of configuration to file') +parser.add_argument( + '--write-json-file', type=str, help='Save JSON of configuration to file' +) args = parser.parse_args() file = args.file json_file = args.write_json_file @@ -56,7 +59,14 @@ write_file = save_file if remote_save is None else NamedTemporaryFile(delete=Fal # config_tree is None before boot configuration is complete; # automated saves should check boot_configuration_complete config_str = None if ct is None else ct.to_string() -add_system_version(config_str, write_file) +versioned_config_str = add_system_version_string(config_str) + +try: + with write_file_atomic(write_file) as f: + f.write(versioned_config_str) +except OSError as e: + print(f'failed to write config file: {e}') + sys.exit(1) if json_file is not None and ct is not None: try: |
