Skip to content

Commit

Permalink
T5249: Add rollback-soft feature
Browse files Browse the repository at this point in the history
Add the ability to rollback configs without rebooting
```
sudo /usr/bin/config-mgmt rollback_soft --rev 1

rollback-soft 1
```
  • Loading branch information
sever-sever committed Dec 9, 2023
1 parent ffa3dc5 commit f46d424
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions python/vyos/config_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,29 @@ def rollback(self, rev: int, no_prompt: bool=False) -> Tuple[str,int]:

return msg, 0

def rollback_soft(self, rev: int):
"""Rollback without reboot (rollback-soft)
"""
msg = ''

if not self._check_revision_number(rev):
msg = f'Invalid revision number {rev}: must be 0 < rev < {maxrev}'
return msg, 1

path = os.path.join(archive_dir, f'config.boot.{rev}.gz')
with gzip.open(path, 'rb') as f:
config = f.read()

# Write config to laod
with open(rollback_config, 'wb') as f:
f.write(config)

rc, out = rc_cmd(f'/bin/cli-shell-api loadFile {rollback_config}')
if rc != 0:
raise ConfigMgmtError(out)

return msg, 0

def compare(self, saved: bool=False, commands: bool=False,
rev1: Optional[int]=None,
rev2: Optional[int]=None) -> Tuple[str,int]:
Expand Down Expand Up @@ -703,6 +726,11 @@ def run():
rollback.add_argument('-y', dest='no_prompt', action='store_true',
help="Excute without prompt")

rollback_soft = subparsers.add_parser('rollback_soft',
help="Rollback to earlier config")
rollback_soft.add_argument('--rev', type=int,
help="Revision number for rollback")

compare = subparsers.add_parser('compare',
help="Compare config files")

Expand Down

0 comments on commit f46d424

Please sign in to comment.