X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=PVE%2FCephConfig.pm;h=31bb887d56386b8a8bc761009044d61941664966;hb=c8a3234574c7276a86ca2eadc76785534f476982;hp=aad2701be04aaf9b9f8b8d9c01a7f7769ed35e40;hpb=187df8553edd30b4a6a5cdc2da0cb3e3add34ea2;p=pve-storage.git diff --git a/PVE/CephConfig.pm b/PVE/CephConfig.pm index aad2701..31bb887 100644 --- a/PVE/CephConfig.pm +++ b/PVE/CephConfig.pm @@ -21,8 +21,9 @@ sub parse_ceph_config { my $section; foreach my $line (@lines) { - $line =~ s/[;#].*$//; + $line =~ s/#.*$//; $line =~ s/^\s+//; + $line =~ s/^;.*$//; $line =~ s/\s+$//; next if !$line; @@ -33,7 +34,10 @@ sub parse_ceph_config { } if ($line =~ m/^(.*?\S)\s*=\s*(\S.*)$/) { - $cfg->{$section}->{$1} = $2; + my ($key, $val) = ($1, $2); + # ceph treats ' ', '_' and '-' in keys the same, so lets do too + $key =~ s/[-\ ]/_/g; + $cfg->{$section}->{$key} = $val; } } @@ -96,32 +100,37 @@ my $ceph_get_key = sub { return $secret; }; +my $get_host = sub { + my ($hostport) = @_; + my ($host, $port) = PVE::Tools::parse_host_and_port($hostport); + if (!defined($host)) { + return ""; + } + $port = defined($port) ? ":$port" : ''; + $host = "[$host]" if Net::IP::ip_is_ipv6($host); + return "${host}${port}"; +}; + sub get_monaddr_list { my ($configfile) = shift; - my $server; - if (!defined($configfile)) { warn "No ceph config specified\n"; return; } my $config = $parse_ceph_file->($configfile); - @$server = sort map { $config->{$_}->{'mon addr'} } grep {/mon\./} %{$config}; - return join(',', @$server); + my @monids = grep { /mon\./ && defined($config->{$_}->{'mon addr'}) } %{$config}; + + return join(',', sort map { $config->{$_}->{'mon addr'} } @monids); }; sub hostlist { my ($list_text, $separator) = @_; my @monhostlist = PVE::Tools::split_list($list_text); - return join($separator, map { - my ($host, $port) = PVE::Tools::parse_host_and_port($_); - $port = defined($port) ? ":$port" : ''; - $host = "[$host]" if Net::IP::ip_is_ipv6($host); - "${host}${port}" - } @monhostlist); + return join($separator, map { $get_host->($_) } @monhostlist); } my $ceph_check_keyfile = sub {