public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox/proxmox-backup] fix some proxmox-tape calls
@ 2021-04-30 12:51 Dominik Csapak
  2021-04-30 12:51 ` [pbs-devel] [PATCH proxmox 1/1] proxmox/api/cli: add extract_output_format Dominik Csapak
  2021-04-30 12:51 ` [pbs-devel] [PATCH proxmox-backup 1/1] bin: use extract_output_format where necessary Dominik Csapak
  0 siblings, 2 replies; 5+ messages in thread
From: Dominik Csapak @ 2021-04-30 12:51 UTC (permalink / raw)
  To: pbs-devel

we sometimes forgot to remove 'output-format' from the 'params'
variable, which we used for the local api call, resulting in an
invalid parameter error

fixing it by adding a 'extract_output_format' in addition to
'get_output_format' and using that where we need it

ofc, proxmox-backup needs to depend on a bumped version of proxmox
for this to work

proxmox:

Dominik Csapak (1):
  proxmox/api/cli: add extract_output_format

 proxmox/src/api/cli/text_table.rs | 12 ++++++++++++
 1 file changed, 12 insertions(+)

proxmox-backup:

Dominik Csapak (1):
  bin: use extract_output_format where necessary

 src/bin/proxmox-backup-client.rs |  3 +--
 src/bin/proxmox-tape.rs          | 32 ++++++++++++++++----------------
 2 files changed, 17 insertions(+), 18 deletions(-)

-- 
2.20.1





^ permalink raw reply	[flat|nested] 5+ messages in thread

* [pbs-devel] [PATCH proxmox 1/1] proxmox/api/cli: add extract_output_format
  2021-04-30 12:51 [pbs-devel] [PATCH proxmox/proxmox-backup] fix some proxmox-tape calls Dominik Csapak
@ 2021-04-30 12:51 ` Dominik Csapak
  2021-05-03  7:03   ` [pbs-devel] applied: " Dietmar Maurer
  2021-04-30 12:51 ` [pbs-devel] [PATCH proxmox-backup 1/1] bin: use extract_output_format where necessary Dominik Csapak
  1 sibling, 1 reply; 5+ messages in thread
From: Dominik Csapak @ 2021-04-30 12:51 UTC (permalink / raw)
  To: pbs-devel

just getting it is not enough, sometimes we want it to remove from
params (if possble) too

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 proxmox/src/api/cli/text_table.rs | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/proxmox/src/api/cli/text_table.rs b/proxmox/src/api/cli/text_table.rs
index 5ff2db0..84d9f34 100644
--- a/proxmox/src/api/cli/text_table.rs
+++ b/proxmox/src/api/cli/text_table.rs
@@ -25,6 +25,18 @@ pub fn get_output_format(param: &Value) -> String {
     output_format.unwrap_or_else(|| String::from("text"))
 }
 
+/// Helper to get output format from parameters or environment
+/// and removing from parameters
+pub fn extract_output_format(param: &mut Value) -> String {
+    let output_format = get_output_format(param);
+
+    if let Some(param) = param.as_object_mut() {
+        param.remove("output-format");
+    }
+
+    output_format
+}
+
 /// Helper to get TableFormatOptions with default from environment
 pub fn default_table_format_options() -> TableFormatOptions {
     let no_border = std::env::var(ENV_VAR_PROXMOX_OUTPUT_NO_BORDER)
-- 
2.20.1





^ permalink raw reply	[flat|nested] 5+ messages in thread

* [pbs-devel] [PATCH proxmox-backup 1/1] bin: use extract_output_format where necessary
  2021-04-30 12:51 [pbs-devel] [PATCH proxmox/proxmox-backup] fix some proxmox-tape calls Dominik Csapak
  2021-04-30 12:51 ` [pbs-devel] [PATCH proxmox 1/1] proxmox/api/cli: add extract_output_format Dominik Csapak
@ 2021-04-30 12:51 ` Dominik Csapak
  2021-05-03  7:04   ` [pbs-devel] applied: " Dietmar Maurer
  1 sibling, 1 reply; 5+ messages in thread
From: Dominik Csapak @ 2021-04-30 12:51 UTC (permalink / raw)
  To: pbs-devel

else we sometimes forget to remove it from the 'params' variable
and use that further, running into 'invalid parameter' errors

found by giving 'output-format' paramter to proxmox-tape status

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/bin/proxmox-backup-client.rs |  3 +--
 src/bin/proxmox-tape.rs          | 32 ++++++++++++++++----------------
 2 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs
index 50703dcb..578b2680 100644
--- a/src/bin/proxmox-backup-client.rs
+++ b/src/bin/proxmox-backup-client.rs
@@ -1266,13 +1266,12 @@ async fn prune_async(mut param: Value) -> Result<Value, Error> {
     let group = tools::required_string_param(&param, "group")?;
     let group: BackupGroup = group.parse()?;
 
-    let output_format = get_output_format(&param);
+    let output_format = extract_output_format(&mut param);
 
     let quiet = param["quiet"].as_bool().unwrap_or(false);
 
     param.as_object_mut().unwrap().remove("repository");
     param.as_object_mut().unwrap().remove("group");
-    param.as_object_mut().unwrap().remove("output-format");
     param.as_object_mut().unwrap().remove("quiet");
 
     param["backup-type"] = group.backup_type().into();
diff --git a/src/bin/proxmox-tape.rs b/src/bin/proxmox-tape.rs
index e1b87e35..e18f334c 100644
--- a/src/bin/proxmox-tape.rs
+++ b/src/bin/proxmox-tape.rs
@@ -119,7 +119,7 @@ pub fn extract_drive_name(
 /// Format media
 async fn format_media(mut param: Value) -> Result<(), Error> {
 
-    let output_format = get_output_format(&param);
+    let output_format = extract_output_format(&mut param);
 
     let (config, _digest) = config::drive::config()?;
 
@@ -152,7 +152,7 @@ async fn format_media(mut param: Value) -> Result<(), Error> {
 /// Rewind tape
 async fn rewind(mut param: Value) -> Result<(), Error> {
 
-    let output_format = get_output_format(&param);
+    let output_format = extract_output_format(&mut param);
 
     let (config, _digest) = config::drive::config()?;
 
@@ -185,7 +185,7 @@ async fn rewind(mut param: Value) -> Result<(), Error> {
 /// Eject/Unload drive media
 async fn eject_media(mut param: Value) -> Result<(), Error> {
 
-    let output_format = get_output_format(&param);
+    let output_format = extract_output_format(&mut param);
 
     let (config, _digest) = config::drive::config()?;
 
@@ -221,7 +221,7 @@ async fn eject_media(mut param: Value) -> Result<(), Error> {
 /// Load media with specified label
 async fn load_media(mut param: Value) -> Result<(), Error> {
 
-    let output_format = get_output_format(&param);
+    let output_format = extract_output_format(&mut param);
 
     let (config, _digest) = config::drive::config()?;
 
@@ -318,7 +318,7 @@ async fn load_media_from_slot(mut param: Value) -> Result<(), Error> {
 /// Unload media via changer
 async fn unload_media(mut param: Value) -> Result<(), Error> {
 
-    let output_format = get_output_format(&param);
+    let output_format = extract_output_format(&mut param);
 
     let (config, _digest) = config::drive::config()?;
 
@@ -358,7 +358,7 @@ async fn unload_media(mut param: Value) -> Result<(), Error> {
 /// Label media
 async fn label_media(mut param: Value) -> Result<(), Error> {
 
-    let output_format = get_output_format(&param);
+    let output_format = extract_output_format(&mut param);
 
     let (config, _digest) = config::drive::config()?;
 
@@ -396,7 +396,7 @@ async fn label_media(mut param: Value) -> Result<(), Error> {
 /// Read media label
 async fn read_label(mut param: Value) -> Result<(), Error> {
 
-    let output_format = get_output_format(&param);
+    let output_format = extract_output_format(&mut param);
 
     let (config, _digest) = config::drive::config()?;
 
@@ -456,7 +456,7 @@ async fn inventory(
     mut param: Value,
 ) -> Result<(), Error> {
 
-    let output_format = get_output_format(&param);
+    let output_format = extract_output_format(&mut param);
 
     let (config, _digest) = config::drive::config()?;
     let drive = extract_drive_name(&mut param, &config)?;
@@ -514,7 +514,7 @@ async fn inventory(
 /// Label media with barcodes from changer device
 async fn barcode_label_media(mut param: Value) -> Result<(), Error> {
 
-    let output_format = get_output_format(&param);
+    let output_format = extract_output_format(&mut param);
 
     let (config, _digest) = config::drive::config()?;
 
@@ -653,7 +653,7 @@ fn debug_scan(mut param: Value) -> Result<(), Error> {
 /// Read Cartridge Memory (Medium auxiliary memory attributes)
 async fn cartridge_memory(mut param: Value) -> Result<(), Error> {
 
-    let output_format = get_output_format(&param);
+    let output_format = extract_output_format(&mut param);
 
     let (config, _digest) = config::drive::config()?;
 
@@ -694,7 +694,7 @@ async fn cartridge_memory(mut param: Value) -> Result<(), Error> {
 /// Read Volume Statistics (SCSI log page 17h)
 async fn volume_statistics(mut param: Value) -> Result<(), Error> {
 
-    let output_format = get_output_format(&param);
+    let output_format = extract_output_format(&mut param);
 
     let (config, _digest) = config::drive::config()?;
 
@@ -732,7 +732,7 @@ async fn volume_statistics(mut param: Value) -> Result<(), Error> {
 /// Get drive/media status
 async fn status(mut param: Value) -> Result<(), Error> {
 
-    let output_format = get_output_format(&param);
+    let output_format = extract_output_format(&mut param);
 
     let (config, _digest) = config::drive::config()?;
 
@@ -792,7 +792,7 @@ async fn status(mut param: Value) -> Result<(), Error> {
 /// Clean drive
 async fn clean_drive(mut param: Value) -> Result<(), Error> {
 
-    let output_format = get_output_format(&param);
+    let output_format = extract_output_format(&mut param);
 
     let (config, _digest) = config::drive::config()?;
 
@@ -853,7 +853,7 @@ async fn clean_drive(mut param: Value) -> Result<(), Error> {
 /// Backup datastore to tape media pool
 async fn backup(mut param: Value) -> Result<(), Error> {
 
-    let output_format = get_output_format(&param);
+    let output_format = extract_output_format(&mut param);
 
     let (config, _digest) = config::drive::config()?;
 
@@ -900,7 +900,7 @@ async fn backup(mut param: Value) -> Result<(), Error> {
 /// Restore data from media-set
 async fn restore(mut param: Value) -> Result<(), Error> {
 
-    let output_format = get_output_format(&param);
+    let output_format = extract_output_format(&mut param);
 
     let (config, _digest) = config::drive::config()?;
 
@@ -947,7 +947,7 @@ async fn restore(mut param: Value) -> Result<(), Error> {
 /// Scan media and record content
 async fn catalog_media(mut param: Value)  -> Result<(), Error> {
 
-    let output_format = get_output_format(&param);
+    let output_format = extract_output_format(&mut param);
 
     let (config, _digest) = config::drive::config()?;
 
-- 
2.20.1





^ permalink raw reply	[flat|nested] 5+ messages in thread

* [pbs-devel] applied: [PATCH proxmox 1/1] proxmox/api/cli: add extract_output_format
  2021-04-30 12:51 ` [pbs-devel] [PATCH proxmox 1/1] proxmox/api/cli: add extract_output_format Dominik Csapak
@ 2021-05-03  7:03   ` Dietmar Maurer
  0 siblings, 0 replies; 5+ messages in thread
From: Dietmar Maurer @ 2021-05-03  7:03 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Dominik Csapak

applied

On 4/30/21 2:51 PM, Dominik Csapak wrote:
> just getting it is not enough, sometimes we want it to remove from
> params (if possble) too
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
>   proxmox/src/api/cli/text_table.rs | 12 ++++++++++++
>   1 file changed, 12 insertions(+)
>
> diff --git a/proxmox/src/api/cli/text_table.rs b/proxmox/src/api/cli/text_table.rs
> index 5ff2db0..84d9f34 100644
> --- a/proxmox/src/api/cli/text_table.rs
> +++ b/proxmox/src/api/cli/text_table.rs
> @@ -25,6 +25,18 @@ pub fn get_output_format(param: &Value) -> String {
>       output_format.unwrap_or_else(|| String::from("text"))
>   }
>   
> +/// Helper to get output format from parameters or environment
> +/// and removing from parameters
> +pub fn extract_output_format(param: &mut Value) -> String {
> +    let output_format = get_output_format(param);
> +
> +    if let Some(param) = param.as_object_mut() {
> +        param.remove("output-format");
> +    }
> +
> +    output_format
> +}
> +
>   /// Helper to get TableFormatOptions with default from environment
>   pub fn default_table_format_options() -> TableFormatOptions {
>       let no_border = std::env::var(ENV_VAR_PROXMOX_OUTPUT_NO_BORDER)




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [pbs-devel] applied: [PATCH proxmox-backup 1/1] bin: use extract_output_format where necessary
  2021-04-30 12:51 ` [pbs-devel] [PATCH proxmox-backup 1/1] bin: use extract_output_format where necessary Dominik Csapak
@ 2021-05-03  7:04   ` Dietmar Maurer
  0 siblings, 0 replies; 5+ messages in thread
From: Dietmar Maurer @ 2021-05-03  7:04 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Dominik Csapak

applied






^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-03  7:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-30 12:51 [pbs-devel] [PATCH proxmox/proxmox-backup] fix some proxmox-tape calls Dominik Csapak
2021-04-30 12:51 ` [pbs-devel] [PATCH proxmox 1/1] proxmox/api/cli: add extract_output_format Dominik Csapak
2021-05-03  7:03   ` [pbs-devel] applied: " Dietmar Maurer
2021-04-30 12:51 ` [pbs-devel] [PATCH proxmox-backup 1/1] bin: use extract_output_format where necessary Dominik Csapak
2021-05-03  7:04   ` [pbs-devel] applied: " Dietmar Maurer

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