From 7ef69f338e4aa01bb9fa8f3b4a8e90165bf78ff4 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Tue, 23 Jul 2019 07:48:45 +0200 Subject: [PATCH] ceph tools: factor out frequent keyring and config init check Signed-off-by: Thomas Lamprecht --- PVE/API2/Ceph.pm | 28 ++++------------------------ PVE/API2/Ceph/FS.pm | 6 +----- PVE/Ceph/Tools.pm | 11 +++++++++++ 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm index 5a48e2d0..4e0191b1 100644 --- a/PVE/API2/Ceph.pm +++ b/PVE/API2/Ceph.pm @@ -725,12 +725,7 @@ __PACKAGE__->register_method ({ my ($param) = @_; PVE::Cluster::check_cfs_quorum(); - PVE::Ceph::Tools::check_ceph_inited(); - - my $pve_ckeyring_path = PVE::Ceph::Tools::get_config('pve_ckeyring_path'); - - die "not fully configured - missing '$pve_ckeyring_path'\n" - if ! -f $pve_ckeyring_path; + PVE::Ceph::Tools::check_ceph_configured(); my $pool = $param->{name}; my $rpcenv = PVE::RPCEnvironment::get(); @@ -786,12 +781,7 @@ __PACKAGE__->register_method ({ code => sub { my ($param) = @_; - PVE::Ceph::Tools::check_ceph_inited(); - - my $pve_ckeyring_path = PVE::Ceph::Tools::get_config('pve_ckeyring_path'); - - die "not fully configured - missing '$pve_ckeyring_path'\n" - if ! -f $pve_ckeyring_path; + PVE::Ceph::Tools::check_ceph_configured(); my $rados = PVE::RADOS->new(); @@ -825,12 +815,7 @@ __PACKAGE__->register_method ({ code => sub { my ($param) = @_; - PVE::Ceph::Tools::check_ceph_inited(); - - my $pve_ckeyring_path = PVE::Ceph::Tools::get_config('pve_ckeyring_path'); - - die "not fully configured - missing '$pve_ckeyring_path'\n" - if ! -f $pve_ckeyring_path; + PVE::Ceph::Tools::check_ceph_configured(); my $set = $param->{set} // !$param->{unset}; my $rados = PVE::RADOS->new(); @@ -868,12 +853,7 @@ __PACKAGE__->register_method ({ code => sub { my ($param) = @_; - PVE::Ceph::Tools::check_ceph_inited(); - - my $pve_ckeyring_path = PVE::Ceph::Tools::get_config('pve_ckeyring_path'); - - die "not fully configured - missing '$pve_ckeyring_path'\n" - if ! -f $pve_ckeyring_path; + PVE::Ceph::Tools::check_ceph_configured(); my $set = $param->{set} // !$param->{unset}; my $rados = PVE::RADOS->new(); diff --git a/PVE/API2/Ceph/FS.pm b/PVE/API2/Ceph/FS.pm index 1806bba0..82b5d616 100644 --- a/PVE/API2/Ceph/FS.pm +++ b/PVE/API2/Ceph/FS.pm @@ -121,11 +121,7 @@ __PACKAGE__->register_method ({ code => sub { my ($param) = @_; - PVE::Ceph::Tools::check_ceph_inited(); - - my $pve_ckeyring_path = PVE::Ceph::Tools::get_config('pve_ckeyring_path'); - die "Ceph is not fully configured - missing '$pve_ckeyring_path'\n" - if ! -f $pve_ckeyring_path; + PVE::Ceph::Tools::check_ceph_configured(); my $fs_name = $param->{name} // 'cephfs'; my $pg_num = $param->{pg_num} // 128; diff --git a/PVE/Ceph/Tools.pm b/PVE/Ceph/Tools.pm index ff00ba15..d268dc38 100644 --- a/PVE/Ceph/Tools.pm +++ b/PVE/Ceph/Tools.pm @@ -109,6 +109,17 @@ sub check_ceph_installed { return 1; } + +sub check_ceph_configured { + + check_ceph_inited(); + + die "ceph not fully configured - missing '$pve_ckeyring_path'\n" + if ! -f $pve_ckeyring_path; + + return 1; +} + sub check_ceph_inited { my ($noerr) = @_;