[pve-devel] [RFC pve-storage master v2 4/10] api: plugins/storage/plugin: factor plugin metadata code into helper
Max R. Carrara
m.carrara at proxmox.com
Fri Nov 21 17:58:33 CET 2025
in order to reduce the number of places that need to be touched when
adding more properties to the returned metadata.
Signed-off-by: Max R. Carrara <m.carrara at proxmox.com>
---
src/PVE/API2/Plugins/Storage/Plugin.pm | 35 +++++++++++---------------
1 file changed, 15 insertions(+), 20 deletions(-)
diff --git a/src/PVE/API2/Plugins/Storage/Plugin.pm b/src/PVE/API2/Plugins/Storage/Plugin.pm
index 757ae1e..457c070 100644
--- a/src/PVE/API2/Plugins/Storage/Plugin.pm
+++ b/src/PVE/API2/Plugins/Storage/Plugin.pm
@@ -65,6 +65,19 @@ my sub get_schema_for_plugin : prototype($) ($plugin) {
return $schema;
}
+my sub build_plugin_metadata : prototype($) ($type) {
+ my $plugin = eval { PVE::Storage::Plugin->lookup($type) };
+ if ($@) {
+ raise("Plugin '$type' not found - $@", code => HTTP_NOT_FOUND);
+ }
+
+ return {
+ module => $plugin,
+ schema => get_schema_for_plugin($plugin),
+ type => $type,
+ };
+}
+
# plugins/storage/plugin
__PACKAGE__->register_method({
@@ -87,14 +100,7 @@ __PACKAGE__->register_method({
my $result = [];
for my $type ($ALL_PLUGIN_TYPES->@*) {
- my $plugin = PVE::Storage::Plugin->lookup($type);
-
- my $item = {
- module => $plugin,
- schema => get_schema_for_plugin($plugin),
- type => $type,
- };
-
+ my $item = build_plugin_metadata($type);
push($result->@*, $item);
}
@@ -124,18 +130,7 @@ __PACKAGE__->register_method({
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,
- schema => get_schema_for_plugin($plugin),
- type => $param_type,
- };
-
- return $result;
+ return build_plugin_metadata($param_type);
},
});
1;
--
2.47.3
More information about the pve-devel
mailing list