From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 6265E620BC for ; Fri, 18 Dec 2020 17:38:50 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 57204B9F4 for ; Fri, 18 Dec 2020 17:38:50 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id B724EB9E4 for ; Fri, 18 Dec 2020 17:38:48 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 7DD5845385 for ; Fri, 18 Dec 2020 17:38:48 +0100 (CET) To: Proxmox VE development discussion , Aaron Lauterer References: <20201218160016.32301-1-a.lauterer@proxmox.com> From: Thomas Lamprecht Message-ID: <2bbe1229-fc2c-bb8e-1883-256d34b53579@proxmox.com> Date: Fri, 18 Dec 2020 17:38:46 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Thunderbird/84.0 MIME-Version: 1.0 In-Reply-To: <20201218160016.32301-1-a.lauterer@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.065 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.001 Looks like a legit reply (A) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox.com, pveceph.pm] Subject: Re: [pve-devel] [PATCH manager] pveceph: change status from long JSON to ceph -s X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Dec 2020 16:38:50 -0000 On 18/12/2020 17:00, 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 > --- > > @Thomas: I hope this is what you hand in mind when we did discuss this > off list. > yeah, this looks fine in general, a code style nit and a comment/questions about the use of eval below. > PVE/CLI/pveceph.pm | 20 +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) > > diff --git a/PVE/CLI/pveceph.pm b/PVE/CLI/pveceph.pm > index 3d7bf2b1..e12a9338 100755 > --- a/PVE/CLI/pveceph.pm > +++ b/PVE/CLI/pveceph.pm > @@ -175,6 +175,20 @@ __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 { > + eval { run_command(['ceph', '-s'], outfunc => sub { print "$_[0]\n" }, errfunc => sub { print STDERR "$_[0]\n" }) }; is the eval really required? silencing execution errors may not be ideal, I'd either drop it completely or if deemed as required do a `warn $@ if $@;` And this is a bit long for a single line, we adapted rules from perl to be closer to the ones from rust, see 80 as soft-limit (i.e., not good if you reach that (branch) indentation, but totally fine for messages or improved readability) and 100 as hard one. https://pve.proxmox.com/wiki/Perl_Style_Guide#Breaking_long_lines_and_strings So rather do: run_command( [ceph', '-s'], outfunc => sub { print "$_[0]\n" }, errfunc => sub { print STDERR "$_[0]\n" }, ); (with and without eval) > + return undef; > + }}); > + > our $cmddef = { > init => [ 'PVE::API2::Ceph', 'init', [], { node => $nodename } ], > pool => { > @@ -229,11 +243,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; >