X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=PVE%2FCephConfig.pm;h=83d72fce94b6aa3507b8e3ab245638ef1f431d5f;hb=ffc31266da8854be3e9063d5f44dcbd1decbe4f9;hp=31bb887d56386b8a8bc761009044d61941664966;hpb=c8a3234574c7276a86ca2eadc76785534f476982;p=pve-storage.git diff --git a/PVE/CephConfig.pm b/PVE/CephConfig.pm index 31bb887..83d72fc 100644 --- a/PVE/CephConfig.pm +++ b/PVE/CephConfig.pm @@ -65,7 +65,7 @@ sub write_ceph_config { my $cond_write_sec = sub { my $re = shift; - foreach my $section (keys %$cfg) { + foreach my $section (sort keys %$cfg) { next if $section !~ m/^$re$/; $out .= "[$section]\n"; foreach my $key (sort keys %{$cfg->{$section}}) { @@ -121,10 +121,31 @@ sub get_monaddr_list { my $config = $parse_ceph_file->($configfile); - my @monids = grep { /mon\./ && defined($config->{$_}->{'mon addr'}) } %{$config}; + my $monhostlist = {}; - return join(',', sort map { $config->{$_}->{'mon addr'} } @monids); -}; + # get all ip addresses from mon_host + my $monhosts = [ split (/[ ,;]+/, $config->{global}->{mon_host} // "") ]; + + foreach my $monhost (@$monhosts) { + $monhost =~ s/^\[?v\d\://; # remove beginning of vector + $monhost =~ s|/\d+\]?||; # remove end of vector + my $host = $get_host->($monhost); + if ($host ne "") { + $monhostlist->{$host} = 1; + } + } + + # then get all addrs from mon. sections + for my $section ( keys %$config ) { + next if $section !~ m/^mon\./; + + if (my $addr = $config->{$section}->{mon_addr}) { + $monhostlist->{$addr} = 1; + } + } + + return join(',', sort keys %$monhostlist); +} sub hostlist { my ($list_text, $separator) = @_; @@ -234,4 +255,33 @@ sub ceph_remove_keyfile { } } +my $ceph_version_parser = sub { + my $ceph_version = shift; + # FIXME this is the same as pve-manager PVE::Ceph::Tools get_local_version + if ($ceph_version =~ /^ceph.*\sv?(\d+(?:\.\d+)+(?:-pve\d+)?)\s+(?:\(([a-zA-Z0-9]+)\))?/) { + my ($version, $buildcommit) = ($1, $2); + my $subversions = [ split(/\.|-/, $version) ]; + + return ($subversions, $version, $buildcommit); + } + warn "Could not parse Ceph version: '$ceph_version'\n"; +}; + +sub local_ceph_version { + my ($cache) = @_; + + my $version_string = $cache; + if (!defined($version_string)) { + run_command('ceph --version', outfunc => sub { + $version_string = shift; + }); + } + return undef if !defined($version_string); + # subversion is an array ref. with the version parts from major to minor + # version is the filtered version string + my ($subversions, $version) = $ceph_version_parser->($version_string); + + return wantarray ? ($subversions, $version) : $version; +} + 1;