From 7aeda03306e9acfc467bfc821f3f730171487d70 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabian=20Gr=C3=BCnbichler?= Date: Tue, 7 Jun 2016 08:45:42 +0200 Subject: [PATCH] add ceph version helpers --- 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.39.2