* [pve-devel] [PATCH proxmox-offline-mirror 1/2] helper: make mountpoint non-optional
@ 2022-09-21 11:04 Fabian Grünbichler
2022-09-21 11:04 ` [pve-devel] [PATCH proxmox-offline-mirror 2/2] helper: add status command Fabian Grünbichler
2022-10-21 11:03 ` [pve-devel] applied-series: [PATCH proxmox-offline-mirror 1/2] helper: make mountpoint non-optional Wolfgang Bumiller
0 siblings, 2 replies; 3+ messages in thread
From: Fabian Grünbichler @ 2022-09-21 11:04 UTC (permalink / raw)
To: pve-devel
the default/fallback was a remnant from a no-longer-employed
"copy-helper-to-medium" deployment strategy.
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
technically breaking, but the default/fallback of /usr/bin was bogus
anyway..
src/bin/proxmox-offline-mirror-helper.rs | 31 +++---------------------
1 file changed, 3 insertions(+), 28 deletions(-)
diff --git a/src/bin/proxmox-offline-mirror-helper.rs b/src/bin/proxmox-offline-mirror-helper.rs
index af090a5..4efb343 100644
--- a/src/bin/proxmox-offline-mirror-helper.rs
+++ b/src/bin/proxmox-offline-mirror-helper.rs
@@ -64,16 +64,7 @@ async fn setup(_param: Value) -> Result<(), Error> {
bail!("Setup wizard can only run interactively.");
}
- let default_dir = std::env::current_exe().map_or_else(
- |_| None,
- |mut p| {
- p.pop();
- let p = p.to_str();
- p.map(str::to_string)
- },
- );
-
- let mountpoint = read_string_from_tty("Path to medium mountpoint", default_dir.as_deref())?;
+ let mountpoint = read_string_from_tty("Path to medium mountpoint", None)?;
let mountpoint = Path::new(&mountpoint);
if !mountpoint.exists() {
bail!("Medium mountpoint doesn't exist.");
@@ -267,8 +258,7 @@ async fn setup(_param: Value) -> Result<(), Error> {
properties: {
mountpoint: {
type: String,
- optional: true,
- description: "Path to medium mountpoint - defaults to `proxmox-offline-mirror-helper` containing directory.",
+ description: "Path to medium mountpoint",
},
product: {
type: ProductType,
@@ -278,7 +268,7 @@ async fn setup(_param: Value) -> Result<(), Error> {
)]
/// Configures and offline subscription key
async fn setup_offline_key(
- mountpoint: Option<String>,
+ mountpoint: String,
product: ProductType,
_param: Value,
) -> Result<(), Error> {
@@ -289,21 +279,6 @@ async fn setup_offline_key(
);
}
- let mountpoint = mountpoint
- .or_else(|| {
- std::env::current_exe().map_or_else(
- |_| None,
- |mut p| {
- p.pop();
- let p = p.to_str();
- p.map(str::to_string)
- },
- )
- })
- .ok_or_else(|| {
- format_err!("Failed to determine fallback mountpoint via executable path.")
- })?;
-
let mountpoint = Path::new(&mountpoint);
if !mountpoint.exists() {
bail!("Medium mountpoint doesn't exist.");
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [pve-devel] [PATCH proxmox-offline-mirror 2/2] helper: add status command
2022-09-21 11:04 [pve-devel] [PATCH proxmox-offline-mirror 1/2] helper: make mountpoint non-optional Fabian Grünbichler
@ 2022-09-21 11:04 ` Fabian Grünbichler
2022-10-21 11:03 ` [pve-devel] applied-series: [PATCH proxmox-offline-mirror 1/2] helper: make mountpoint non-optional Wolfgang Bumiller
1 sibling, 0 replies; 3+ messages in thread
From: Fabian Grünbichler @ 2022-09-21 11:04 UTC (permalink / raw)
To: pve-devel
similar to `proxmox-offline-mirror medium status <ID>`, but limited to
the information that is stored on the medium itself. this command can be
used to get a quick overview over what's on a medium, or for automated
setup of the contained repositories.
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
src/bin/proxmox-offline-mirror-helper.rs | 98 +++++++++++++++++++++++-
1 file changed, 97 insertions(+), 1 deletion(-)
diff --git a/src/bin/proxmox-offline-mirror-helper.rs b/src/bin/proxmox-offline-mirror-helper.rs
index 4efb343..353973f 100644
--- a/src/bin/proxmox-offline-mirror-helper.rs
+++ b/src/bin/proxmox-offline-mirror-helper.rs
@@ -12,7 +12,10 @@ use proxmox_sys::{fs::file_get_contents, linux::tty};
use proxmox_time::epoch_to_rfc3339_utc;
use serde_json::Value;
-use proxmox_router::cli::{run_cli_command, CliCommand, CliCommandMap, CliEnvironment};
+use proxmox_router::cli::{
+ format_and_print_result, get_output_format, run_cli_command, CliCommand, CliCommandMap,
+ CliEnvironment, OUTPUT_FORMAT,
+};
use proxmox_schema::{api, param_bail};
use proxmox_offline_mirror::helpers::tty::{
@@ -319,11 +322,104 @@ async fn setup_offline_key(
}
}
+#[api(
+ input: {
+ properties: {
+ mountpoint: {
+ type: String,
+ description: "Path to medium mountpoint",
+ },
+ "output-format": {
+ schema: OUTPUT_FORMAT,
+ optional: true,
+ },
+ },
+ },
+)]
+/// Prints status of medium
+async fn status(mountpoint: String, param: Value) -> Result<(), Error> {
+ let output_format = get_output_format(¶m);
+
+ let mountpoint = Path::new(&mountpoint);
+ if !mountpoint.exists() {
+ bail!("Medium mountpoint doesn't exist.");
+ }
+
+ let mut statefile = mountpoint.to_path_buf();
+ statefile.push(".mirror-state");
+
+ let raw = file_get_contents(&statefile)?;
+ let state: MediumState = serde_json::from_slice(&raw)?;
+
+ if output_format == "text" {
+ println!("Last sync: {}", epoch_to_rfc3339_utc(state.last_sync)?);
+ for (mirror, info) in &state.mirrors {
+ println!("\nMirror {mirror}:");
+ match medium::list_snapshots(mountpoint, mirror) {
+ Ok(snapshots) => {
+ match (snapshots.first(), snapshots.last()) {
+ (Some(first), Some(last)) if first == last => {
+ println!("1 snapshot: {}", first);
+ }
+ (Some(first), Some(last)) => {
+ println!("{} snapshots: '{first}..{last}'", snapshots.len());
+ }
+ _ => {
+ println!("No snapshots.");
+ }
+ };
+ if let Some(last) = snapshots.last() {
+ println!(
+ "repository config: {}",
+ proxmox_offline_mirror::generate_repo_file_line(
+ mountpoint, mirror, info, last
+ )?
+ );
+ }
+ }
+ Err(err) => {
+ println!("Failed to obtain snapshot list - {err}");
+ }
+ }
+ }
+ } else {
+ let mut json: serde_json::value::Map<String, Value> = serde_json::json!(state)
+ .as_object()
+ .ok_or_else(|| format_err!("Failed to serialize state file"))?
+ .to_owned();
+ for mirror in state.mirrors.keys() {
+ let mirror_json = json
+ .get_mut("mirrors")
+ .and_then(|v| v.as_object_mut())
+ .and_then(|o| o.get_mut(mirror))
+ .and_then(|v| v.as_object_mut())
+ .ok_or_else(|| format_err!("Failed to obtain JSON field for mirror {mirror}"))?;
+
+ match medium::list_snapshots(mountpoint, mirror) {
+ Ok(snapshots) => {
+ mirror_json.insert("snapshots".to_owned(), serde_json::json!(snapshots));
+ }
+ Err(err) => {
+ mirror_json.insert(
+ "errors".to_owned(),
+ serde_json::json!(format!("Failed to obtain snapshot list - {err}")),
+ );
+ }
+ }
+ }
+ json.remove("subscriptions");
+ format_and_print_result(&json.into(), &output_format);
+ }
+
+ Ok(())
+}
+
fn main() {
let rpcenv = CliEnvironment::new();
let cmd_def = CliCommandMap::new()
.insert("setup", CliCommand::new(&API_METHOD_SETUP))
+ .insert("status", CliCommand::new(&API_METHOD_STATUS))
.insert(
"offline-key",
CliCommand::new(&API_METHOD_SETUP_OFFLINE_KEY),
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [pve-devel] applied-series: [PATCH proxmox-offline-mirror 1/2] helper: make mountpoint non-optional
2022-09-21 11:04 [pve-devel] [PATCH proxmox-offline-mirror 1/2] helper: make mountpoint non-optional Fabian Grünbichler
2022-09-21 11:04 ` [pve-devel] [PATCH proxmox-offline-mirror 2/2] helper: add status command Fabian Grünbichler
@ 2022-10-21 11:03 ` Wolfgang Bumiller
1 sibling, 0 replies; 3+ messages in thread
From: Wolfgang Bumiller @ 2022-10-21 11:03 UTC (permalink / raw)
To: Fabian Grünbichler; +Cc: pve-devel
applied, thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-10-21 11:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-21 11:04 [pve-devel] [PATCH proxmox-offline-mirror 1/2] helper: make mountpoint non-optional Fabian Grünbichler
2022-09-21 11:04 ` [pve-devel] [PATCH proxmox-offline-mirror 2/2] helper: add status command Fabian Grünbichler
2022-10-21 11:03 ` [pve-devel] applied-series: [PATCH proxmox-offline-mirror 1/2] helper: make mountpoint non-optional Wolfgang Bumiller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox