[pve-devel] [PATCH v3 guest-common 02/22] Add foreach_unused_volume

Fabian Ebner f.ebner at proxmox.com
Thu Mar 12 13:08:12 CET 2020


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 PVE/AbstractConfig.pm | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/PVE/AbstractConfig.pm b/PVE/AbstractConfig.pm
index 6148271..5b1683b 100644
--- a/PVE/AbstractConfig.pm
+++ b/PVE/AbstractConfig.pm
@@ -419,6 +419,19 @@ sub add_unused_volume {
     return $key;
 }
 
+# Iterate over all unused volumes, calling $func for each key/value pair
+# with additional parameters @param.
+sub foreach_unused_volume {
+    my ($class, $conf, $func, @param) = @_;
+
+    foreach my $key (keys %{$conf}) {
+	if ($key =~ m/^unused\d+$/) {
+	    my $volume = $class->parse_volume($key, $conf->{$key});
+	    $func->($key, $volume, @param);
+	}
+    }
+}
+
 # Returns whether the template parameter is set in $conf.
 sub is_template {
     my ($class, $conf) = @_;
-- 
2.20.1





More information about the pve-devel mailing list