From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 2213C1FF16B for ; Fri, 21 Nov 2025 17:59:03 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E6CAC891; Fri, 21 Nov 2025 17:59:03 +0100 (CET) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Date: Fri, 21 Nov 2025 17:58:30 +0100 Message-ID: <20251121165858.818307-2-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251121165858.818307-1-m.carrara@proxmox.com> References: <20251121165858.818307-1-m.carrara@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1763744307786 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.085 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [disks.pm, storage.pm, plugin.pm] Subject: [pve-devel] [RFC pve-storage master v2 1/10] api: plugins/storage: add initial routes and endpoints X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Add the following routes / endpoints: * `GET plugins/storage` Subdir index--lists the direct child path components (so, just 'plugin' currently). * `GET plugins/storage/plugin` Lists all installed storage plugins and their metadata. Currently, this is just an array of objects, with each object containing the plugin's `type()` and Perl module path. * `GET plugins/storage/plugin/{type}` Returns the metadata for a single plugin given by `{type}`. Signed-off-by: Max R. Carrara --- src/PVE/API2/Makefile | 1 + src/PVE/API2/Plugins/Makefile | 18 +++++ src/PVE/API2/Plugins/Storage.pm | 54 +++++++++++++ src/PVE/API2/Plugins/Storage/Makefile | 17 ++++ src/PVE/API2/Plugins/Storage/Plugin.pm | 104 +++++++++++++++++++++++++ 5 files changed, 194 insertions(+) create mode 100644 src/PVE/API2/Plugins/Makefile create mode 100644 src/PVE/API2/Plugins/Storage.pm create mode 100644 src/PVE/API2/Plugins/Storage/Makefile create mode 100644 src/PVE/API2/Plugins/Storage/Plugin.pm diff --git a/src/PVE/API2/Makefile b/src/PVE/API2/Makefile index fe316c5..01b7b28 100644 --- a/src/PVE/API2/Makefile +++ b/src/PVE/API2/Makefile @@ -5,3 +5,4 @@ install: install -D -m 0644 Disks.pm ${DESTDIR}${PERLDIR}/PVE/API2/Disks.pm make -C Storage install make -C Disks install + make -C Plugins install diff --git a/src/PVE/API2/Plugins/Makefile b/src/PVE/API2/Plugins/Makefile new file mode 100644 index 0000000..f59e75b --- /dev/null +++ b/src/PVE/API2/Plugins/Makefile @@ -0,0 +1,18 @@ +SOURCES = Storage.pm \ + + +SUBDIRS = Storage \ + + +INSTALL_PATH = ${DESTDIR}${PERLDIR}/PVE/API2/Plugins + + +.PHONY: install +install: + set -e && for SOURCE in ${SOURCES}; \ + do install -D -m 0644 $$SOURCE ${INSTALL_PATH}/$$SOURCE; \ + done + set -e && for SUBDIR in ${SUBDIRS}; \ + do make -C $$SUBDIR install; \ + done + diff --git a/src/PVE/API2/Plugins/Storage.pm b/src/PVE/API2/Plugins/Storage.pm new file mode 100644 index 0000000..53b883f --- /dev/null +++ b/src/PVE/API2/Plugins/Storage.pm @@ -0,0 +1,54 @@ +package PVE::API2::Plugins::Storage; + +use v5.36; + +use PVE::Storage; +use PVE::Storage::Plugin; + +use PVE::API2::Plugins::Storage::Plugin; + +use PVE::RESTHandler; +use base qw(PVE::RESTHandler); + +__PACKAGE__->register_method({ + subclass => 'PVE::API2::Plugins::Storage::Plugin', + path => 'plugin', +}); + +# plugins/storage + +__PACKAGE__->register_method({ + name => 'index', + path => '', + method => 'GET', + description => 'Directory index.', + permissions => { + user => 'all', + }, + parameters => { + additionalProperties => 0, + properties => {}, + }, + returns => { + type => 'array', + items => { + type => "object", + additionalProperties => 0, + properties => { + subdir => { + type => 'string', + }, + }, + }, + links => [{ rel => 'child', href => "{subdir}" }], + }, + code => sub($param) { + my $result = [ + { subdir => 'plugin' }, + ]; + + return $result; + }, +}); + +1; diff --git a/src/PVE/API2/Plugins/Storage/Makefile b/src/PVE/API2/Plugins/Storage/Makefile new file mode 100644 index 0000000..06473a2 --- /dev/null +++ b/src/PVE/API2/Plugins/Storage/Makefile @@ -0,0 +1,17 @@ +SOURCES = Plugin.pm \ + + +SUBDIRS = + + +INSTALL_PATH = ${DESTDIR}${PERLDIR}/PVE/API2/Plugins/Storage + +.PHONY: install +install: + set -e && for SOURCE in ${SOURCES}; \ + do install -D -m 0644 $$SOURCE ${INSTALL_PATH}/$$SOURCE; \ + done + set -e && for SUBDIR in ${SUBDIRS}; \ + do make -C $$SUBDIR install; \ + done + diff --git a/src/PVE/API2/Plugins/Storage/Plugin.pm b/src/PVE/API2/Plugins/Storage/Plugin.pm new file mode 100644 index 0000000..fd0f734 --- /dev/null +++ b/src/PVE/API2/Plugins/Storage/Plugin.pm @@ -0,0 +1,104 @@ +package PVE::API2::Plugins::Storage::Plugin; + +use v5.36; + +use HTTP::Status qw(:constants); + +use PVE::Exception qw(raise); +use PVE::Storage; +use PVE::Storage::Plugin; +use PVE::Tools qw(extract_param); + +use PVE::RESTHandler; +use base qw(PVE::RESTHandler); + +my $ALL_PLUGIN_TYPES = PVE::Storage::Plugin->lookup_types(); + +my $PLUGIN_METADATA_SCHEMA = { + type => 'object', + additionalProperties => 0, + properties => { + module => { + type => 'string', + optional => 0, + }, + type => { + type => 'string', + optional => 0, + enum => $ALL_PLUGIN_TYPES, + }, + }, +}; + +# plugins/storage/plugin + +__PACKAGE__->register_method({ + name => 'index', + path => '', + method => 'GET', + description => 'List all available storage plugins and their metadata.', + permissions => { + user => 'all', + }, + parameters => { + additionalProperties => 0, + properties => {}, + }, + returns => { + type => 'array', + items => $PLUGIN_METADATA_SCHEMA, + }, + code => sub($param) { + my $result = []; + + for my $type ($ALL_PLUGIN_TYPES->@*) { + my $plugin = PVE::Storage::Plugin->lookup($type); + + my $item = { + module => $plugin, + type => $type, + }; + + push($result->@*, $item); + } + + return $result; + }, +}); + +# plugins/storage/plugin/{type} + +__PACKAGE__->register_method({ + name => 'info', + path => '{type}', + method => 'GET', + description => 'Fetch metadata of a storage plugin.', + permissions => { + user => 'all', + }, + parameters => { + additionalProperties => 0, + properties => { + type => { + type => 'string', + }, + }, + }, + returns => $PLUGIN_METADATA_SCHEMA, + code => sub($param) { + my $param_type = extract_param($param, 'type'); + + my $plugin = eval { PVE::Storage::Plugin->lookup($param_type) }; + if ($@) { + raise("Plugin '$param_type' not found - $@", code => HTTP_NOT_FOUND); + } + + my $result = { + module => $plugin, + type => $param_type, + }; + + return $result; + }, +}); +1; -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel