]> git.proxmox.com Git - pve-storage.git/commitdiff
api: add import/export format querying
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 12 May 2017 09:56:10 +0000 (11:56 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 12 May 2017 12:42:17 +0000 (14:42 +0200)
PVE/Storage.pm
PVE/Storage/Plugin.pm
PVE/Storage/ZFSPoolPlugin.pm

index 501494aa4c874cf7c6b3ec1bc19bda9371b75c53..26215f1264d98e61337f76f64ac8e36c8519547b 100755 (executable)
@@ -1485,6 +1485,37 @@ sub volume_import {
                                   $base_snapshot, $with_snapshots);
 }
 
+sub volume_export_formats {
+    my ($cfg, $volid, $snapshot, $base_snapshot, $with_snapshots) = @_;
+
+    my ($storeid, $volname) = parse_volume_id($volid, 1);
+    return if !$storeid;
+    my $scfg = storage_config($cfg, $storeid);
+    my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+    return $plugin->volume_export_formats($scfg, $storeid, $volname,
+                                          $base_snapshot, $with_snapshots);
+}
+
+sub volume_import_formats {
+    my ($cfg, $volid, $base_snapshot, $with_snapshots) = @_;
+
+    my ($storeid, $volname) = parse_volume_id($volid, 1);
+    return if !$storeid;
+    my $scfg = storage_config($cfg, $storeid);
+    my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+    return $plugin->volume_import_formats($scfg, $storeid, $volname,
+                                          $base_snapshot, $with_snapshots);
+}
+
+sub volume_transfer_formats {
+    my ($cfg, $src_volid, $dst_volid, $snapshot, $base_snapshot, $with_snapshots) = @_;
+    my @export_formats = volume_export_formats($cfg, $src_volid, $snapshot, $base_snapshot, $with_snapshots);
+    my @import_formats = volume_import_formats($cfg, $dst_volid, $base_snapshot, $with_snapshots);
+    my %import_hash = map { $_ => 1 } @import_formats;
+    my @common = grep { $import_hash{$_} } @export_formats;
+    return @common;
+}
+
 # bash completion helper
 
 sub complete_storage {
index b7ec261586c7dccd331ce6a17de6a7ccd0cc204d..4df6608a109e641c77ece903fd46bc6612d242ab 100644 (file)
@@ -894,10 +894,20 @@ sub volume_export {
     die "volume export not implemented for $class";
 }
 
+sub volume_export_formats {
+    my ($class, $scfg, $storeid, $volname, $snapshot, $base_snapshot, $with_snapshots) = @_;
+    die "volume export formats not implemented for $class";
+}
+
 # Import data from a stream, creating a new or replacing or adding to an existing volume.
 sub volume_import {
     my ($class, $scfg, $storeid, $fh, $volname, $format, $base_snapshot, $with_snapshots) = @_;
     die "volume import not implemented for $class";
 }
 
+sub volume_import_formats {
+    my ($class, $scfg, $storeid, $volname, $base_snapshot, $with_snapshots) = @_;
+    die "volume import formats not implemented for $class";
+}
+
 1;
index 72da44dc38fbbd62cc71cb4a63b0f5513047982a..bc9da23d220f66da06b50b96d0d2b1215a43fdde 100644 (file)
@@ -681,6 +681,16 @@ sub volume_export {
     return;
 }
 
+sub volume_export_formats {
+    my ($class, $scfg, $storeid, $volname, $snapshot, $base_snapshot, $with_snapshots) = @_;
+
+    my @formats = ('zfs');
+    # TODOs:
+    # push @formats, 'fies' if $volname !~ /^(?:basevol|subvol)-/;
+    # push @formats, 'raw' if !$base_snapshot && !$with_snapshots;
+    return @formats;
+}
+
 sub volume_import {
     my ($class, $scfg, $storeid, $fh, $volname, $format, $base_snapshot, $with_snapshots) = @_;
 
@@ -714,4 +724,10 @@ sub volume_import {
     return;
 }
 
+sub volume_import_formats {
+    my ($class, $scfg, $storeid, $volname, $base_snapshot, $with_snapshots) = @_;
+
+    return $class->volume_export_formats($scfg, $storeid, $volname, undef, $base_snapshot, $with_snapshots);
+}
+
 1;