Skip to content

Commit

Permalink
Merge pull request #2596 from sever-sever/T5249
Browse files Browse the repository at this point in the history
T5249: Add rollback-soft feature
  • Loading branch information
sever-sever authored Dec 17, 2023
2 parents 59ea017 + f208e9b commit fc173e3
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions python/vyos/config_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from vyos.config import Config
from vyos.configtree import ConfigTree, ConfigTreeError, show_diff
from vyos.load_config import load, LoadConfigError
from vyos.defaults import directories
from vyos.version import get_full_version_data
from vyos.utils.io import ask_yes_no
Expand Down Expand Up @@ -262,6 +263,23 @@ 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 < {self.num_revisions}'
return msg, 1

rollback_ct = self._get_config_tree_revision(rev)
try:
load(rollback_ct, switch='explicit')
except LoadConfigError as e:
raise ConfigMgmtError(e) from e

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 @@ -456,13 +474,10 @@ def show_commit_file(self, rev: int) -> str:

# utility functions
#
@staticmethod
def _strip_version(s):
return re.split(r'(^//)', s, maxsplit=1, flags=re.MULTILINE)[0]

def _get_saved_config_tree(self):
with open(config_file) as f:
c = self._strip_version(f.read())
c = f.read()
return ConfigTree(c)

def _get_file_revision(self, rev: int):
Expand All @@ -474,7 +489,7 @@ def _get_file_revision(self, rev: int):
return r

def _get_config_tree_revision(self, rev: int):
c = self._strip_version(self._get_file_revision(rev))
c = self._get_file_revision(rev)
return ConfigTree(c)

def _add_logrotate_conf(self):
Expand Down Expand Up @@ -697,6 +712,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 fc173e3

Please sign in to comment.