plugin: dir: implement import content type
in DirPlugin and not Plugin (because of cyclic dependency of Plugin -> OVF -> Storage -> Plugin otherwise) only ovf is currently supported (though ova will be shown in import listing), expects the files to not be in a subdir, and adjacent to the ovf file. listed will be all ovf/qcow2/raw/vmdk files. ovf because it can be imported, and the rest because they can be used in the 'import-from' part of qemu-server. Signed-off-by: Dominik Csapak <d.csapak@proxmox.com> Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
This commit is contained in:
committed by
Thomas Lamprecht
parent
4e97c507d2
commit
d955a46a32
@ -10,6 +10,7 @@ use IO::File;
|
||||
use POSIX;
|
||||
|
||||
use PVE::Storage::Plugin;
|
||||
use PVE::GuestImport::OVF;
|
||||
use PVE::JSONSchema qw(get_standard_option);
|
||||
|
||||
use base qw(PVE::Storage::Plugin);
|
||||
@ -22,7 +23,7 @@ sub type {
|
||||
|
||||
sub plugindata {
|
||||
return {
|
||||
content => [ { images => 1, rootdir => 1, vztmpl => 1, iso => 1, backup => 1, snippets => 1, none => 1 },
|
||||
content => [ { images => 1, rootdir => 1, vztmpl => 1, iso => 1, backup => 1, snippets => 1, none => 1, import => 1 },
|
||||
{ images => 1, rootdir => 1 }],
|
||||
format => [ { raw => 1, qcow2 => 1, vmdk => 1, subvol => 1 } , 'raw' ],
|
||||
};
|
||||
@ -247,4 +248,37 @@ sub check_config {
|
||||
return $opts;
|
||||
}
|
||||
|
||||
sub get_import_metadata {
|
||||
my ($class, $scfg, $volname, $storeid) = @_;
|
||||
|
||||
my ($vtype, $name, undef, undef, undef, undef, $fmt) = $class->parse_volname($volname);
|
||||
die "invalid content type '$vtype'\n" if $vtype ne 'import';
|
||||
die "invalid format\n" if $fmt ne 'ovf';
|
||||
|
||||
# NOTE: all types of warnings must be added to the return schema of the import-metadata API endpoint
|
||||
my $warnings = [];
|
||||
|
||||
my $path = $class->path($scfg, $volname, $storeid, undef);
|
||||
my $res = PVE::GuestImport::OVF::parse_ovf($path);
|
||||
my $disks = {};
|
||||
for my $disk ($res->{disks}->@*) {
|
||||
my $id = $disk->{disk_address};
|
||||
my $size = $disk->{virtual_size};
|
||||
my $path = $disk->{relative_path};
|
||||
$disks->{$id} = {
|
||||
volid => "$storeid:import/$path",
|
||||
defined($size) ? (size => $size) : (),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
type => 'vm',
|
||||
source => $volname,
|
||||
'create-args' => $res->{qm},
|
||||
'disks' => $disks,
|
||||
warnings => $warnings,
|
||||
net => [],
|
||||
};
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
@ -663,6 +663,8 @@ sub parse_volname {
|
||||
return ('backup', $fn);
|
||||
} elsif ($volname =~ m!^snippets/([^/]+)$!) {
|
||||
return ('snippets', $1);
|
||||
} elsif ($volname =~ m!^import/(${PVE::Storage::SAFE_CHAR_CLASS_RE}+$PVE::Storage::IMPORT_EXT_RE_1)$!) {
|
||||
return ('import', $1, undef, undef, undef, undef, $2);
|
||||
}
|
||||
|
||||
die "unable to parse directory volume name '$volname'\n";
|
||||
@ -675,6 +677,7 @@ my $vtype_subdirs = {
|
||||
vztmpl => 'template/cache',
|
||||
backup => 'dump',
|
||||
snippets => 'snippets',
|
||||
import => 'import',
|
||||
};
|
||||
|
||||
sub get_vtype_subdirs {
|
||||
@ -1269,7 +1272,7 @@ sub list_images {
|
||||
return $res;
|
||||
}
|
||||
|
||||
# list templates ($tt = <iso|vztmpl|backup|snippets>)
|
||||
# list templates ($tt = <iso|vztmpl|backup|snippets|import>)
|
||||
my $get_subdir_files = sub {
|
||||
my ($sid, $path, $tt, $vmid) = @_;
|
||||
|
||||
@ -1325,6 +1328,10 @@ my $get_subdir_files = sub {
|
||||
volid => "$sid:snippets/". basename($fn),
|
||||
format => 'snippet',
|
||||
};
|
||||
} elsif ($tt eq 'import') {
|
||||
next if $fn !~ m!/(${PVE::Storage::SAFE_CHAR_CLASS_RE}+$PVE::Storage::IMPORT_EXT_RE_1)$!i;
|
||||
|
||||
$info = { volid => "$sid:import/$1", format => "$2" };
|
||||
}
|
||||
|
||||
$info->{size} = $st->size;
|
||||
@ -1359,6 +1366,8 @@ sub list_volumes {
|
||||
$data = $get_subdir_files->($storeid, $path, 'backup', $vmid);
|
||||
} elsif ($type eq 'snippets') {
|
||||
$data = $get_subdir_files->($storeid, $path, 'snippets');
|
||||
} elsif ($type eq 'import') {
|
||||
$data = $get_subdir_files->($storeid, $path, 'import');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user