[pve-devel] [PATCH storage 1/2] add ceph version helpers

Fabian Grünbichler f.gruenbichler at proxmox.com
Tue Jun 7 08:45:42 CEST 2016


---
Note: this could be used in CephTools / pveceph as well if necessary

 PVE/Storage/RBDPlugin.pm | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
index 967ee04..2b4ff9c 100644
--- a/PVE/Storage/RBDPlugin.pm
+++ b/PVE/Storage/RBDPlugin.pm
@@ -79,6 +79,36 @@ my $rados_cmd = sub {
     return $cmd;
 };
 
+my $ceph_version_parser = sub {
+	my $line = shift;
+	if ($line =~ m/^ceph version ((\d+)\.(\d+)\.(\d+))(?: \([a-fA-F0-9]+\))?$/) {
+	    return ($2, $3, $4, $1);
+	} else {
+	    warn "Could not parse Ceph version: '$line'\n";
+	}
+};
+
+sub ceph_version {
+    my ($cache) = @_;
+
+    my $version_string = $cache;
+
+    my $major;
+    my $minor;
+    my $bugfix;
+
+    if (defined($version_string)) {
+	($major, $minor, $bugfix, $version_string) = &$version_parser($version_string);
+    } else {
+	run_command('ceph version', outfunc => sub {
+	    my $line = shift;
+	    ($major, $minor, $bugfix, $version_string) = &$version_parser($line);
+	});
+    }
+    return undef if !defined($version_string);
+    return wantarray ? ($major, $minor, $bugfix, $version_string) : $version_string;
+}
+
 sub run_rbd_command {
     my ($cmd, %args) = @_;
 
-- 
2.1.4




More information about the pve-devel mailing list