[pve-devel] [PATCH manager 06/14] ceph: mon create: detect pubnet via config database

Dominik Csapak d.csapak at proxmox.com
Tue Jun 18 15:42:50 CEST 2019


if we already have a monitor, we can try to get the public_network via
the ceph configuration database

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/API2/Ceph/MON.pm | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/PVE/API2/Ceph/MON.pm b/PVE/API2/Ceph/MON.pm
index c7de3624..44110bd5 100644
--- a/PVE/API2/Ceph/MON.pm
+++ b/PVE/API2/Ceph/MON.pm
@@ -19,7 +19,17 @@ use PVE::Tools qw(run_command file_set_contents);
 use base qw(PVE::RESTHandler);
 
 my $find_mon_ip = sub {
-    my ($pubnet, $node, $overwrite_ip) = @_;
+    my ($cfg, $rados, $node, $overwrite_ip) = @_;
+
+    my $pubnet;
+    if ($rados) {
+	$pubnet = $rados->mon_command({ prefix => "config get" , who => "mon.",
+		key => "public_network", format => 'plain' });
+	# if not defined in the db, the result is empty, it is also always
+	# followed by a newline
+	($pubnet) = $pubnet =~ m/^(\S+)$/;
+    }
+    $pubnet //= $cfg->{global}->{public_network};
 
     if (!$pubnet) {
 	return $overwrite_ip // PVE::Cluster::remote_node_ip($node);
@@ -152,6 +162,7 @@ __PACKAGE__->register_method ({
 	my $authuser = $rpcenv->get_user();
 
 	my $cfg = cfs_read_file('ceph.conf');
+	my $rados = eval { PVE::RADOS->new() }; # try a rados connection, fails for first monitor
 
 	my $moncount = 0;
 	my $monaddrhash = {};
@@ -170,8 +181,7 @@ __PACKAGE__->register_method ({
 	my $monid = $param->{monid} // $param->{node};
 
 	my $monsection = "mon.$monid";
-	my $pubnet = $cfg->{global}->{'public network'};
-	my $ip = $find_mon_ip->($pubnet, $param->{node}, $param->{'mon-address'});
+	my $ip = $find_mon_ip->($cfg, $rados, $param->{node}, $param->{'mon-address'});
 
 	my $monaddr = Net::IP::ip_is_ipv6($ip) ? "[$ip]:6789" : "$ip:6789";
 	my $monname = $param->{node};
-- 
2.11.0





More information about the pve-devel mailing list