]> git.proxmox.com Git - qemu-server.git/commitdiff
add is_template sub
authorAlexandre Derumier <aderumier@odiso.com>
Thu, 14 Feb 2013 10:58:50 +0000 (11:58 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 15 Feb 2013 06:51:09 +0000 (07:51 +0100)
return 1 if vm is a full template (all disks are base image)
return 2 if vm is a semi-tempalte (mix of base and non-base image)

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
PVE/QemuServer.pm

index 2202b7ac673854c86fe160746416383a43386b28..8a795252a6672a8b0595e459656720a3348fa4c0 100644 (file)
@@ -4441,4 +4441,29 @@ sub template_create {
     }
 }
 
+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 undef if $baseimagecount == 0;
+
+    return 1 if $baseimagecount == $totalvolumecount; #full template
+    return 2 if $baseimagecount < $totalvolumecount; #semi-template
+
+}
+
 1;