[pve-devel] [PATCH manager 03/20] ceph: refactor broadcast_ceph_services and get_cluster_service
Dominik Csapak
d.csapak at proxmox.com
Tue Jun 4 14:47:42 CEST 2019
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 at proxmox.com>
---
PVE/API2/Ceph/MON.pm | 2 ++
PVE/API2/Cluster.pm | 8 +++-----
PVE/Ceph/Services.pm | 36 ++++++++++++++++++++++++++++++++++++
PVE/Service/pvestatd.pm | 11 +----------
4 files changed, 42 insertions(+), 15 deletions(-)
diff --git a/PVE/API2/Ceph/MON.pm b/PVE/API2/Ceph/MON.pm
index fb81cced..17660039 100644
--- a/PVE/API2/Ceph/MON.pm
+++ b/PVE/API2/Ceph/MON.pm
@@ -276,6 +276,7 @@ __PACKAGE__->register_method ({
my $rados = PVE::RADOS->new(timeout => PVE::Ceph::Tools::get_config('long_rados_timeout'));
PVE::Ceph::Services::create_mgr($monid, $rados);
}
+ PVE::Ceph::Services::broadcast_ceph_services();
};
return $rpcenv->fork_worker('cephcreatemon', $monsection, $authuser, $worker);
@@ -357,6 +358,7 @@ __PACKAGE__->register_method ({
eval { PVE::Ceph::Services::destroy_mgr($monid) };
warn $@ if $@;
}
+ PVE::Ceph::Services::broadcast_ceph_services();
};
return $rpcenv->fork_worker('cephdestroymon', $monsection, $authuser, $worker);
diff --git a/PVE/API2/Cluster.pm b/PVE/API2/Cluster.pm
index fb517ca4..bfdd9ad1 100644
--- a/PVE/API2/Cluster.pm
+++ b/PVE/API2/Cluster.pm
@@ -652,13 +652,11 @@ __PACKAGE__->register_method ({
};
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 = {};
for my $host (sort keys %$typedata) {
- my $d = eval { decode_json($typedata->{$host}) };
- for my $service (sort keys %$d) {
- $d->{hostname} = $host;
- $data->{"$service\@$host"} = $d->{$service};
+ for my $service (sort keys %{$typedata->{$host}}) {
+ $data->{"$service\@$host"} = $typedata->{$host}->{$service};
}
}
diff --git a/PVE/Ceph/Services.pm b/PVE/Ceph/Services.pm
index 3206e323..37621652 100644
--- a/PVE/Ceph/Services.pm
+++ b/PVE/Ceph/Services.pm
@@ -4,9 +4,11 @@ use strict;
use warnings;
use PVE::Ceph::Tools;
+use PVE::Cluster;
use PVE::Tools qw(run_command);
use PVE::RADOS;
+use JSON;
use File::Path;
# checks /etc/systemd/system/ceph-* to list all services, even if not running
@@ -34,6 +36,28 @@ sub get_local_services {
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 {
my ($action, $service) = @_;
@@ -174,6 +198,8 @@ sub create_mds {
print "starting service 'ceph-mds\@$id.service'\n";
ceph_service_cmd('start', $service_name);
+ broadcast_ceph_services();
+
return undef;
};
@@ -208,6 +234,8 @@ sub destroy_mds {
format => 'plain'
});
+ broadcast_ceph_services();
+
return undef;
};
@@ -244,6 +272,10 @@ sub create_mgr {
ceph_service_cmd('enable', $mgrname);
print "starting service 'ceph-mgr\@$id.service'\n";
ceph_service_cmd('start', $mgrname);
+
+ broadcast_ceph_services();
+
+ return undef;
}
sub destroy_mgr {
@@ -263,6 +295,10 @@ sub destroy_mgr {
print "removing manager directory '$mgrdir'\n";
File::Path::remove_tree($mgrdir);
+
+ broadcast_ceph_services();
+
+ return undef;
}
1;
diff --git a/PVE/Service/pvestatd.pm b/PVE/Service/pvestatd.pm
index acc42fa1..e138b2e8 100755
--- a/PVE/Service/pvestatd.pm
+++ b/PVE/Service/pvestatd.pm
@@ -449,15 +449,6 @@ sub rotate_authkeys {
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 {
my ($version) = PVE::Ceph::Tools::get_local_version(1);
@@ -527,7 +518,7 @@ sub update_status {
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();
};
$err = $@;
--
2.11.0
More information about the pve-devel
mailing list