[pve-devel] [PATCH manager 1/7] ceph: use cfs_read/write_file for ceph.conf
Dominik Csapak
d.csapak at proxmox.com
Wed Dec 19 11:24:41 CET 2018
The parser is now registered, and ceph.conf is a tracked file in pmxcfs.
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
PVE/API2/Ceph.pm | 24 ++++++++++---------
PVE/API2/Ceph/MDS.pm | 15 ++++++------
PVE/CephTools.pm | 65 ----------------------------------------------------
3 files changed, 21 insertions(+), 83 deletions(-)
diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index 5a52350f..8d181825 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -7,6 +7,8 @@ use Cwd qw(abs_path);
use IO::File;
use PVE::CephTools;
+use PVE::CephConfig;
+use PVE::Cluster qw(cfs_read_file cfs_write_file);
use PVE::Diskmanage;
use PVE::Exception qw(raise_param_exc);
use PVE::JSONSchema qw(get_standard_option);
@@ -536,7 +538,7 @@ use Net::IP;
use UUID;
use PVE::CephTools;
-use PVE::Cluster;
+use PVE::Cluster qw(cfs_read_file cfs_write_file);
use PVE::JSONSchema qw(get_standard_option);
use PVE::Network;
use PVE::RADOS;
@@ -771,7 +773,7 @@ __PACKAGE__->register_method ({
my $res = [];
- my $cfg = PVE::CephTools::parse_ceph_config();
+ my $cfg = cfs_read_file('ceph.conf');
my $monhash = {};
foreach my $section (keys %$cfg) {
@@ -884,7 +886,7 @@ __PACKAGE__->register_method ({
}
# simply load old config if it already exists
- my $cfg = PVE::CephTools::parse_ceph_config();
+ my $cfg = cfs_read_file('ceph.conf');
if (!$cfg->{global}) {
@@ -929,7 +931,7 @@ __PACKAGE__->register_method ({
$cfg->{global}->{'cluster network'} = $param->{'cluster-network'};
}
- PVE::CephTools::write_ceph_config($cfg);
+ cfs_write_file('ceph.conf', $cfg);
PVE::CephTools::setup_pve_symlinks();
@@ -1067,7 +1069,7 @@ __PACKAGE__->register_method ({
my $authuser = $rpcenv->get_user();
- my $cfg = PVE::CephTools::parse_ceph_config();
+ my $cfg = cfs_read_file('ceph.conf');
my $moncount = 0;
@@ -1158,7 +1160,7 @@ __PACKAGE__->register_method ({
'mon addr' => $monaddr,
};
- PVE::CephTools::write_ceph_config($cfg);
+ cfs_write_file('ceph.conf', $cfg);
my $create_keys_pid = fork();
if (!defined($create_keys_pid)) {
@@ -1223,7 +1225,7 @@ __PACKAGE__->register_method ({
PVE::CephTools::check_ceph_inited();
- my $cfg = PVE::CephTools::parse_ceph_config();
+ my $cfg = cfs_read_file('ceph.conf');
my $monid = $param->{monid};
my $monsection = "mon.$monid";
@@ -1254,7 +1256,7 @@ __PACKAGE__->register_method ({
warn $@ if $@;
delete $cfg->{$monsection};
- PVE::CephTools::write_ceph_config($cfg);
+ cfs_write_file('ceph.conf', $cfg);
File::Path::remove_tree($mondir);
# remove manager
@@ -1389,7 +1391,7 @@ __PACKAGE__->register_method ({
PVE::CephTools::check_ceph_inited();
- my $cfg = PVE::CephTools::parse_ceph_config();
+ my $cfg = cfs_read_file('ceph.conf');
scalar(keys %$cfg) || die "no configuration\n";
my $worker = sub {
@@ -1440,7 +1442,7 @@ __PACKAGE__->register_method ({
PVE::CephTools::check_ceph_inited();
- my $cfg = PVE::CephTools::parse_ceph_config();
+ my $cfg = cfs_read_file('ceph.conf');
scalar(keys %$cfg) || die "no configuration\n";
my $worker = sub {
@@ -1491,7 +1493,7 @@ __PACKAGE__->register_method ({
PVE::CephTools::check_ceph_inited();
- my $cfg = PVE::CephTools::parse_ceph_config();
+ my $cfg = cfs_read_file('ceph.conf');
scalar(keys %$cfg) || die "no configuration\n";
my $worker = sub {
diff --git a/PVE/API2/Ceph/MDS.pm b/PVE/API2/Ceph/MDS.pm
index dff28405..e8e6be36 100644
--- a/PVE/API2/Ceph/MDS.pm
+++ b/PVE/API2/Ceph/MDS.pm
@@ -4,6 +4,7 @@ use strict;
use warnings;
use PVE::CephTools;
+use PVE::Cluster qw(cfs_read_file cfs_write_file);
use PVE::INotify;
use PVE::JSONSchema qw(get_standard_option);
use PVE::RADOS;
@@ -68,7 +69,7 @@ __PACKAGE__->register_method ({
my $res = [];
- my $cfg = PVE::CephTools::parse_ceph_config();
+ my $cfg = cfs_read_file('ceph.conf');
my $mds_hash = {};
@@ -149,7 +150,7 @@ __PACKAGE__->register_method ({
my $timeout = PVE::CephTools::get_config('long_rados_timeout');
my $rados = PVE::RADOS->new(timeout => $timeout);
- my $cfg = PVE::CephTools::parse_ceph_config();
+ my $cfg = cfs_read_file('ceph.conf');
my $section = "mds.$mds_id";
@@ -171,7 +172,7 @@ __PACKAGE__->register_method ({
$cfg->{$section}->{"mds standby replay"} = 'true';
}
- PVE::CephTools::write_ceph_config($cfg);
+ cfs_write_file('ceph.conf', $cfg);
eval { PVE::CephTools::create_mds($mds_id, $rados) };
if (my $err = $@) {
@@ -179,9 +180,9 @@ __PACKAGE__->register_method ({
# wrote it at this point. Do not auto remove the service, could
# do real harm for previously manual setup MDS
warn "Encountered error, remove '$section' from ceph.conf\n";
- $cfg = PVE::CephTools::parse_ceph_config();
+ my $cfg = cfs_read_file('ceph.conf');
delete $cfg->{$section};
- PVE::CephTools::write_ceph_config($cfg);
+ cfs_write_file('ceph.conf', $cfg);
die "$err\n";
}
@@ -228,11 +229,11 @@ __PACKAGE__->register_method ({
my $timeout = PVE::CephTools::get_config('long_rados_timeout');
my $rados = PVE::RADOS->new(timeout => $timeout);
- my $cfg = PVE::CephTools::parse_ceph_config();
+ my $cfg = cfs_read_file('ceph.conf');
if (defined($cfg->{"mds.$mds_id"})) {
delete $cfg->{"mds.$mds_id"};
- PVE::CephTools::write_ceph_config($cfg);
+ cfs_write_file('ceph.conf', $cfg);
}
PVE::CephTools::destroy_mds($mds_id, $rados);
diff --git a/PVE/CephTools.pm b/PVE/CephTools.pm
index c30369fa..c0ecd6f5 100644
--- a/PVE/CephTools.pm
+++ b/PVE/CephTools.pm
@@ -122,71 +122,6 @@ sub check_ceph_enabled {
return 1;
}
-sub parse_ceph_config {
- my ($filename) = @_;
-
- $filename = $pve_ceph_cfgpath if !$filename;
-
- my $cfg = {};
-
- return $cfg if ! -f $filename;
-
- my $fh = IO::File->new($filename, "r") ||
- die "unable to open '$filename' - $!\n";
-
- my $section;
-
- while (defined(my $line = <$fh>)) {
- $line =~ s/[;#].*$//;
- $line =~ s/^\s+//;
- $line =~ s/\s+$//;
- next if !$line;
-
- $section = $1 if $line =~ m/^\[(\S+)\]$/;
- if (!$section) {
- warn "no section - skip: $line\n";
- next;
- }
-
- if ($line =~ m/^(.*?\S)\s*=\s*(\S.*)$/) {
- $cfg->{$section}->{$1} = $2;
- }
-
- }
-
- return $cfg;
-}
-
-sub write_ceph_config {
- my ($cfg) = @_;
-
- my $out = '';
-
- my $cond_write_sec = sub {
- my $re = shift;
-
- foreach my $section (keys %$cfg) {
- next if $section !~ m/^$re$/;
- $out .= "[$section]\n";
- foreach my $key (sort keys %{$cfg->{$section}}) {
- $out .= "\t $key = $cfg->{$section}->{$key}\n";
- }
- $out .= "\n";
- }
- };
-
- &$cond_write_sec('global');
- &$cond_write_sec('client');
- &$cond_write_sec('mds');
- &$cond_write_sec('mds\..*');
- &$cond_write_sec('mon');
- &$cond_write_sec('osd');
- &$cond_write_sec('mon\..*');
- &$cond_write_sec('osd\..*');
-
- PVE::Tools::file_set_contents($pve_ceph_cfgpath, $out);
-}
-
sub create_pool {
my ($pool, $param, $rados) = @_;
--
2.11.0
More information about the pve-devel
mailing list