From e72845efbf847b1b2cd4288ba901ff39371639b5 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 6 Mar 2024 14:13:54 +0100 Subject: [PATCH] api: add storage/{storage}/import-metadata This will be used for returning the base meta information of a external VM that is about to be imported into Proxmox VE. A front-end can use this endpoint to show the proposed configs with potential override switches to the user, so that they can adapt the most important options to ensure that import can work. Signed-off-by: Wolfgang Bumiller [ TL: add more commit message with some background ] Signed-off-by: Thomas Lamprecht --- src/PVE/API2/Storage/Status.pm | 71 ++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/PVE/API2/Storage/Status.pm b/src/PVE/API2/Storage/Status.pm index bc67b81..84bb605 100644 --- a/src/PVE/API2/Storage/Status.pm +++ b/src/PVE/API2/Storage/Status.pm @@ -227,6 +227,7 @@ __PACKAGE__->register_method ({ { subdir => 'content' }, { subdir => 'download-url' }, { subdir => 'file-restore' }, + { subdir => 'import-metadata' }, { subdir => 'prunebackups' }, { subdir => 'rrd' }, { subdir => 'rrddata' }, @@ -676,4 +677,74 @@ __PACKAGE__->register_method({ return $rpcenv->fork_worker('download', $worker_id, $user, $worker); }}); +__PACKAGE__->register_method({ + name => 'get_import_metadata', + path => '{storage}/import-metadata', + method => 'GET', + description => + "Get the base parameters for creating a guest which imports data from a foreign importable" + ." guest, like an ESXi VM", + proxyto => 'node', + permissions => { + description => "You need read access for the volume.", + user => 'all', + }, + protected => 1, + parameters => { + additionalProperties => 0, + properties => { + node => get_standard_option('pve-node'), + storage => get_standard_option('pve-storage-id'), + volume => { + description => "Volume identifier", + type => 'string', + }, + target => get_standard_option('pve-storage-id', { + description => 'The default target storage', + optional => 1, + default => 'local', + }), + }, + }, + returns => { + type => "object", + description => 'Information about how to import a guest.', + additionalProperties => 0, + properties => { + type => { + type => 'string', + enum => [ 'vm' ], + description => 'The type of guest this is going to produce.', + }, + 'create-args' => { + type => 'object', + additionalProperties => 1, + description => 'Parameters which can be used in a call to create a VM or container.', + }, + }, + }, + code => sub { + my ($param) = @_; + + my $rpcenv = PVE::RPCEnvironment::get(); + my $authuser = $rpcenv->get_user(); + + my ($storeid, $volume, $target) = $param->@{qw(storage volume target)}; + my $volid = "$storeid:$volume"; + + my $cfg = PVE::Storage::config(); + + PVE::Storage::check_volume_access($rpcenv, $authuser, $cfg, undef, $volid); + + my $create_args = PVE::Tools::run_with_timeout(30, sub { + my $import = PVE::Storage::get_import_metadata($cfg, $volid); + return $import->get_create_args($target); + }); + + return { + type => 'vm', # currently we only have this + 'create-args' => $create_args, + }; + }}); + 1;