public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup 1/3] api2/tape/drive: add optional label-text to erase
@ 2021-02-16  8:35 Dominik Csapak
  2021-02-16  8:35 ` [pbs-devel] [PATCH proxmox-backup 2/3] ui: tape/TapeInventory: add erase button Dominik Csapak
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dominik Csapak @ 2021-02-16  8:35 UTC (permalink / raw)
  To: pbs-devel

if given, erases the tape only iff the inserted tape contains that label
used to safeguard tape erasing from ui for standalone drives

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/api2/tape/drive.rs | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/api2/tape/drive.rs b/src/api2/tape/drive.rs
index 4991d66b..12709df9 100644
--- a/src/api2/tape/drive.rs
+++ b/src/api2/tape/drive.rs
@@ -202,19 +202,23 @@ pub async fn unload(
                 optional: true,
                 default: true,
             },
+            "label-text": {
+                schema: MEDIA_LABEL_SCHEMA,
+                optional: true,
+            },
         },
     },
     returns: {
         schema: UPID_SCHEMA,
     },
 )]
-/// Erase media
+/// Erase media. Check for label-text if given (cancels if wrong media).
 pub fn erase_media(
     drive: String,
     fast: Option<bool>,
+    label_text: Option<String>,
     rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<Value, Error> {
-
     let (config, _digest) = config::drive::config()?;
 
     // early check/lock before starting worker
@@ -236,16 +240,32 @@ pub fn erase_media(
 
             match drive.read_label() {
                 Err(err) => {
+                    if let Some(label) = label_text {
+                        bail!("expected label '{}', found unrelated data", label);
+                    }
                     /* assume drive contains no or unrelated data */
                     task_log!(worker, "unable to read media label: {}", err);
                     task_log!(worker, "erase anyways");
                     drive.erase_media(fast.unwrap_or(true))?;
                 }
                 Ok((None, _)) => {
+                    if let Some(label) = label_text {
+                        bail!("expected label '{}', found empty tape", label);
+                    }
                     task_log!(worker, "found empty media - erase anyways");
                     drive.erase_media(fast.unwrap_or(true))?;
                 }
                 Ok((Some(media_id), _key_config)) => {
+                    if let Some(label_text) = label_text {
+                        if media_id.label.label_text != label_text {
+                            bail!(
+                                "expected label '{}', found '{}', aborting",
+                                label_text,
+                                media_id.label.label_text
+                            );
+                        }
+                    }
+
                     task_log!(
                         worker,
                         "found media '{}' with uuid '{}'",
-- 
2.20.1





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

* [pbs-devel] [PATCH proxmox-backup 2/3] ui: tape/TapeInventory: add erase button
  2021-02-16  8:35 [pbs-devel] [PATCH proxmox-backup 1/3] api2/tape/drive: add optional label-text to erase Dominik Csapak
@ 2021-02-16  8:35 ` Dominik Csapak
  2021-02-16  8:35 ` [pbs-devel] [PATCH proxmox-backup 3/3] ui: tape/BackupOverview: show mediaset loading error in msg box instead Dominik Csapak
  2021-02-16  9:18 ` [pbs-devel] applied: [PATCH proxmox-backup 1/3] api2/tape/drive: add optional label-text to erase Dietmar Maurer
  2 siblings, 0 replies; 4+ messages in thread
From: Dominik Csapak @ 2021-02-16  8:35 UTC (permalink / raw)
  To: pbs-devel

to erase the selected tape

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
i'll put that feature also on the changer library screen, and limit
the drive selection here to standalone drives in the future
for now this should be good enough

 www/tape/TapeInventory.js | 56 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/www/tape/TapeInventory.js b/www/tape/TapeInventory.js
index 25dea1ba..ec10f5c9 100644
--- a/www/tape/TapeInventory.js
+++ b/www/tape/TapeInventory.js
@@ -33,6 +33,56 @@ Ext.define('PBS.TapeManagement.TapeInventory', {
 	    Ext.create('PBS.TapeManagement.LabelMediaWindow').show();
 	},
 
+	erase: function() {
+	    let me = this;
+	    let view = me.getView();
+	    let selection = view.getSelection();
+	    if (!selection || selection.length < 1) {
+		return;
+	    }
+	    let label = selection[0].data['label-text'];
+	    Ext.create('Proxmox.window.Edit', {
+		title: gettext('Erase'),
+		url: `/api2/extjs/tape/drive`,
+		showProgress: true,
+		submitUrl: function(url, values) {
+		    let drive = values.drive;
+		    delete values.drive;
+		    return `${url}/${drive}/erase-media`;
+		},
+		method: 'POST',
+		items: [
+		    {
+			xtype: 'displayfield',
+			cls: 'pmx-hint',
+			value: gettext('Make sure to insert the tape into the selected drive.'),
+		    },
+		    {
+			xtype: 'pbsDriveSelector',
+			fieldLabel: gettext('Drive'),
+			name: 'drive',
+		    },
+		    {
+			xtype: 'displayfield',
+			name: 'label-text',
+			value: label,
+			submitValue: true,
+			fieldLabel: gettext('Media'),
+		    },
+		    {
+			xtype: 'proxmoxcheckbox',
+			fieldLabel: gettext('Fast Erase'),
+			name: 'fast',
+		    },
+		],
+		listeners: {
+		    destroy: function() {
+			me.reload();
+		    },
+		},
+	    }).show();
+	},
+
 	moveToVault: function() {
 	    let me = this;
 	    let view = me.getView();
@@ -107,6 +157,12 @@ Ext.define('PBS.TapeManagement.TapeInventory', {
 	    handler: 'moveToVault',
 	    enableFn: (rec) => !rec.data.location.startsWith('online-'),
 	},
+	{
+	    xtype: 'proxmoxButton',
+	    text: gettext('Erase'),
+	    disabled: true,
+	    handler: 'erase',
+	},
     ],
 
     columns: [
-- 
2.20.1





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

* [pbs-devel] [PATCH proxmox-backup 3/3] ui: tape/BackupOverview: show mediaset loading error in msg box instead
  2021-02-16  8:35 [pbs-devel] [PATCH proxmox-backup 1/3] api2/tape/drive: add optional label-text to erase Dominik Csapak
  2021-02-16  8:35 ` [pbs-devel] [PATCH proxmox-backup 2/3] ui: tape/TapeInventory: add erase button Dominik Csapak
@ 2021-02-16  8:35 ` Dominik Csapak
  2021-02-16  9:18 ` [pbs-devel] applied: [PATCH proxmox-backup 1/3] api2/tape/drive: add optional label-text to erase Dietmar Maurer
  2 siblings, 0 replies; 4+ messages in thread
From: Dominik Csapak @ 2021-02-16  8:35 UTC (permalink / raw)
  To: pbs-devel

if a catalog is missing (or the loading otherwise throws an error), show
the error message in a msg box instead of a mask. this way a user can
still navigate the tree

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 www/tape/BackupOverview.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/www/tape/BackupOverview.js b/www/tape/BackupOverview.js
index c90d23d7..a5bbfc09 100644
--- a/www/tape/BackupOverview.js
+++ b/www/tape/BackupOverview.js
@@ -148,7 +148,8 @@ Ext.define('PBS.TapeManagement.BackupOverview', {
 		Proxmox.Utils.setErrorMask(view, false);
 		node.expand();
 	    } catch (error) {
-		Proxmox.Utils.setErrorMask(view, error.toString());
+		Proxmox.Utils.setErrorMask(view, false);
+		Ext.Msg.alert('Error', error.toString());
 	    }
 	},
 
-- 
2.20.1





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

* [pbs-devel] applied: [PATCH proxmox-backup 1/3] api2/tape/drive: add optional label-text to erase
  2021-02-16  8:35 [pbs-devel] [PATCH proxmox-backup 1/3] api2/tape/drive: add optional label-text to erase Dominik Csapak
  2021-02-16  8:35 ` [pbs-devel] [PATCH proxmox-backup 2/3] ui: tape/TapeInventory: add erase button Dominik Csapak
  2021-02-16  8:35 ` [pbs-devel] [PATCH proxmox-backup 3/3] ui: tape/BackupOverview: show mediaset loading error in msg box instead Dominik Csapak
@ 2021-02-16  9:18 ` Dietmar Maurer
  2 siblings, 0 replies; 4+ messages in thread
From: Dietmar Maurer @ 2021-02-16  9:18 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Dominik Csapak

applied all 3 patches




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

end of thread, other threads:[~2021-02-16  9:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-16  8:35 [pbs-devel] [PATCH proxmox-backup 1/3] api2/tape/drive: add optional label-text to erase Dominik Csapak
2021-02-16  8:35 ` [pbs-devel] [PATCH proxmox-backup 2/3] ui: tape/TapeInventory: add erase button Dominik Csapak
2021-02-16  8:35 ` [pbs-devel] [PATCH proxmox-backup 3/3] ui: tape/BackupOverview: show mediaset loading error in msg box instead Dominik Csapak
2021-02-16  9:18 ` [pbs-devel] applied: [PATCH proxmox-backup 1/3] api2/tape/drive: add optional label-text to erase 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