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

Alexandre Derumier aderumier at odiso.com
Mon Jan 21 10:47:57 CET 2013


return 1 if current is template
return 2 if a snapshot is a template

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 586fce8..dc0f3ec 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -4489,4 +4489,20 @@ sub template_delete {
 
 }
 
+sub is_template {
+    my ($conf, $snapname, $checkall) = @_;
+
+    return 2 if $snapname && defined($conf->{snapshots}->{$snapname}->{template});
+    return 1 if ($conf->{template} && !$snapname);
+
+    if($checkall){
+	my $snaphash = $conf->{snapshots} || {};
+	foreach my $snapname (keys %$snaphash) {
+	    return 2 if defined($snaphash->{$snapname}->{template});
+	}
+    }
+
+    return undef;
+}
+
 1;
-- 
1.7.10.4




More information about the pve-devel mailing list