[pve-devel] [PATCH v3 container 3/5] Rely on template_create to check whether creating a template is possible

Fabian Ebner f.ebner at proxmox.com
Mon Mar 23 12:18:52 CET 2020


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 src/PVE/API2/LXC.pm | 29 ++---------------------------
 1 file changed, 2 insertions(+), 27 deletions(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index ddf417b..c724118 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -440,13 +440,8 @@ __PACKAGE__->register_method({
 		# If the template flag was set, we try to convert again to template after restore
 		if ($was_template) {
 		    print STDERR "Convert restored container to template...\n";
-		    if (my $err = check_storage_supports_templates($conf)) {
-			warn $err;
-			warn "Leave restored backup as container instead of converting to template.\n"
-		    } else {
-			PVE::LXC::template_create($vmid, $conf);
-			$conf->{template} = 1;
-		    }
+		    PVE::LXC::template_create($vmid, $conf);
+		    $conf->{template} = 1;
 		}
 		PVE::LXC::Config->write_config($vmid, $conf);
 	    };
@@ -468,22 +463,6 @@ __PACKAGE__->register_method({
 	return $rpcenv->fork_worker($workername, $vmid, $authuser, $realcmd);
     }});
 
-sub check_storage_supports_templates {
-    my ($conf) = @_;
-
-    my $scfg = PVE::Storage::config();
-    eval {
-	PVE::LXC::Config->foreach_mountpoint($conf, sub {
-	    my ($ms, $mp) = @_;
-
-	    my ($sid) = PVE::Storage::parse_volume_id($mp->{volume}, 0);
-	    die "Warning: Directory storage '$sid' does not support container templates!\n"
-		if $scfg->{ids}->{$sid}->{path};
-	});
-    };
-    return $@
-}
-
 __PACKAGE__->register_method({
     name => 'vmdiridx',
     path => '{vmid}',
@@ -1238,10 +1217,6 @@ __PACKAGE__->register_method({
 	    die "you can't convert a CT to template if the CT is running\n"
 		if PVE::LXC::check_running($vmid);
 
-	    if (my $err = check_storage_supports_templates($conf)) {
-		die $err;
-	    }
-
 	    my $realcmd = sub {
 		PVE::LXC::template_create($vmid, $conf);
 
-- 
2.20.1





More information about the pve-devel mailing list