]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/QemuServer.pm
set template flag earlier
[qemu-server.git] / PVE / QemuServer.pm
index e0309c3ebc162432409473478e4983b5ec8d61f3..194b678d12f1edfa5ceb5f64a319c3b6b57889d7 100644 (file)
@@ -358,6 +358,12 @@ EODESC
        typetext => '[[order=]\d+] [,up=\d+] [,down=\d+] ',
        description => "Startup and shutdown behavior. Order is a non-negative number defining the general startup order. Shutdown in done with reverse ordering. Additionally you can set the 'up' or 'down' delay in seconds, which specifies a delay to wait before the next VM is started or stopped.",
     },
+    template => {
+       optional => 1,
+       type => 'boolean',
+       description => "Enable/disable Template.",
+       default => 0,
+    },
     args => {
        optional => 1,
        type => 'string',
@@ -3622,7 +3628,13 @@ sub rescan {
            
        check_lock($conf);
 
-       my $changes = update_disksize($vmid, $conf, $volid_hash);
+       my $vm_volids = {};
+       foreach my $volid (keys %$volid_hash) {
+           my $info = $volid_hash->{$volid};
+           $vm_volids->{$volid} = $info if $info->{vmid} && $info->{vmid} == $vmid;
+       }
+
+       my $changes = update_disksize($vmid, $conf, $vm_volids);
 
        update_config_nolock($vmid, $conf, 1) if $changes;
     };
@@ -4433,7 +4445,6 @@ sub template_create {
     die "you can't convert a vm to template if vm is running vm\n" if $running;
 
     my $storecfg = PVE::Storage::config();
-    my $i = 0;
 
     foreach_drive($conf, sub {
        my ($ds, $drive) = @_;
@@ -4442,52 +4453,19 @@ sub template_create {
        return if $disk && $ds ne $disk;
 
        my $volid = $drive->{file};
-       die "volume '$volid' does not support template/clone\n" 
-           if !PVE::Storage::volume_has_feature($storecfg, 'template', $volid);
-    });
+       return if !PVE::Storage::volume_has_feature($storecfg, 'template', $volid);
 
-    foreach_drive($conf, sub {
-       my ($ds, $drive) = @_;
-
-       return if drive_is_cdrom($drive);
-       return if $disk && $ds ne $disk;
-
-       my $volid = $drive->{file};
        my $voliddst = PVE::Storage::vdisk_create_base($storecfg, $volid);
        $drive->{file} = $voliddst;
        $conf->{$ds} = PVE::QemuServer::print_drive($vmid, $drive);
        PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
-
     });
-    if($conf->{snapshots}){
-       delete $conf->{parent};
-       delete $conf->{snapshots};
-       PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
-       #fixme : do we need to delete disks snapshots ?
-    }
 }
 
 sub is_template {
     my ($conf) = @_;
 
-    my $baseimagecount = 0;
-    my $totalvolumecount = 0;
-    my $storecfg = PVE::Storage::config();
-
-    foreach_drive($conf, sub {
-       my ($ds, $drive) = @_;
-       return if drive_is_cdrom($drive);
-       $totalvolumecount++;
-       my $volid = $drive->{file};
-       if (PVE::Storage::volume_is_base($storecfg, $volid)){
-           $baseimagecount++;
-       }
-
-    });
-
-    return 0 if $baseimagecount == 0;
-    return 1 if $baseimagecount == $totalvolumecount; #full template
-    return 2 if $baseimagecount < $totalvolumecount; #semi-template
+    return 1 if defined $conf->{template} && $conf->{template} == 1;
 }
 
 1;