my $section;
foreach my $line (@lines) {
- $line =~ s/[;#].*$//;
+ $line =~ s/#.*$//;
$line =~ s/^\s+//;
+ $line =~ s/^;.*$//;
$line =~ s/\s+$//;
next if !$line;
}
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;
}
}
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 {