[pve-devel] [PATCH 02/13] add is_template sub
Alexandre Derumier
aderumier at odiso.com
Thu Feb 14 11:58:50 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 | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 85bba1c..f48d859 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -4444,4 +4444,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;
--
1.7.10.4
More information about the pve-devel
mailing list