particle-os-tools/src/apt-ostree.py/client/commands/rollback.py

33 lines
No EOL
1.2 KiB
Python

"""
Rollback command for apt-ostree CLI.
This module implements the 'rollback' command that rolls back to the previous deployment
using the apt-ostree daemon.
"""
import argparse
import subprocess
from typing import Any
def setup_parser(subparsers: argparse._SubParsersAction):
rollback_parser = subparsers.add_parser('rollback', help='Rollback to previous deployment')
rollback_parser.add_argument('--reboot', '-r', action='store_true', help='Reboot after rollback')
def run(cli: Any, args: argparse.Namespace) -> int:
try:
print("Rolling back to previous deployment...")
result = cli.call_daemon_method('RollbackSystem')
if result.get('success'):
print("✓ Rollback completed successfully")
if args.reboot:
print("Rebooting in 5 seconds...")
subprocess.run(['shutdown', '-r', '+1'])
return 0
else:
print(f"✗ Rollback failed: {result.get('error', 'Unknown error')}")
cli.logger.error(f"Rollback failed: {result.get('error', 'Unknown error')}")
return 1
except Exception as e:
print(f"Error rolling back: {e}")
cli.logger.error(f"Error rolling back: {e}")
return 1