public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH v2 storage manager docs] Expose content-dirs through GUI + use relative paths
@ 2023-03-14 13:14 Leo Nunner
  2023-03-14 13:14 ` [pve-devel] [PATCH v2 storage] config: use relative paths for content overrides Leo Nunner
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Leo Nunner @ 2023-03-14 13:14 UTC (permalink / raw)
  To: pve-devel

Changes from v1:
    - make it clear that all paths are relative to the mountpoint by
      removing the requirement to have a preceeding / for paths.

storage:

Leo Nunner (1):
  config: use relative paths for content overrides

 PVE/Storage/Plugin.pm   | 6 +++---
 test/get_subdir_test.pm | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

manager:

Leo Nunner (1):
  gui: expose content-dirs property in storage edit/create

 www/manager6/storage/CIFSEdit.js |  8 +++
 www/manager6/storage/DirEdit.js  | 85 ++++++++++++++++++++++++++++++++
 www/manager6/storage/NFSEdit.js  |  8 +++
 3 files changed, 101 insertions(+)

docs:

Leo Nunner (1):
  config: remove reference to preceeding / from content-dirs

 pve-storage-dir.adoc | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

-- 
2.30.2





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

* [pve-devel] [PATCH v2 storage] config: use relative paths for content overrides
  2023-03-14 13:14 [pve-devel] [PATCH v2 storage manager docs] Expose content-dirs through GUI + use relative paths Leo Nunner
@ 2023-03-14 13:14 ` Leo Nunner
  2023-03-20 14:26   ` [pve-devel] applied: " Thomas Lamprecht
  2023-03-14 13:14 ` [pve-devel] [PATCH v2 manager] gui: expose content-dirs property in storage edit/create Leo Nunner
  2023-03-14 13:14 ` [pve-devel] [PATCH v2 docs] config: remove reference to preceeding / from content-dirs Leo Nunner
  2 siblings, 1 reply; 7+ messages in thread
From: Leo Nunner @ 2023-03-14 13:14 UTC (permalink / raw)
  To: pve-devel

Remove the requirement for paths to start with a /, as it might be
confusing to users.

Signed-off-by: Leo Nunner <l.nunner@proxmox.com>
---
RFC: I'm not really sure how much input validation we want to do here.
e.g., should we keep the user from appending or prepending slashes (e.g.
setting the override as /dir/)? Or should we just accept everything?

 PVE/Storage/Plugin.pm   | 6 +++---
 test/get_subdir_test.pm | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index ca7a0d4..6295aa2 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -355,7 +355,7 @@ PVE::JSONSchema::register_format('pve-dir-override', \&verify_dir_override);
 sub verify_dir_override {
     my ($value, $noerr) = @_;
 
-    if($value =~ m/^([a-z]+)=\/.+$/ &&
+    if($value =~ m/^([a-z]+)=[^.]+$/ &&
 	verify_content($1, $noerr)) {
 	return $value;
     }
@@ -659,9 +659,9 @@ sub get_subdir {
     die "storage definition has no path\n" if !$path;
     die "unknown vtype '$vtype'\n" if !exists($vtype_subdirs->{$vtype});
 
-    my $subdir = $scfg->{"content-dirs"}->{$vtype} // "/".$vtype_subdirs->{$vtype};
+    my $subdir = $scfg->{"content-dirs"}->{$vtype} // $vtype_subdirs->{$vtype};
 
-    return $path.$subdir;
+    return "$path/$subdir";
 }
 
 sub filesystem_path {
diff --git a/test/get_subdir_test.pm b/test/get_subdir_test.pm
index ff42985..b9d61d5 100644
--- a/test/get_subdir_test.pm
+++ b/test/get_subdir_test.pm
@@ -29,9 +29,9 @@ foreach my $type (keys %$vtype_subdirs) {
 
 # creates additional tests for overrides
 foreach my $type (keys %$vtype_subdirs) {
-    my $override = "/${type}_override";
+    my $override = "${type}_override";
     my $scfg_with_override = { path => '/some/path', 'content-dirs' => { $type => $override } };
-    push @$tests, [ $scfg_with_override, $type, "$scfg_with_override->{path}$scfg_with_override->{'content-dirs'}->{$type}" ];
+    push @$tests, [ $scfg_with_override, $type, "$scfg_with_override->{path}/$scfg_with_override->{'content-dirs'}->{$type}" ];
 }
 
 plan tests => scalar @$tests;
-- 
2.30.2





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

* [pve-devel] [PATCH v2 manager] gui: expose content-dirs property in storage edit/create
  2023-03-14 13:14 [pve-devel] [PATCH v2 storage manager docs] Expose content-dirs through GUI + use relative paths Leo Nunner
  2023-03-14 13:14 ` [pve-devel] [PATCH v2 storage] config: use relative paths for content overrides Leo Nunner
@ 2023-03-14 13:14 ` Leo Nunner
  2023-03-20 19:25   ` Thomas Lamprecht
  2023-03-14 13:14 ` [pve-devel] [PATCH v2 docs] config: remove reference to preceeding / from content-dirs Leo Nunner
  2 siblings, 1 reply; 7+ messages in thread
From: Leo Nunner @ 2023-03-14 13:14 UTC (permalink / raw)
  To: pve-devel

Add a separate tab for the storage edit/create panels to set the
recently introduced "content-dirs" property which overrides the
default directory locations. Analogous to the API implementation,
the tab was added for Directory, CIFS and NFS storages.

Signed-off-by: Leo Nunner <l.nunner@proxmox.com>
---
 www/manager6/storage/CIFSEdit.js |  8 +++
 www/manager6/storage/DirEdit.js  | 85 ++++++++++++++++++++++++++++++++
 www/manager6/storage/NFSEdit.js  |  8 +++
 3 files changed, 101 insertions(+)

diff --git a/www/manager6/storage/CIFSEdit.js b/www/manager6/storage/CIFSEdit.js
index 71415401..c909ccf2 100644
--- a/www/manager6/storage/CIFSEdit.js
+++ b/www/manager6/storage/CIFSEdit.js
@@ -218,6 +218,14 @@ Ext.define('PVE.storage.CIFSInputPanel', {
 	    },
 	];
 
+	me.extraTabs = [
+	    {
+		xtype: 'pveContentDirsTab',
+		title: gettext("Content Directories"),
+		onlineHelp: me.onlineHelp,
+	    },
+	];
+
 	me.callParent();
     },
 });
diff --git a/www/manager6/storage/DirEdit.js b/www/manager6/storage/DirEdit.js
index 7e9ec44d..f49aaeca 100644
--- a/www/manager6/storage/DirEdit.js
+++ b/www/manager6/storage/DirEdit.js
@@ -33,6 +33,91 @@ Ext.define('PVE.storage.DirInputPanel', {
 	    },
 	];
 
+	me.extraTabs = [
+	    {
+		xtype: 'pveContentDirsTab',
+		title: gettext("Content Directories"),
+		onlineHelp: me.onlineHelp,
+	    },
+	];
+
+	me.callParent();
+    },
+});
+
+Ext.define('PVE.panel.ContentDirsPanel', {
+    extend: 'Proxmox.panel.InputPanel',
+    xtype: 'pveContentDirsTab',
+
+    onGetValues: function(form) {
+	let str = PVE.Parser.printPropertyString(form);
+	let values = { "content-dirs": str };
+	return values;
+    },
+
+    onSetValues: function(values) {
+	return values?.["content-dirs"];
+    },
+
+    initComponent: function() {
+	let me = this;
+
+	me.column1 = [
+	    {
+		xtype: 'textfield',
+		name: 'images',
+		fieldLabel: gettext('Disk image'),
+		allowBlank: true,
+		emptyText: "images",
+	    },
+	    {
+		xtype: 'textfield',
+		name: 'iso',
+		fieldLabel: gettext('ISO image'),
+		allowBlank: true,
+		emptyText: "template/iso",
+	    },
+	    {
+		xtype: 'textfield',
+		name: 'vztmpl',
+		fieldLabel: gettext('CT template'),
+		allowBlank: true,
+		emptyText: "template/cache",
+	    },
+	];
+
+	me.column2 = [
+	    {
+		xtype: 'textfield',
+		name: 'backup',
+		fieldLabel: gettext('Backup files'),
+		allowBlank: true,
+		emptyText: "dump",
+	    },
+	    {
+		xtype: 'textfield',
+		name: 'rootdir',
+		fieldLabel: gettext('Container'),
+		allowBlank: true,
+		emptyText: "private",
+	    },
+	    {
+		xtype: 'textfield',
+		name: 'snippets',
+		fieldLabel: gettext('Snippets'),
+		allowBlank: true,
+		emptyText: "snippets",
+	    },
+	];
+
+	me.columnB = [
+	    {
+		xtype: 'displayfield',
+		userCls: 'pmx-hint',
+		value: gettext('Paths are relative to the mountpoint of the storage'),
+	    },
+	];
+
 	me.callParent();
     },
 });
diff --git a/www/manager6/storage/NFSEdit.js b/www/manager6/storage/NFSEdit.js
index 202c7de0..606e1c02 100644
--- a/www/manager6/storage/NFSEdit.js
+++ b/www/manager6/storage/NFSEdit.js
@@ -160,6 +160,14 @@ Ext.define('PVE.storage.NFSInputPanel', {
 	    },
 	];
 
+	me.extraTabs = [
+	    {
+		xtype: 'pveContentDirsTab',
+		title: gettext("Content Directories"),
+		onlineHelp: me.onlineHelp,
+	    },
+	];
+
 	me.callParent();
     },
 });
-- 
2.30.2





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

* [pve-devel] [PATCH v2 docs] config: remove reference to preceeding / from content-dirs
  2023-03-14 13:14 [pve-devel] [PATCH v2 storage manager docs] Expose content-dirs through GUI + use relative paths Leo Nunner
  2023-03-14 13:14 ` [pve-devel] [PATCH v2 storage] config: use relative paths for content overrides Leo Nunner
  2023-03-14 13:14 ` [pve-devel] [PATCH v2 manager] gui: expose content-dirs property in storage edit/create Leo Nunner
@ 2023-03-14 13:14 ` Leo Nunner
  2023-03-20 19:10   ` [pve-devel] applied: " Thomas Lamprecht
  2 siblings, 1 reply; 7+ messages in thread
From: Leo Nunner @ 2023-03-14 13:14 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Leo Nunner <l.nunner@proxmox.com>
---
 pve-storage-dir.adoc | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/pve-storage-dir.adoc b/pve-storage-dir.adoc
index 4eb8dcd..3367394 100644
--- a/pve-storage-dir.adoc
+++ b/pve-storage-dir.adoc
@@ -57,8 +57,7 @@ in the following format:
  vtype=path
 
 Where `vtype` is one of the allowed content types for the storage, and
-`path` is a path relative to the mountpoint of the storage, preceded
-with /.
+`path` is a path relative to the mountpoint of the storage.
 
 .Configuration Example (`/etc/pve/storage.cfg`)
 ----
@@ -67,7 +66,7 @@ dir: backup
         content backup
         prune-backups keep-last=7
         max-protected-backups 3
-        content-dirs backup=/custom/backup/dir
+        content-dirs backup=custom/backup/dir
 ----
 
 The above configuration defines a storage pool called `backup`. That pool can be
-- 
2.30.2





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

* [pve-devel] applied: [PATCH v2 storage] config: use relative paths for content overrides
  2023-03-14 13:14 ` [pve-devel] [PATCH v2 storage] config: use relative paths for content overrides Leo Nunner
@ 2023-03-20 14:26   ` Thomas Lamprecht
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Lamprecht @ 2023-03-20 14:26 UTC (permalink / raw)
  To: Proxmox VE development discussion, Leo Nunner

Am 14/03/2023 um 14:14 schrieb Leo Nunner:
> Remove the requirement for paths to start with a /, as it might be
> confusing to users.
> 
> Signed-off-by: Leo Nunner <l.nunner@proxmox.com>
> ---
> RFC: I'm not really sure how much input validation we want to do here.
> e.g., should we keep the user from appending or prepending slashes (e.g.
> setting the override as /dir/)? Or should we just accept everything?
> 
>  PVE/Storage/Plugin.pm   | 6 +++---
>  test/get_subdir_test.pm | 4 ++--
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
>

applied, with trivial merge conflict for code-style fixes I did inbetween
resolved, thanks!

Also added a follow up that allows using dots, as long as it's not followed by
another dot, and enforces max-component and a overly-strict max-path length
here already.




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

* [pve-devel] applied: [PATCH v2 docs] config: remove reference to preceeding / from content-dirs
  2023-03-14 13:14 ` [pve-devel] [PATCH v2 docs] config: remove reference to preceeding / from content-dirs Leo Nunner
@ 2023-03-20 19:10   ` Thomas Lamprecht
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Lamprecht @ 2023-03-20 19:10 UTC (permalink / raw)
  To: Proxmox VE development discussion, Leo Nunner

Am 14/03/2023 um 14:14 schrieb Leo Nunner:
> Signed-off-by: Leo Nunner <l.nunner@proxmox.com>
> ---
>  pve-storage-dir.adoc | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
>

applied, thanks!




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

* Re: [pve-devel] [PATCH v2 manager] gui: expose content-dirs property in storage edit/create
  2023-03-14 13:14 ` [pve-devel] [PATCH v2 manager] gui: expose content-dirs property in storage edit/create Leo Nunner
@ 2023-03-20 19:25   ` Thomas Lamprecht
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Lamprecht @ 2023-03-20 19:25 UTC (permalink / raw)
  To: Proxmox VE development discussion, Leo Nunner

Am 14/03/2023 um 14:14 schrieb Leo Nunner:
> Add a separate tab for the storage edit/create panels to set the
> recently introduced "content-dirs" property which overrides the
> default directory locations. Analogous to the API implementation,
> the tab was added for Directory, CIFS and NFS storages.
> 
> Signed-off-by: Leo Nunner <l.nunner@proxmox.com>
> ---
>  www/manager6/storage/CIFSEdit.js |  8 +++
>  www/manager6/storage/DirEdit.js  | 85 ++++++++++++++++++++++++++++++++
>  www/manager6/storage/NFSEdit.js  |  8 +++
>  3 files changed, 101 insertions(+)
> 

> +Ext.define('PVE.panel.ContentDirsPanel', {
> +    extend: 'Proxmox.panel.InputPanel',

this shouldn't be squished into DirEdit, but rather live in its own file - e.g. in
panel/

> +    xtype: 'pveContentDirsTab',
> +
> +    onGetValues: function(form) {

while form isn't wrong, it has IMO merits to keep the more widely used
`values` as parameter name here.

> +	let str = PVE.Parser.printPropertyString(form);
> +	let values = { "content-dirs": str };
> +	return values;

could be as short as:

onGetValues: values => ({ "content-dirs", PVE.Parser.printPropertyString(values) }),

> +    },
> +
> +    onSetValues: function(values) {
> +	return values?.["content-dirs"];
> +    },

could be:

onSetValues: values => values?.["content-dirs"],

without loosing really any readability

> +
> +    initComponent: function() {
> +	let me = this;
> +
> +	me.column1 = [
> +	    {
> +		xtype: 'textfield',
> +		name: 'images',
> +		fieldLabel: gettext('Disk image'),

We normally use Title Case for field labels.

> +		allowBlank: true,
> +		emptyText: "images",

It would UX do good if you define a vtype (see Toolkit.js in manager or widget toolkit)
for the regex used by the backend to help users catching bogus entries early.

Above two (casing & vtype) applies for the remaining fields here.


Note also that having things like disks or the like editable for existing storages
can break things fast. I'd maybe be open for having snippets, ISOs and CT templates
editable, and even then show a warning hint that existing guest might be affected by
the change (i.e., not start anymore). FYI: pmxDisplayEditField is designed for such
mixed create/edit -> editable/display-only use-cases.





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

end of thread, other threads:[~2023-03-20 19:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-14 13:14 [pve-devel] [PATCH v2 storage manager docs] Expose content-dirs through GUI + use relative paths Leo Nunner
2023-03-14 13:14 ` [pve-devel] [PATCH v2 storage] config: use relative paths for content overrides Leo Nunner
2023-03-20 14:26   ` [pve-devel] applied: " Thomas Lamprecht
2023-03-14 13:14 ` [pve-devel] [PATCH v2 manager] gui: expose content-dirs property in storage edit/create Leo Nunner
2023-03-20 19:25   ` Thomas Lamprecht
2023-03-14 13:14 ` [pve-devel] [PATCH v2 docs] config: remove reference to preceeding / from content-dirs Leo Nunner
2023-03-20 19:10   ` [pve-devel] applied: " Thomas Lamprecht

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