public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Daniel Kral <d.kral@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH container] api: autocomplete rootdir storages for create, move-volume and clone
Date: Tue, 10 Sep 2024 13:23:42 +0200	[thread overview]
Message-ID: <20240910112342.114849-1-d.kral@proxmox.com> (raw)

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


             reply	other threads:[~2024-09-10 11:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-10 11:23 Daniel Kral [this message]
2024-09-10 14:36 ` [pve-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240910112342.114849-1-d.kral@proxmox.com \
    --to=d.kral@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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