public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH installer 07/16] post-hook: re-use low-level config retrieval from proxmox-chroot
Date: Fri, 31 Jul 2026 16:35:30 +0200	[thread overview]
Message-ID: <20260731143910.936881-8-c.heiss@proxmox.com> (raw)
In-Reply-To: <20260731143910.936881-1-c.heiss@proxmox.com>

We load the file in both tools, so simpfify it a bit for the
proxmox-post-hook side.

While at it, add some context to its errors, as they don't include the
path by default, making debugging unnecessary hard.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 proxmox-chroot/src/main.rs            | 14 ++------------
 proxmox-installer-common/src/setup.rs | 12 ++++++++++++
 proxmox-post-hook/src/main.rs         |  3 +--
 3 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/proxmox-chroot/src/main.rs b/proxmox-chroot/src/main.rs
index c329f1a..387bdf4 100644
--- a/proxmox-chroot/src/main.rs
+++ b/proxmox-chroot/src/main.rs
@@ -13,10 +13,7 @@ use std::{
     process::{self, Command},
 };
 
-use proxmox_installer_common::{
-    RUNTIME_DIR, cli,
-    setup::{InstallConfig, SetupInfo},
-};
+use proxmox_installer_common::{RUNTIME_DIR, cli, setup::SetupInfo};
 use proxmox_installer_types::answer::Filesystem;
 
 const ANSWER_MP: &str = "answer";
@@ -170,7 +167,7 @@ fn cleanup(args: &CommandCleanupArgs) -> Result<()> {
 fn get_fs(filesystem: Option<Filesystem>) -> Result<Filesystem> {
     let fs = match filesystem {
         None => {
-            let low_level_config = match get_low_level_config() {
+            let low_level_config = match proxmox_installer_common::setup::get_low_level_config() {
                 Ok(c) => c,
                 Err(_) => bail!(
                     "Could not fetch config from previous installation. Please specify file system with -f."
@@ -184,13 +181,6 @@ fn get_fs(filesystem: Option<Filesystem>) -> Result<Filesystem> {
     Ok(fs)
 }
 
-fn get_low_level_config() -> Result<InstallConfig> {
-    let file = fs::File::open("/tmp/low-level-config.json")?;
-    let reader = io::BufReader::new(file);
-    let config: InstallConfig = serde_json::from_reader(reader)?;
-    Ok(config)
-}
-
 fn get_iso_info() -> Result<SetupInfo> {
     let path = PathBuf::from(RUNTIME_DIR).join("iso-info.json");
     let reader = io::BufReader::new(fs::File::open(path)?);
diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs
index b8af4e3..a5733bf 100644
--- a/proxmox-installer-common/src/setup.rs
+++ b/proxmox-installer-common/src/setup.rs
@@ -1,3 +1,4 @@
+use anyhow::{Context, Result};
 use serde::{Deserialize, Deserializer, Serialize, Serializer, de};
 use std::{
     cmp,
@@ -469,6 +470,17 @@ pub struct InstallFirstBootSetup {
     pub ordering_target: Option<String>,
 }
 
+pub fn get_low_level_config() -> Result<InstallConfig> {
+    const PATH: &str = "/tmp/low-level-config.json";
+    let file = File::open(PATH).with_context(|| format!("while opening {PATH}"))?;
+
+    let reader = io::BufReader::new(file);
+    let config: InstallConfig =
+        serde_json::from_reader(reader).with_context(|| format!("while parsing {PATH}"))?;
+
+    Ok(config)
+}
+
 pub fn spawn_low_level_installer(test_mode: bool) -> io::Result<process::Child> {
     let (path, args, envs): (&str, &[&str], Vec<(&str, &str)>) = if test_mode {
         (
diff --git a/proxmox-post-hook/src/main.rs b/proxmox-post-hook/src/main.rs
index ec9ab74..d0fb297 100644
--- a/proxmox-post-hook/src/main.rs
+++ b/proxmox-post-hook/src/main.rs
@@ -60,8 +60,7 @@ mod detail {
     pub fn gather(target_path: &str, answer: &AutoInstallerConfig) -> Result<PostHookInfo> {
         println!("Gathering installed system data ...");
 
-        let config: InstallConfig =
-            serde_json::from_reader(BufReader::new(File::open("/tmp/low-level-config.json")?))?;
+        let config = proxmox_installer_common::setup::get_low_level_config()?;
 
         let (setup_info, _, run_env) =
             load_installer_setup_files(proxmox_installer_common::RUNTIME_DIR)
-- 
2.54.0





  parent reply	other threads:[~2026-07-31 14:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-31 14:35 [PATCH proxmox/installer/datacenter-manager 00/16] auto-installer: add installed target systems as new remotes Christoph Heiss
2026-07-31 14:35 ` [PATCH proxmox 01/16] installer-types: drop unnecessary clippy attribute Christoph Heiss
2026-07-31 14:35 ` [PATCH proxmox 02/16] installer-types: post-hook: factor schema version into proper struct Christoph Heiss
2026-07-31 14:35 ` [PATCH proxmox 03/16] installer-types: post-hook: allow additional properties on api schema Christoph Heiss
2026-07-31 14:35 ` [PATCH proxmox 04/16] installer-types: post-hook: add api-token and cert-fingerprint options Christoph Heiss
2026-07-31 14:35 ` [PATCH proxmox 05/16] installer-types: systeminfo: add check for API token creation capability Christoph Heiss
2026-07-31 14:35 ` [PATCH installer 06/16] chroot: print full error if bind-mounting fails Christoph Heiss
2026-07-31 14:35 ` Christoph Heiss [this message]
2026-07-31 14:35 ` [PATCH installer 08/16] post-hook: generate and retrieve node certificate fingerprint Christoph Heiss
2026-07-31 14:35 ` [PATCH installer 09/16] post-hook: support creating API token if requested in answer file Christoph Heiss
2026-07-31 14:35 ` [PATCH installer 10/16] auto: enforce https for post hook when generating an API token Christoph Heiss
2026-07-31 14:35 ` [PATCH installer 11/16] assistant: validate-answer: also verify post-hook settings if set Christoph Heiss
2026-07-31 14:35 ` [PATCH datacenter-manager 12/16] ui: auto-installer: spell out Proxmox Datacenter Manager Christoph Heiss
2026-07-31 14:35 ` [PATCH datacenter-manager 13/16] config: auto-install: add optional `post-hook-add-as-remote` field Christoph Heiss
2026-07-31 14:35 ` [PATCH datacenter-manager 14/16] api: auto-installer: add option for adding new remotes to PDM Christoph Heiss
2026-07-31 14:35 ` [PATCH datacenter-manager 15/16] ui: auto-installer: wizard: add checkbox to add target as new remote Christoph Heiss
2026-07-31 14:35 ` [PATCH datacenter-manager 16/16] docs: auto-installer: document adding targets as remotes afterwards Christoph Heiss

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260731143910.936881-8-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pdm-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal