On 6/19/19 11:58 AM, Thomas Lamprecht wrote:
On 6/18/19 3:42 PM, Dominik Csapak wrote:
we need to remove an ip, ip:port or a ipvector from monhost
so use multiple regex search and replaces for this
this looks not really nice, but due to the strange format
of the line (e.g. ',' is a seperator inside and outside of a vector,
also ipv6 adresses may be surrounded with [] but so are vectors),
i found no better way
Signed-off-by: Dominik Csapak <d.csa...@proxmox.com>
---
PVE/API2/Ceph/MON.pm | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/PVE/API2/Ceph/MON.pm b/PVE/API2/Ceph/MON.pm
index a8ece0b4..975e1848 100644
--- a/PVE/API2/Ceph/MON.pm
+++ b/PVE/API2/Ceph/MON.pm
@@ -337,6 +337,15 @@ __PACKAGE__->register_method ({
$monstat = $rados->mon_command({ prefix => 'mon_status' });
$monlist = $monstat->{monmap}->{mons};
+ my $addr;
+ for my $mon (@$monlist) {
+ if ($mon->{name} eq $monid) {
+ $addr = $mon->{public_addr} // $mon->{addr};
+ ($addr) = $addr =~ m|^(.*):\d+/\d+$|; # extract the ip
without port/nonce
+ last;
+ }
+ }
+
$assert_mon_can_remove->($monhash, $monlist, $monid);
$rados->mon_command({ prefix => "mon remove", name => $monid, format => 'plain' });
@@ -347,6 +356,35 @@ __PACKAGE__->register_method ({
# delete section
delete $cfg->{$monsection};
+ # delete from mon_host
+ if (my $monhost = $cfg->{global}->{mon_host}) {
+ # various replaces to remove the ip
+ # we always match the beginning or a seperator (also at the
end)
+ # so we do not accidentally remove a wrong ip
+ # e.g. removing 10.0.0.1 should not remove 10.0.0.101 or
110.0.0.1
+
+ # remove vector containing this ip
+ # format is [vX:ip:port/nonce,vY:ip:port/nonce]
+ my $vectorpart_re = "v\\d+:\Q$addr\E:\\d+\\/\\d+";
+ $monhost =~ s/(^|[
,;]*)\[$vectorpart_re(?:,$vectorpart_re)*\](?:[ ,;]+|$)/$1/;
+
+ # ip only
+ $monhost =~ s/(^|[ ,;]+)\Q$addr\E(?:[ ,;]+|$)/$1/;
+ # ip + port
+ $monhost =~ s/(^|[ ,;]+)\Q$addr\E:\d+(?:[ ,;]+|$)/$1/;
why not both at once with \d*
should work, but we have to do '(:\d+)?'
+
+ # ipv6 only without brackets
+ if ($addr =~ m/^\[?(.*?:.*?)\]?$/) {
+ $addr = $1;
+ $monhost =~ s/(^|[ ,;]+)\Q$addr\E(?:[ ,;]+|$)/$1/;
+ }
+
+ # remove trailing seperators
+ $monhost =~ s/[ ,;]+$//;
not too happy about all above to be honest... but could work for now, I mean
you did not invent this "nice" format..
me neither... but the only alternative i see is to build a full
parser/writer, which is even more complicated code...
+
+ $cfg->{global}->{mon_host} = $monhost;
+ }
+
cfs_write_file('ceph.conf', $cfg);
File::Path::remove_tree($mondir);
eval { PVE::Ceph::Services::ceph_service_cmd('disable',
$monsection) };
_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel