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

Alexandre Derumier aderumier at odiso.com
Tue Dec 18 10:14:51 CET 2012


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 f7ea5ce..b0511fb 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -4431,4 +4431,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