Skip to content

Commit

Permalink
Add initial support for pirogue-admin --redeploy --commit.
Browse files Browse the repository at this point in the history
To be used in postinst scripts when upgrading: everything is deployed
again using the stored config.yaml except the WireGuard configuration
(see #9). For
now, a warning is logged (without setting a failed return code) if the
config file is missing.

Link: #4
  • Loading branch information
CyrilBrulebois committed Aug 24, 2024
1 parent 667d8ef commit 077e0a5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pirogue-admin/debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ pirogue-admin (1.2.3) UNRELEASED; urgency=medium

* Set PersistentKeepAlive for the PiRogue-side WireGuard peer (“server”)
as well (https://github.com/PiRogueToolSuite/pirogue-admin/issues/13).
* Add initial support for `pirogue-admin --redeploy --commit` to be used
in postinst scripts when upgrading: everything is deployed again using
the stored config.yaml except the WireGuard configuration (see
https://github.com/PiRogueToolSuite/pirogue-admin/issues/9). For now,
a warning is logged (without setting a failed return code) if the
config file is missing.

-- Cyril Brulebois <cyril@debamax.com> Sat, 24 Aug 2024 23:58:49 +0200

Expand Down
27 changes: 27 additions & 0 deletions pirogue-admin/pirogue_admin/cmd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import logging
import os
import sys
from pathlib import Path
from typing import TextIO

import yaml
Expand Down Expand Up @@ -168,6 +169,28 @@ def apply_configuration(c_ctx: ConfigurationContext, in_fd: TextIO):
logging.info('Applied!')


def redeploy_configuration(c_ctx: ConfigurationContext):
"""
Redeploy the stored configuration.
This is similar to apply_configuration() except we want to use the
configuration that's been stored already.
"""
# Maybe ConfigurationContext should know about config.yaml instead of
# duplicating the following in PackageConfigLoader.__init__() and below:
current_config_path = Path(c_ctx.var_dir, 'config.yaml')
if not current_config_path.exists():
# FIXME: Decide before a noisy no-op and a straight-up failure. Remember
# the main use case is postinst scripts!
logging.warning('Ignoring redeploy request, no configuration file stored!')
return

logging.info('Redeploying: %s', current_config_path)
loader = PackageConfigLoader(c_ctx)
loader.apply_configuration(yaml.safe_load(current_config_path.read_text()))
logging.info('Redeployed!')


def generate_definition_tree(c_ctx: ConfigurationContext, out_fd: TextIO):
"""
Generates a configuration tree description of this pirogue instance.
Expand Down Expand Up @@ -227,6 +250,8 @@ def main():
help='''apply a new configuration to the system.
Configuration is read from an optional input file or stdin (default).
Configuration is a set of "KEY: 'value'" pairs''')
parser.add_argument('--redeploy', action='store_true',
help='redeploy the current configuration (useful for postinst scripts)')
parser.add_argument('--configuration-tree', '--tree', '-t',
action='store', nargs='?', type=argparse.FileType('w'),
default=argparse.SUPPRESS,
Expand All @@ -253,6 +278,8 @@ def main():
autodetect_settings(c_ctx)
if 'apply' in args:
apply_configuration(c_ctx, args.apply)
if 'redeploy' in args:
redeploy_configuration(c_ctx)
if 'configuration_tree' in args:
generate_definition_tree(c_ctx, args.configuration_tree)
if 'current_config' in args:
Expand Down

0 comments on commit 077e0a5

Please sign in to comment.