[pve-devel] [PATCH 02/13] add is_template sub

Alexandre Derumier aderumier at odiso.com
Tue Jan 29 17:13:42 CET 2013


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 at odiso.com>
---
 PVE/QemuServer.pm |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 3d7e346..afef5fb 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -4461,4 +4461,27 @@ sub template_create {
     }
 }
 
+sub is_template {
+    my ($conf) = @_;
+
+    my $baseimagecount = 0;
+    my $totalvolumecount = 0;
+
+    foreach_drive($conf, sub {
+	my ($ds, $drive) = @_;
+	return if drive_is_cdrom($drive);
+	$totalvolumecount++;
+	my $volid = $drive->{file};
+	if ($volid =~ m/(base-(\d+)-disk-(\d+)(.(raw|qcow2|vmdk))?)$/){
+	    $baseimagecount++;
+	}
+    });
+
+    return undef if $baseimagecount == 0;
+
+    return 1 if $baseimagecount == $totalvolumecount; #full template
+    return 2 if $baseimagecount < $totalvolumecount; #semi-template
+
+}
+
 1;
-- 
1.7.10.4




More information about the pve-devel mailing list