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)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 66A61773CF for ; Thu, 21 Oct 2021 14:51:23 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 58ADA1EDDE for ; Thu, 21 Oct 2021 14:50:53 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 7F17B1EDD0 for ; Thu, 21 Oct 2021 14:50:52 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 583EF45EC1 for ; Thu, 21 Oct 2021 14:50:52 +0200 (CEST) To: Proxmox VE development discussion References: <20211021124919.87618-1-l.stechauner@proxmox.com> From: Lorenz Stechauner Message-ID: <20d2bb27-d293-45ab-371e-fcf8ca63683a@proxmox.com> Date: Thu, 21 Oct 2021 14:50:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <20211021124919.87618-1-l.stechauner@proxmox.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-SPAM-LEVEL: Spam detection results: 0 AWL 1.518 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -2.267 Looks like a legit reply (A) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: Re: [pve-devel] [PATCH v3 storage 1/2] fix #3633: pvesm: use print_api_result 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: Thu, 21 Oct 2021 12:51:23 -0000 On 21.10.21 14:49, Lorenz Stechauner wrote: > Signed-off-by: Lorenz Stechauner > --- changes to v2: * ordering rows for pvesm {status|list} > PVE/CLI/pvesm.pm | 158 +++++++++-------------------------------------- > 1 file changed, 30 insertions(+), 128 deletions(-) > > diff --git a/PVE/CLI/pvesm.pm b/PVE/CLI/pvesm.pm > index 190de91..94847cd 100755 > --- a/PVE/CLI/pvesm.pm > +++ b/PVE/CLI/pvesm.pm > @@ -178,68 +178,6 @@ __PACKAGE__->register_method ({ > return; > }}); > > -my $print_content = sub { > - my ($list) = @_; > - > - my ($maxlenname, $maxsize) = (0, 0); > - foreach my $info (@$list) { > - my $volid = $info->{volid}; > - my $sidlen = length ($volid); > - $maxlenname = $sidlen if $sidlen > $maxlenname; > - $maxsize = $info->{size} if ($info->{size} // 0) > $maxsize; > - } > - my $sizemaxdigits = length($maxsize); > - > - my $basefmt = "%-${maxlenname}s %-7s %-9s %${sizemaxdigits}s"; > - printf "$basefmt %s\n", "Volid", "Format", "Type", "Size", "VMID"; > - > - foreach my $info (@$list) { > - next if !$info->{vmid}; > - my $volid = $info->{volid}; > - > - printf "$basefmt %d\n", $volid, $info->{format}, $info->{content}, $info->{size}, $info->{vmid}; > - } > - > - foreach my $info (sort { $a->{format} cmp $b->{format} } @$list) { > - next if $info->{vmid}; > - my $volid = $info->{volid}; > - > - printf "$basefmt\n", $volid, $info->{format}, $info->{content}, $info->{size}; > - } > -}; > - > -my $print_status = sub { > - my $res = shift; > - > - my $maxlen = 0; > - foreach my $res (@$res) { > - my $storeid = $res->{storage}; > - $maxlen = length ($storeid) if length ($storeid) > $maxlen; > - } > - $maxlen+=1; > - > - printf "%-${maxlen}s %10s %10s %15s %15s %15s %8s\n", 'Name', 'Type', > - 'Status', 'Total', 'Used', 'Available', '%'; > - > - foreach my $res (sort { $a->{storage} cmp $b->{storage} } @$res) { > - my $storeid = $res->{storage}; > - > - my $active = $res->{active} ? 'active' : 'inactive'; > - my ($per, $per_fmt) = (0, '% 7.2f%%'); > - $per = ($res->{used}*100)/$res->{total} if $res->{total} > 0; > - > - if (!$res->{enabled}) { > - $per = 'N/A'; > - $per_fmt = '% 8s'; > - $active = 'disabled'; > - } > - > - printf "%-${maxlen}s %10s %10s %15d %15d %15d $per_fmt\n", $storeid, > - $res->{type}, $active, $res->{total}/1024, $res->{used}/1024, > - $res->{avail}/1024, $per; > - } > -}; > - > __PACKAGE__->register_method ({ > name => 'export', > path => 'export', > @@ -573,14 +511,26 @@ my $print_api_result = sub { > PVE::CLIFormatter::print_api_result($data, $schema, undef, $options); > }; > > +my $print_content = sub { > + my ($data, $schema, $options) = @_; > + my $order = [qw(volid format content size used vmid ctime parent encrypted verification notes)]; > + PVE::CLIFormatter::print_api_result($data, $schema, $order, $options); > +}; > + > +my $print_status = sub { > + my ($data, $schema, $options) = @_; > + my $order = [qw(storage type active enabled shared total used avail used_fraction content)]; > + PVE::CLIFormatter::print_api_result($data, $schema, $order, $options); > +}; > + > our $cmddef = { > add => [ "PVE::API2::Storage::Config", 'create', ['type', 'storage'] ], > set => [ "PVE::API2::Storage::Config", 'update', ['storage'] ], > remove => [ "PVE::API2::Storage::Config", 'delete', ['storage'] ], > - status => [ "PVE::API2::Storage::Status", 'index', [], > - { node => $nodename }, $print_status ], > - list => [ "PVE::API2::Storage::Content", 'index', ['storage'], > - { node => $nodename }, $print_content ], > + status => [ "PVE::API2::Storage::Status", 'index', [], { node => $nodename }, > + $print_status, $PVE::RESTHandler::standard_output_options ], > + list => [ "PVE::API2::Storage::Content", 'index', ['storage'], { node => $nodename }, > + $print_content, $PVE::RESTHandler::standard_output_options ], > alloc => [ "PVE::API2::Storage::Content", 'create', ['storage', 'vmid', 'filename', 'size'], > { node => $nodename }, sub { > my $volid = shift; > @@ -589,61 +539,18 @@ our $cmddef = { > free => [ "PVE::API2::Storage::Content", 'delete', ['volume'], > { node => $nodename } ], > scan => { > - nfs => [ "PVE::API2::Storage::Scan", 'nfsscan', ['server'], { node => $nodename }, sub { > - my $res = shift; > - > - my $maxlen = 0; > - foreach my $rec (@$res) { > - my $len = length ($rec->{path}); > - $maxlen = $len if $len > $maxlen; > - } > - foreach my $rec (@$res) { > - printf "%-${maxlen}s %s\n", $rec->{path}, $rec->{options}; > - } > - }], > - cifs => [ "PVE::API2::Storage::Scan", 'cifsscan', ['server'], { node => $nodename }, sub { > - my $res = shift; > - > - my $maxlen = 0; > - foreach my $rec (@$res) { > - my $len = length ($rec->{share}); > - $maxlen = $len if $len > $maxlen; > - } > - foreach my $rec (@$res) { > - printf "%-${maxlen}s %s\n", $rec->{share}, $rec->{description}; > - } > - }], > - glusterfs => [ "PVE::API2::Storage::Scan", 'glusterfsscan', ['server'], { node => $nodename }, sub { > - my $res = shift; > - > - foreach my $rec (@$res) { > - printf "%s\n", $rec->{volname}; > - } > - }], > - iscsi => [ "PVE::API2::Storage::Scan", 'iscsiscan', ['portal'], { node => $nodename }, sub { > - my $res = shift; > - > - my $maxlen = 0; > - foreach my $rec (@$res) { > - my $len = length ($rec->{target}); > - $maxlen = $len if $len > $maxlen; > - } > - foreach my $rec (@$res) { > - printf "%-${maxlen}s %s\n", $rec->{target}, $rec->{portal}; > - } > - }], > - lvm => [ "PVE::API2::Storage::Scan", 'lvmscan', [], { node => $nodename }, sub { > - my $res = shift; > - foreach my $rec (@$res) { > - printf "$rec->{vg}\n"; > - } > - }], > - lvmthin => [ "PVE::API2::Storage::Scan", 'lvmthinscan', ['vg'], { node => $nodename }, sub { > - my $res = shift; > - foreach my $rec (@$res) { > - printf "$rec->{lv}\n"; > - } > - }], > + nfs => [ "PVE::API2::Storage::Scan", 'nfsscan', ['server'], { node => $nodename }, > + $print_api_result, $PVE::RESTHandler::standard_output_options ], > + cifs => [ "PVE::API2::Storage::Scan", 'cifsscan', ['server'], { node => $nodename }, > + $print_api_result, $PVE::RESTHandler::standard_output_options ], > + glusterfs => [ "PVE::API2::Storage::Scan", 'glusterfsscan', ['server'], { node => $nodename }, > + $print_api_result, $PVE::RESTHandler::standard_output_options ], > + iscsi => [ "PVE::API2::Storage::Scan", 'iscsiscan', ['portal'], { node => $nodename }, > + $print_api_result, $PVE::RESTHandler::standard_output_options ], > + lvm => [ "PVE::API2::Storage::Scan", 'lvmscan', [], { node => $nodename }, > + $print_api_result, $PVE::RESTHandler::standard_output_options ], > + lvmthin => [ "PVE::API2::Storage::Scan", 'lvmthinscan', ['vg'], { node => $nodename }, > + $print_api_result, $PVE::RESTHandler::standard_output_options ], > pbs => [ > "PVE::API2::Storage::Scan", > 'pbsscan', > @@ -652,13 +559,8 @@ our $cmddef = { > $print_api_result, > $PVE::RESTHandler::standard_output_options, > ], > - zfs => [ "PVE::API2::Storage::Scan", 'zfsscan', [], { node => $nodename }, sub { > - my $res = shift; > - > - foreach my $rec (@$res) { > - printf "$rec->{pool}\n"; > - } > - }], > + zfs => [ "PVE::API2::Storage::Scan", 'zfsscan', [], { node => $nodename }, > + $print_api_result, $PVE::RESTHandler::standard_output_options ], > }, > nfsscan => { alias => 'scan nfs' }, > cifsscan => { alias => 'scan cifs' },