From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v2 manager 12/14] api: ceph: mon: factor out mon_host regex address removal
Date: Mon, 10 May 2021 14:18:24 +0200 [thread overview]
Message-ID: <20210510121826.8543-13-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210510121826.8543-1-f.ebner@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
New in v2.
PVE/API2/Ceph/MON.pm | 52 ++++++++++++++++++++++++--------------------
1 file changed, 29 insertions(+), 23 deletions(-)
diff --git a/PVE/API2/Ceph/MON.pm b/PVE/API2/Ceph/MON.pm
index 27278bc1..e5f11c8a 100644
--- a/PVE/API2/Ceph/MON.pm
+++ b/PVE/API2/Ceph/MON.pm
@@ -127,6 +127,34 @@ my $assert_mon_can_remove = sub {
die "can't remove last monitor\n" if scalar(@$monlist) <= 1;
};
+my $remove_addr_from_mon_host = sub {
+ my ($monhost, $addr) = @_;
+
+ # various replaces to remove the ip
+ # we always match the beginning or a separator (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 (+ port)
+ $monhost =~ s/(^|[ ,;]+)\Q$addr\E(?::\d+)?(?:[ ,;]+|$)/$1/;
+
+ # ipv6 only without brackets
+ if ($addr =~ m/^\[?(.*?:.*?)\]?$/) {
+ $addr = $1;
+ $monhost =~ s/(^|[ ,;]+)\Q$addr\E(?:[ ,;]+|$)/$1/;
+ }
+
+ # remove trailing separators
+ $monhost =~ s/[ ,;]+$//;
+
+ return $monhost;
+};
+
__PACKAGE__->register_method ({
name => 'listmon',
path => '',
@@ -471,29 +499,7 @@ __PACKAGE__->register_method ({
# delete from mon_host
if (my $monhost = $cfg->{global}->{mon_host}) {
- # various replaces to remove the ip
- # we always match the beginning or a separator (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 (+ port)
- $monhost =~ s/(^|[ ,;]+)\Q$addr\E(?::\d+)?(?:[ ,;]+|$)/$1/;
-
- # ipv6 only without brackets
- if ($addr =~ m/^\[?(.*?:.*?)\]?$/) {
- $addr = $1;
- $monhost =~ s/(^|[ ,;]+)\Q$addr\E(?:[ ,;]+|$)/$1/;
- }
-
- # remove trailing separators
- $monhost =~ s/[ ,;]+$//;
-
- $cfg->{global}->{mon_host} = $monhost;
+ $cfg->{global}->{mon_host} = $remove_addr_from_mon_host->($monhost, $addr);
}
cfs_write_file('ceph.conf', $cfg);
--
2.20.1
next prev parent reply other threads:[~2021-05-10 12:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-10 12:18 [pve-devel] [PATCH-SERIES v2 common/manager] fix #2422: allow multiple Ceph public networks Fabian Ebner
2021-05-10 12:18 ` [pve-devel] [PATCH v2 common 01/14] network: is_ip_in_cidr: correctly handle the CIDR being a singleton range Fabian Ebner
2021-05-10 12:18 ` [pve-devel] [PATCH v2 common 02/14] network: is_ip_in_cidr: avoid warning when versions don't match Fabian Ebner
2021-05-10 12:18 ` [pve-devel] [PATCH v2 common 03/14] network: add canonical_ip function Fabian Ebner
2021-05-10 12:18 ` [pve-devel] [PATCH v2 common 04/14] network: add unique_ips function Fabian Ebner
2021-05-10 12:18 ` [pve-devel] [PATCH v2 manager 05/14] api: ceph: mon: split up arguments for run_command Fabian Ebner
2021-05-10 12:18 ` [pve-devel] [PATCH v2 manager 06/14] api: ceph: create mon: handle ms_bind_ipv* options more generally Fabian Ebner
2021-05-10 12:18 ` [pve-devel] [PATCH v2 manager 07/14] api: ceph: create mon: factor out monmaptool command Fabian Ebner
2021-05-10 12:18 ` [pve-devel] [PATCH v2 manager 08/14] api: ceph: create mon: explicitly add subsequent monitors to the monmap Fabian Ebner
2021-05-10 12:18 ` [pve-devel] [PATCH v2 manager 09/14] api: ceph: mon: fix handling of IPv6 addresses in find_mon_ip Fabian Ebner
2021-05-10 12:18 ` [pve-devel] [PATCH v2 manager 10/14] api: ceph: mon: add ips_from_mon_host helper Fabian Ebner
2021-05-10 12:18 ` [pve-devel] [PATCH v2 manager 11/14] api: ceph: mon: fix handling of IPv6 addresses in assert_mon_prerequisites Fabian Ebner
2021-05-10 12:18 ` Fabian Ebner [this message]
2021-05-10 12:18 ` [pve-devel] [PATCH v2 manager 13/14] api: ceph: mon: fix handling of IPv6 addresses in destroymon Fabian Ebner
2021-05-10 12:18 ` [pve-devel] [PATCH v2 manager 14/14] fix #2422: allow multiple Ceph public networks Fabian Ebner
2021-06-17 13:21 ` [pve-devel] applied-partially: [PATCH-SERIES v2 common/manager] " Thomas Lamprecht
2021-06-18 15:14 ` [pve-devel] " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210510121826.8543-13-f.ebner@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox