public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH container] api: autocomplete rootdir storages for create, move-volume and clone
@ 2024-09-10 11:23 Daniel Kral
  2024-09-10 14:36 ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Kral @ 2024-09-10 11:23 UTC (permalink / raw)
  To: pve-devel

Adds a helper subroutine for enumerating storages that are enabled and
have the content type `rootdir` set, therefore supporting container
directories.

The autocompletion is added to the clone command and changed for the
create and move-volume commands, which previously suggested any storage
device. This is misleading as these commands will fail for any storage
that is not configured to store container directories.

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
I have already noticed that the create command has the default value
'local' for the storage parameter, which could fail on any installation
where the local storage is not configured to store rootdirs. This should
be fixed in a separate patch in my opinion.

 src/PVE/API2/LXC.pm |  5 +++--
 src/PVE/LXC.pm      | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index d9f1c0a..918e719 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -148,9 +148,9 @@ __PACKAGE__->register_method({
 	    },
 	    storage => get_standard_option('pve-storage-id', {
 		description => "Default Storage.",
+		completion => \&PVE::LXC::complete_storage,
 		default => 'local',
 		optional => 1,
-		completion => \&PVE::Storage::complete_storage_enabled,
 	    }),
 	    force => {
 		optional => 1,
@@ -1582,6 +1582,7 @@ __PACKAGE__->register_method({
             }),
 	    storage => get_standard_option('pve-storage-id', {
 		description => "Target storage for full clone.",
+		completion => \&PVE::LXC::complete_storage,
 		optional => 1,
 	    }),
 	    full => {
@@ -2084,7 +2085,7 @@ __PACKAGE__->register_method({
 	    },
 	    storage => get_standard_option('pve-storage-id', {
 		description => "Target Storage.",
-		completion => \&PVE::Storage::complete_storage_enabled,
+		completion => \&PVE::LXC::complete_storage,
 		optional => 1,
 	    }),
 	    delete => {
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 65d0fa8..269614c 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -2382,6 +2382,20 @@ sub complete_ctid_running {
     return &$complete_ctid_full(1);
 }
 
+sub complete_storage {
+    my $cfg = PVE::Storage::config();
+    my $ids = $cfg->{ids};
+
+    my $res = [];
+    foreach my $sid (keys %$ids) {
+	next if !PVE::Storage::storage_check_enabled($cfg, $sid, undef, 1);
+	next if !$ids->{$sid}->{content}->{rootdir};
+	push @$res, $sid;
+    }
+
+    return $res;
+}
+
 sub parse_id_maps {
     my ($conf) = @_;
 
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

* [pve-devel] applied: [PATCH container] api: autocomplete rootdir storages for create, move-volume and clone
  2024-09-10 11:23 [pve-devel] [PATCH container] api: autocomplete rootdir storages for create, move-volume and clone Daniel Kral
@ 2024-09-10 14:36 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2024-09-10 14:36 UTC (permalink / raw)
  To: Proxmox VE development discussion, Daniel Kral

Am 10/09/2024 um 13:23 schrieb Daniel Kral:
> Adds a helper subroutine for enumerating storages that are enabled and
> have the content type `rootdir` set, therefore supporting container
> directories.
> 
> The autocompletion is added to the clone command and changed for the
> create and move-volume commands, which previously suggested any storage
> device. This is misleading as these commands will fail for any storage
> that is not configured to store container directories.
> 
> Signed-off-by: Daniel Kral <d.kral@proxmox.com>
> ---
> I have already noticed that the create command has the default value
> 'local' for the storage parameter, which could fail on any installation
> where the local storage is not configured to store rootdirs. This should
> be fixed in a separate patch in my opinion.

good call

>  src/PVE/API2/LXC.pm |  5 +++--
>  src/PVE/LXC.pm      | 14 ++++++++++++++
>  2 files changed, 17 insertions(+), 2 deletions(-)
> 
>

applied, thanks!


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

end of thread, other threads:[~2024-09-10 14:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-10 11:23 [pve-devel] [PATCH container] api: autocomplete rootdir storages for create, move-volume and clone Daniel Kral
2024-09-10 14:36 ` [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