From c04392c7e00292332a7284fe06628d7b1cc4e00a Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sat, 21 Dec 2013 10:18:17 +0100 Subject: [PATCH] ceph: allow to specify network --- PVE/API2/Ceph.pm | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm index fb37c443..eabbc5cb 100644 --- a/PVE/API2/Ceph.pm +++ b/PVE/API2/Ceph.pm @@ -8,6 +8,7 @@ use POSIX qw (LONG_MAX); use Cwd qw(abs_path); use IO::Dir; use UUID; +use Net::IP; use PVE::SafeSyslog; use PVE::Tools qw(extract_param run_command file_get_contents file_read_firstline dir_glob_regex dir_glob_foreach); @@ -503,6 +504,12 @@ __PACKAGE__->register_method ({ additionalProperties => 0, properties => { node => get_standard_option('pve-node'), + network => { + description => "Use specific network for all ceph related traffic", + type => 'string', format => 'CIDR', + optional => 1, + maxLength => 128, + }, size => { description => 'Number of replicas per object', type => 'integer', @@ -563,7 +570,12 @@ __PACKAGE__->register_method ({ $cfg->{global}->{'osd pg bits'} = $param->{pg_bits}; $cfg->{global}->{'osd pgp bits'} = $param->{pg_bits}; } - + + if ($param->{network}) { + $cfg->{global}->{'public network'} = $param->{network}; + $cfg->{global}->{'cluster network'} = $param->{network}; + } + &$write_ceph_config($cfg); &$setup_pve_symlinks(); @@ -571,6 +583,24 @@ __PACKAGE__->register_method ({ return undef; }}); +my $find_node_ip = sub { + my ($cidr) = @_; + + my $config = PVE::INotify::read_file('interfaces'); + + my $net = Net::IP->new($cidr) || die Net::IP::Error() . "\n"; + + foreach my $iface (keys %$config) { + my $d = $config->{$iface}; + next if !$d->{address}; + my $a = Net::IP->new($d->{address}); + next if !$a; + return $d->{address} if $net->overlaps($a); + } + + die "unable to find local address within network '$cidr'\n"; +}; + __PACKAGE__->register_method ({ name => 'createmon', path => 'mon', @@ -622,8 +652,15 @@ __PACKAGE__->register_method ({ } die "unable to find usable monitor id\n" if !defined($monid); - my $monsection = "mon.$monid"; - my $monaddr = PVE::Cluster::remote_node_ip($param->{node}) . ":6789"; + my $monsection = "mon.$monid"; + my $ip; + if (my $pubnet = $cfg->{global}->{'public network'}) { + $ip = &$find_node_ip($pubnet); + } else { + $ip = PVE::Cluster::remote_node_ip($param->{node}); + } + + my $monaddr = "$ip:6789"; my $monname = $param->{node}; die "monitor '$monsection' already exists\n" if $cfg->{$monsection}; -- 2.39.5