public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Aaron Lauterer <a.lauterer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager 4/6] api: mon: mds: osd: add safety check endpoints
Date: Fri, 18 Feb 2022 12:38:25 +0100	[thread overview]
Message-ID: <20220218113827.1415641-5-a.lauterer@proxmox.com> (raw)
In-Reply-To: <20220218113827.1415641-1-a.lauterer@proxmox.com>

for mon, mds and osd: ok-to-stop
mon: ok-to-rm
osd: safe-to-destroy

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---

I added the OSD safe-to-destroy endpoint even though I have no immediate
use for it as of now. But plan to include it in the OSD panel once I
have an idea how to do so in a sensible manner.

The main problem with safe-to-destroy is, that it only works if the OSD
is still running and by the time we enable the destroy button, the OSD
needs to be stopped.

 PVE/API2/Ceph/MDS.pm |  50 ++++++++++++++++++++++
 PVE/API2/Ceph/MON.pm | 100 +++++++++++++++++++++++++++++++++++++++++++
 PVE/API2/Ceph/OSD.pm | 100 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 250 insertions(+)

diff --git a/PVE/API2/Ceph/MDS.pm b/PVE/API2/Ceph/MDS.pm
index 1cb0b74f..2ed3cf5a 100644
--- a/PVE/API2/Ceph/MDS.pm
+++ b/PVE/API2/Ceph/MDS.pm
@@ -230,4 +230,54 @@ __PACKAGE__->register_method ({
     }
 });
 
+__PACKAGE__->register_method ({
+    name => 'oktostop',
+    path => '{name}/ok-to-stop',
+    method => 'GET',
+    description => "Check if it is ok to stop the MON",
+    proxyto => 'node',
+    protected => 1,
+    permissions => {
+	check => ['perm', '/', [ 'Sys.Modify' ]],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    name => {
+		type => 'string',
+		pattern => PVE::Ceph::Services::SERVICE_REGEX,
+		description => 'The name (ID) of the mds',
+	    },
+	},
+    },
+    returns => {
+	type => "object",
+    },
+    code => sub {
+	my ($param) = @_;
+
+	PVE::Ceph::Tools::check_ceph_inited();
+
+	my $name = $param->{name};
+	my $rados = PVE::RADOS->new();
+
+	my $result = {
+	    ok_to_stop => 0,
+	    status => '',
+	};
+
+	my $code;
+	my $status;
+	eval {
+	    ($code, $status) = $rados->mon_command({ prefix => 'mds ok-to-stop', format => 'plain', ids => [ $name ] }, 1);
+	};
+	die $@ if $@;
+
+	$result->{ok_to_stop} = $code == 0 ? 1 : 0;
+	$result->{status} = $status;
+
+	return $result;
+    }});
+
 1;
diff --git a/PVE/API2/Ceph/MON.pm b/PVE/API2/Ceph/MON.pm
index 12c9caf0..49d15f12 100644
--- a/PVE/API2/Ceph/MON.pm
+++ b/PVE/API2/Ceph/MON.pm
@@ -591,4 +591,104 @@ __PACKAGE__->register_method ({
 	return $rpcenv->fork_worker('cephdestroymon', $monsection,  $authuser, $worker);
     }});
 
+__PACKAGE__->register_method ({
+    name => 'oktostop',
+    path => '{monid}/ok-to-stop',
+    method => 'GET',
+    description => "Check if it is ok to stop the MON",
+    proxyto => 'node',
+    protected => 1,
+    permissions => {
+	check => ['perm', '/', [ 'Sys.Modify' ]],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    monid => {
+		type => 'string',
+		pattern => PVE::Ceph::Services::SERVICE_REGEX,
+		description => "The ID for the monitor",
+	    },
+	},
+    },
+    returns => {
+	type => "object",
+    },
+    code => sub {
+	my ($param) = @_;
+
+	PVE::Ceph::Tools::check_ceph_inited();
+
+	my $monid = $param->{monid};
+	my $rados = PVE::RADOS->new();
+
+	my $result = {
+	    ok_to_stop => 0,
+	    status => '',
+	};
+
+	my $code;
+	my $status;
+	eval {
+	    ($code, $status) = $rados->mon_command({ prefix => 'mon ok-to-stop', format => 'plain', ids => [ $monid ] }, 1);
+	};
+	die $@ if $@;
+
+	$result->{ok_to_stop} = $code == 0 ? 1 : 0;
+	$result->{status} = $status;
+
+	return $result;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'oktorm',
+    path => '{monid}/ok-to-rm',
+    method => 'GET',
+    description => "Check if it is ok to remove the MON",
+    proxyto => 'node',
+    protected => 1,
+    permissions => {
+	check => ['perm', '/', [ 'Sys.Modify' ]],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    monid => {
+		type => 'string',
+		pattern => PVE::Ceph::Services::SERVICE_REGEX,
+		description => "The ID for the monitor",
+	    },
+	},
+    },
+    returns => {
+	type => "object",
+    },
+    code => sub {
+	my ($param) = @_;
+
+	PVE::Ceph::Tools::check_ceph_inited();
+
+	my $monid = $param->{monid};
+	my $rados = PVE::RADOS->new();
+
+	my $result = {
+	    ok_to_rm => 0,
+	    status => '',
+	};
+
+	my $code;
+	my $status;
+	eval {
+	    ($code, $status) = $rados->mon_command({ prefix => 'mon ok-to-rm', format => 'plain', id => $monid }, 1);
+	};
+	die $@ if $@;
+
+	$result->{ok_to_rm} = $code == 0 ? 1 : 0;
+	$result->{status} = $status;
+
+	return $result;
+    }});
+
 1;
diff --git a/PVE/API2/Ceph/OSD.pm b/PVE/API2/Ceph/OSD.pm
index 26d61e3b..7a7599e2 100644
--- a/PVE/API2/Ceph/OSD.pm
+++ b/PVE/API2/Ceph/OSD.pm
@@ -825,4 +825,104 @@ __PACKAGE__->register_method ({
 	return undef;
     }});
 
+__PACKAGE__->register_method ({
+    name => 'oktostop',
+    path => '{osdid}/ok-to-stop',
+    method => 'GET',
+    description => "Check if it is ok to stop the OSD",
+    proxyto => 'node',
+    protected => 1,
+    permissions => {
+	check => ['perm', '/', [ 'Sys.Modify' ]],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    osdid => {
+		description => 'OSD ID',
+		type => 'integer',
+	    },
+	},
+    },
+    returns => {
+	type => "object",
+    },
+    code => sub {
+	my ($param) = @_;
+
+	PVE::Ceph::Tools::check_ceph_inited();
+
+	my $osdid = $param->{osdid};
+	my $rados = PVE::RADOS->new();
+	$get_osd_status->($rados, $osdid); # osd exists?
+
+	my $result = {
+	    ok_to_stop => 0,
+	    status => '',
+	};
+
+	my $code;
+	my $status;
+	eval {
+	    ($code, $status) = $rados->mon_command({ prefix => 'osd ok-to-stop', format => 'plain', ids => [ $osdid ] }, 1);
+	};
+	die $@ if $@;
+
+	$result->{ok_to_stop} = $code == 0 ? 1 : 0;
+	$result->{status} = $status;
+
+	return $result;
+    }});
+
+__PACKAGE__->register_method ({
+    name => 'safetodestroy',
+    path => '{osdid}/safe-to-destroy',
+    method => 'GET',
+    description => "Check if it is safe to destroy the OSD",
+    proxyto => 'node',
+    protected => 1,
+    permissions => {
+	check => ['perm', '/', [ 'Sys.Modify' ]],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    osdid => {
+		description => 'OSD ID',
+		type => 'integer',
+	    },
+	},
+    },
+    returns => {
+	type => "object",
+    },
+    code => sub {
+	my ($param) = @_;
+
+	PVE::Ceph::Tools::check_ceph_inited();
+
+	my $osdid = $param->{osdid};
+	my $rados = PVE::RADOS->new();
+	$get_osd_status->($rados, $osdid); # osd exists?
+
+	my $result = {
+	    safe_to_destroy => 0,
+	    status => '',
+	};
+
+	my $code;
+	my $status;
+	eval {
+	    ($code, $status) = $rados->mon_command({ prefix => 'osd safe-to-destroy', format => 'plain', ids => [ $osdid ] }, 1);
+	};
+	die $@ if $@;
+
+	$result->{safe_to_destroy} = $code == 0 ? 1 : 0;
+	$result->{status} = $status;
+
+	return $result;
+    }});
+
 1;
-- 
2.30.2





  parent reply	other threads:[~2022-02-18 11:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-18 11:38 [pve-devel] [PATCH librados2-perl manager 0/6] Add Ceph safety checks Aaron Lauterer
2022-02-18 11:38 ` [pve-devel] [PATCH librados2-perl 1/6] mon_command: free outs buffer Aaron Lauterer
2022-02-21 15:35   ` Thomas Lamprecht
2022-02-18 11:38 ` [pve-devel] [PATCH librados2-perl 2/6] mon_command: optionally ignore errors and return hashmap Aaron Lauterer
2022-02-21 15:44   ` Thomas Lamprecht
2022-02-22 12:42     ` Aaron Lauterer
2022-02-18 11:38 ` [pve-devel] [PATCH manager 3/6] api: osd: force mon_command to scalar context Aaron Lauterer
2022-02-18 11:38 ` Aaron Lauterer [this message]
2022-02-22  8:44   ` [pve-devel] [PATCH manager 4/6] api: mon: mds: osd: add safety check endpoints Thomas Lamprecht
2022-03-14 16:49     ` Aaron Lauterer
2022-03-14 17:02       ` Thomas Lamprecht
2022-02-18 11:38 ` [pve-devel] [PATCH manager 5/6] ui: osd: warn if removal could be problematic Aaron Lauterer
2022-02-24 12:46   ` Thomas Lamprecht
2022-02-18 11:38 ` [pve-devel] [PATCH manager 6/6] ui: osd: mon: mds: warn if stop/destroy actions are problematic Aaron Lauterer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220218113827.1415641-5-a.lauterer@proxmox.com \
    --to=a.lauterer@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal