ceph: refactor broadcast_ceph_services and get_cluster_service

and use the broadcast when a service is added/removed
we will use 'get_cluster_service' in the future when we generate a list
of services of a specific type

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2019-06-04 14:47:42 +02:00 committed by Thomas Lamprecht
parent 74628668d7
commit 4e76dbd7b3
4 changed files with 42 additions and 15 deletions

View File

@ -276,6 +276,7 @@ __PACKAGE__->register_method ({
my $rados = PVE::RADOS->new(timeout => PVE::Ceph::Tools::get_config('long_rados_timeout')); my $rados = PVE::RADOS->new(timeout => PVE::Ceph::Tools::get_config('long_rados_timeout'));
PVE::Ceph::Services::create_mgr($monid, $rados); PVE::Ceph::Services::create_mgr($monid, $rados);
} }
PVE::Ceph::Services::broadcast_ceph_services();
}; };
return $rpcenv->fork_worker('cephcreatemon', $monsection, $authuser, $worker); return $rpcenv->fork_worker('cephcreatemon', $monsection, $authuser, $worker);
@ -357,6 +358,7 @@ __PACKAGE__->register_method ({
eval { PVE::Ceph::Services::destroy_mgr($monid) }; eval { PVE::Ceph::Services::destroy_mgr($monid) };
warn $@ if $@; warn $@ if $@;
} }
PVE::Ceph::Services::broadcast_ceph_services();
}; };
return $rpcenv->fork_worker('cephdestroymon', $monsection, $authuser, $worker); return $rpcenv->fork_worker('cephdestroymon', $monsection, $authuser, $worker);

View File

@ -652,13 +652,11 @@ __PACKAGE__->register_method ({
}; };
for my $type ( qw(mon mgr mds) ) { for my $type ( qw(mon mgr mds) ) {
my $typedata = PVE::Cluster::get_node_kv("ceph-$type"); my $typedata = PVE::Ceph::Services::get_cluster_service($type);
my $data = {}; my $data = {};
for my $host (sort keys %$typedata) { for my $host (sort keys %$typedata) {
my $d = eval { decode_json($typedata->{$host}) }; for my $service (sort keys %{$typedata->{$host}}) {
for my $service (sort keys %$d) { $data->{"$service\@$host"} = $typedata->{$host}->{$service};
$d->{hostname} = $host;
$data->{"$service\@$host"} = $d->{$service};
} }
} }

View File

@ -4,9 +4,11 @@ use strict;
use warnings; use warnings;
use PVE::Ceph::Tools; use PVE::Ceph::Tools;
use PVE::Cluster;
use PVE::Tools qw(run_command); use PVE::Tools qw(run_command);
use PVE::RADOS; use PVE::RADOS;
use JSON;
use File::Path; use File::Path;
# checks /etc/systemd/system/ceph-* to list all services, even if not running # checks /etc/systemd/system/ceph-* to list all services, even if not running
@ -34,6 +36,28 @@ sub get_local_services {
return $res; return $res;
} }
sub broadcast_ceph_services {
my $services = get_local_services();
for my $type (keys %$services) {
my $data = encode_json($services->{$type});
PVE::Cluster::broadcast_node_kv("ceph-$type", $data);
}
}
sub get_cluster_service {
my ($type) = @_;
PVE::Cluster::cfs_update();
my $raw = PVE::Cluster::get_node_kv("ceph-$type");
my $res = {};
for my $host (keys %$raw) {
$res->{$host} = eval { decode_json($raw->{$host}) };
}
return $res;
}
sub ceph_service_cmd { sub ceph_service_cmd {
my ($action, $service) = @_; my ($action, $service) = @_;
@ -174,6 +198,8 @@ sub create_mds {
print "starting service 'ceph-mds\@$id.service'\n"; print "starting service 'ceph-mds\@$id.service'\n";
ceph_service_cmd('start', $service_name); ceph_service_cmd('start', $service_name);
broadcast_ceph_services();
return undef; return undef;
}; };
@ -208,6 +234,8 @@ sub destroy_mds {
format => 'plain' format => 'plain'
}); });
broadcast_ceph_services();
return undef; return undef;
}; };
@ -244,6 +272,10 @@ sub create_mgr {
ceph_service_cmd('enable', $mgrname); ceph_service_cmd('enable', $mgrname);
print "starting service 'ceph-mgr\@$id.service'\n"; print "starting service 'ceph-mgr\@$id.service'\n";
ceph_service_cmd('start', $mgrname); ceph_service_cmd('start', $mgrname);
broadcast_ceph_services();
return undef;
} }
sub destroy_mgr { sub destroy_mgr {
@ -263,6 +295,10 @@ sub destroy_mgr {
print "removing manager directory '$mgrdir'\n"; print "removing manager directory '$mgrdir'\n";
File::Path::remove_tree($mgrdir); File::Path::remove_tree($mgrdir);
broadcast_ceph_services();
return undef;
} }
1; 1;

View File

@ -449,15 +449,6 @@ sub rotate_authkeys {
PVE::AccessControl::rotate_authkey() if !PVE::AccessControl::check_authkey(1); PVE::AccessControl::rotate_authkey() if !PVE::AccessControl::check_authkey(1);
} }
sub update_ceph_services {
my $services = PVE::Ceph::Services::get_local_services();
for my $type (keys %$services) {
my $data = encode_json($services->{$type});
PVE::Cluster::broadcast_node_kv("ceph-$type", $data);
}
}
sub update_ceph_version { sub update_ceph_version {
my ($version) = PVE::Ceph::Tools::get_local_version(1); my ($version) = PVE::Ceph::Tools::get_local_version(1);
@ -527,7 +518,7 @@ sub update_status {
eval { eval {
return if !PVE::Ceph::Tools::check_ceph_inited(1); # "return" from eval return if !PVE::Ceph::Tools::check_ceph_inited(1); # "return" from eval
update_ceph_services(); PVE::Ceph::Services::broadcast_ceph_services();
update_ceph_version(); update_ceph_version();
}; };
$err = $@; $err = $@;