[pve-devel] [PATCH v1 pve-manager 2/8] ceph: tools: update Ceph version regex

Max Carrara m.carrara at proxmox.com
Tue Apr 30 17:28:51 CEST 2024


Make the regex more maintainable declaring it as a variable, breaking it
up and commenting it by using the x flag.

Also remove the part that parses our Debian revision (e.g. -pve1) from
the version, as we do not actually include that in our Ceph builds.

The part of the regex that parses the build commit hash is made
mandatory (remove '?' after its group).

Signed-off-by: Max Carrara <m.carrara at proxmox.com>
---
 PVE/Ceph/Tools.pm | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/PVE/Ceph/Tools.pm b/PVE/Ceph/Tools.pm
index 087c4ef3..a00d23e1 100644
--- a/PVE/Ceph/Tools.pm
+++ b/PVE/Ceph/Tools.pm
@@ -68,7 +68,18 @@ sub get_local_version {
 
     return undef if !defined $ceph_version;
 
-    if ($ceph_version =~ /^ceph.*\sv?(\d+(?:\.\d+)+(?:-pve\d+)?)\s+(?:\(([a-zA-Z0-9]+)\))?/) {
+    my $re_ceph_version = qr/
+	# Skip ahead to the version, which may optionally start with 'v'
+	^ceph.*\sv?
+
+	# Parse the version X.Y, X.Y.Z, etc.
+	( \d+ (?:\.\d+)+ ) \s+
+
+	# Parse the git commit hash between parentheses
+	(?: \( ([a-zA-Z0-9]+) \) )
+    /x;
+
+    if ($ceph_version =~ /$re_ceph_version/) {
 	my ($version, $buildcommit) = ($1, $2);
 	my $subversions = [ split(/\.|-/, $version) ];
 
-- 
2.39.2





More information about the pve-devel mailing list