public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH v2 manager] pveceph: change status from long JSON to ceph -s
@ 2020-12-21 10:07 Aaron Lauterer
  2020-12-21 14:25 ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 3+ messages in thread
From: Aaron Lauterer @ 2020-12-21 10:07 UTC (permalink / raw)
  To: pve-devel

Printing a lot of very detailed JSON output on the CLI is not very
useful.

Printing the `ceph -s` overview is much more suited to give an overview
of the ceph cluster status.

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
v1 -> v2:
* added check if Ceph is iniated to avoid ugly error msg
* removed eval (if the command fails, we want to see the error msg)
* code style: avoiding long lines

@thomas thx for the hint in the dev guidelines regarding long lines.
somehow I missed that until now and took the surrounding (older) code as
guideline :)


 PVE/CLI/pveceph.pm | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/PVE/CLI/pveceph.pm b/PVE/CLI/pveceph.pm
index 3d7bf2b1..de046dd0 100755
--- a/PVE/CLI/pveceph.pm
+++ b/PVE/CLI/pveceph.pm
@@ -175,6 +175,26 @@ __PACKAGE__->register_method ({
 	return undef;
     }});
 
+__PACKAGE__->register_method ({
+    name => 'status',
+    path => 'status',
+    method => 'GET',
+    description => "Get Ceph Status.",
+    parameters => {
+	additionalProperties => 0,
+    },
+    returns => { type => 'null' },
+    code => sub {
+	PVE::Ceph::Tools::check_ceph_inited();
+
+	run_command(
+	    ['ceph', '-s'],
+	    outfunc => sub { print "$_[0]\n" },
+	    errfunc => sub { print STDERR "$_[0]\n" }
+	);
+	return undef;
+    }});
+
 our $cmddef = {
     init => [ 'PVE::API2::Ceph', 'init', [], { node => $nodename } ],
     pool => {
@@ -229,11 +249,7 @@ our $cmddef = {
     stop => [ 'PVE::API2::Ceph', 'stop', [], { node => $nodename }, $upid_exit],
     install => [ __PACKAGE__, 'install', [] ],
     purge => [  __PACKAGE__, 'purge', [] ],
-    status => [ 'PVE::API2::Ceph', 'status', [], { node => $nodename }, sub {
-	my $res = shift;
-	my $json = JSON->new->allow_nonref;
-	print $json->pretty->encode($res) . "\n";
-    }],
+    status => [ __PACKAGE__, 'status', []],
 };
 
 1;
-- 
2.20.1





^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pve-devel] applied: Re: [PATCH v2 manager] pveceph: change status from long JSON to ceph -s
  2020-12-21 10:07 [pve-devel] [PATCH v2 manager] pveceph: change status from long JSON to ceph -s Aaron Lauterer
@ 2020-12-21 14:25 ` Thomas Lamprecht
  2020-12-21 14:31   ` Aaron Lauterer
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Lamprecht @ 2020-12-21 14:25 UTC (permalink / raw)
  To: Proxmox VE development discussion, Aaron Lauterer

On 21/12/2020 11:07, Aaron Lauterer wrote:
> Printing a lot of very detailed JSON output on the CLI is not very
> useful.
> 
> Printing the `ceph -s` overview is much more suited to give an overview
> of the ceph cluster status.
> 
> Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
> ---
> v1 -> v2:
> * added check if Ceph is iniated to avoid ugly error msg

good idea

> * removed eval (if the command fails, we want to see the error msg)
> * code style: avoiding long lines
> 
> @thomas thx for the hint in the dev guidelines regarding long lines.
> somehow I missed that until now and took the surrounding (older) code as
> guideline :)
> 

please also add a trailing comma to the last argument when doing all
arguments on separate lines - at least if they're a "eats all" param hash
or array, avoids the need to change multiple lines when adding or removing
an argument. We may add a more specific rule for that though.

> 
>  PVE/CLI/pveceph.pm | 26 +++++++++++++++++++++-----
>  1 file changed, 21 insertions(+), 5 deletions(-)
> 
>

applied, thanks! Added a timeout of 15s (chose by gut feeling) to the
run_command, as ceph -s hangs indefinitely if it cannot reach any monitor
(and/or other ceph service).




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pve-devel] applied: Re: [PATCH v2 manager] pveceph: change status from long JSON to ceph -s
  2020-12-21 14:25 ` [pve-devel] applied: " Thomas Lamprecht
@ 2020-12-21 14:31   ` Aaron Lauterer
  0 siblings, 0 replies; 3+ messages in thread
From: Aaron Lauterer @ 2020-12-21 14:31 UTC (permalink / raw)
  To: Thomas Lamprecht, Proxmox VE development discussion



On 12/21/20 3:25 PM, Thomas Lamprecht wrote:
> On 21/12/2020 11:07, Aaron Lauterer wrote:
>> Printing a lot of very detailed JSON output on the CLI is not very
>> useful.
>>
>> Printing the `ceph -s` overview is much more suited to give an overview
>> of the ceph cluster status.
>>
>> Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
>> ---
>> v1 -> v2:
>> * added check if Ceph is iniated to avoid ugly error msg
> 
> good idea
> 
>> * removed eval (if the command fails, we want to see the error msg)
>> * code style: avoiding long lines
>>
>> @thomas thx for the hint in the dev guidelines regarding long lines.
>> somehow I missed that until now and took the surrounding (older) code as
>> guideline :)
>>
> 
> please also add a trailing comma to the last argument when doing all
> arguments on separate lines - at least if they're a "eats all" param hash
> or array, avoids the need to change multiple lines when adding or removing
> an argument. We may add a more specific rule for that though.

ah, forgot about that :/

> 
>>
>>   PVE/CLI/pveceph.pm | 26 +++++++++++++++++++++-----
>>   1 file changed, 21 insertions(+), 5 deletions(-)
>>
>>
> 
> applied, thanks! Added a timeout of 15s (chose by gut feeling) to the
> run_command, as ceph -s hangs indefinitely if it cannot reach any monitor
> (and/or other ceph service).

thx!





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-21 14:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-21 10:07 [pve-devel] [PATCH v2 manager] pveceph: change status from long JSON to ceph -s Aaron Lauterer
2020-12-21 14:25 ` [pve-devel] applied: " Thomas Lamprecht
2020-12-21 14:31   ` Aaron Lauterer

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