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 3C6ED6D190 for ; Mon, 27 Sep 2021 09:09:31 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 31C291E347 for ; Mon, 27 Sep 2021 09:09:31 +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 2BE391E33E for ; Mon, 27 Sep 2021 09:09:30 +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 EE829445BD for ; Mon, 27 Sep 2021 09:09:29 +0200 (CEST) From: Lorenz Stechauner To: pve-devel@lists.proxmox.com Date: Mon, 27 Sep 2021 09:09:16 +0200 Message-Id: <20210927070917.1504165-1-l.stechauner@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.417 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH storage 1/2] pvesm: reformat cmd definitions 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: Mon, 27 Sep 2021 07:09:31 -0000 Signed-off-by: Lorenz Stechauner --- PVE/CLI/pvesm.pm | 343 ++++++++++++++++++++++++++++++----------------- 1 file changed, 223 insertions(+), 120 deletions(-) diff --git a/PVE/CLI/pvesm.pm b/PVE/CLI/pvesm.pm index 190de91..7afbe22 100755 --- a/PVE/CLI/pvesm.pm +++ b/PVE/CLI/pvesm.pm @@ -574,76 +574,143 @@ my $print_api_result = sub { }; 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 ], - alloc => [ "PVE::API2::Storage::Content", 'create', ['storage', 'vmid', 'filename', 'size'], - { node => $nodename }, sub { - my $volid = shift; - print "successfully created '$volid'\n"; - }], - free => [ "PVE::API2::Storage::Content", 'delete', ['volume'], - { node => $nodename } ], + 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, + ], + alloc => [ + "PVE::API2::Storage::Content", + 'create', + ['storage', 'vmid', 'filename', 'size'], + { node => $nodename }, + sub { + my $volid = shift; + print "successfully created '$volid'\n"; + }, + ], + 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; + 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; - 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"; - } - }], + 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"; + } + }, + ], pbs => [ "PVE::API2::Storage::Scan", 'pbsscan', @@ -652,13 +719,19 @@ our $cmddef = { $print_api_result, $PVE::RESTHandler::standard_output_options, ], - zfs => [ "PVE::API2::Storage::Scan", 'zfsscan', [], { node => $nodename }, sub { - my $res = shift; + zfs => [ + "PVE::API2::Storage::Scan", + 'zfsscan', + [], + { node => $nodename }, + sub { + my $res = shift; - foreach my $rec (@$res) { - printf "$rec->{pool}\n"; - } - }], + foreach my $rec (@$res) { + printf "$rec->{pool}\n"; + } + }, + ], }, nfsscan => { alias => 'scan nfs' }, cifsscan => { alias => 'scan cifs' }, @@ -667,55 +740,85 @@ our $cmddef = { lvmscan => { alias => 'scan lvm' }, lvmthinscan => { alias => 'scan lvmthin' }, zfsscan => { alias => 'scan zfs' }, - path => [ __PACKAGE__, 'path', ['volume']], - extractconfig => [__PACKAGE__, 'extractconfig', ['volume']], - export => [ __PACKAGE__, 'export', ['volume', 'format', 'filename']], - import => [ __PACKAGE__, 'import', ['volume', 'format', 'filename'], {}, sub { - my $volid = shift; - print PVE::Storage::volume_imported_message($volid); - }], - apiinfo => [ __PACKAGE__, 'apiinfo', [], {}, sub { - my $res = shift; - - print "APIVER $res->{apiver}\n"; - print "APIAGE $res->{apiage}\n"; - }], - 'prune-backups' => [ __PACKAGE__, 'prunebackups', ['storage'], { node => $nodename }, sub { - my $res = shift; - - my ($dryrun, $list) = ($res->{dryrun}, $res->{list}); - - return if !$dryrun; - - if (!scalar(@{$list})) { - print "No backups found\n"; - return; - } + path => [ + __PACKAGE__, + 'path', + ['volume'], + ], + extractconfig => [ + __PACKAGE__, + 'extractconfig', + ['volume'], + ], + export => [ + __PACKAGE__, + 'export', + ['volume', 'format', 'filename'], + ], + import => [ + __PACKAGE__, + 'import', + ['volume', 'format', 'filename'], + {}, + sub { + my $volid = shift; + print PVE::Storage::volume_imported_message($volid); + }, + ], + apiinfo => [ + __PACKAGE__, + 'apiinfo', + [], + {}, + sub { + my $res = shift; - print "NOTE: this is only a preview and might not be what a subsequent\n" . - "prune call does if backups are removed/added in the meantime.\n\n"; + print "APIVER $res->{apiver}\n"; + print "APIAGE $res->{apiage}\n"; + }, + ], + 'prune-backups' => [ + __PACKAGE__, + 'prunebackups', + ['storage'], + { node => $nodename }, + sub { + my $res = shift; - my @sorted = sort { - my $vmcmp = PVE::Tools::safe_compare($a->{vmid}, $b->{vmid}, sub { $_[0] <=> $_[1] }); - return $vmcmp if $vmcmp ne 0; - return $a->{ctime} <=> $b->{ctime}; - } @{$list}; + my ($dryrun, $list) = ($res->{dryrun}, $res->{list}); - my $maxlen = 0; - foreach my $backup (@sorted) { - my $volid = $backup->{volid}; - $maxlen = length($volid) if length($volid) > $maxlen; - } - $maxlen+=1; - - printf("%-${maxlen}s %15s %10s\n", 'Backup', 'Backup-ID', 'Prune-Mark'); - foreach my $backup (@sorted) { - my $type = $backup->{type}; - my $vmid = $backup->{vmid}; - my $backup_id = defined($vmid) ? "$type/$vmid" : "$type"; - printf("%-${maxlen}s %15s %10s\n", $backup->{volid}, $backup_id, $backup->{mark}); - } - }], + return if !$dryrun; + + if (!scalar(@{$list})) { + print "No backups found\n"; + return; + } + + print "NOTE: this is only a preview and might not be what a subsequent\n" . + "prune call does if backups are removed/added in the meantime.\n\n"; + + my @sorted = sort { + my $vmcmp = PVE::Tools::safe_compare($a->{vmid}, $b->{vmid}, sub { $_[0] <=> $_[1] }); + return $vmcmp if $vmcmp ne 0; + return $a->{ctime} <=> $b->{ctime}; + } @{$list}; + + my $maxlen = 0; + foreach my $backup (@sorted) { + my $volid = $backup->{volid}; + $maxlen = length($volid) if length($volid) > $maxlen; + } + $maxlen+=1; + + printf("%-${maxlen}s %15s %10s\n", 'Backup', 'Backup-ID', 'Prune-Mark'); + foreach my $backup (@sorted) { + my $type = $backup->{type}; + my $vmid = $backup->{vmid}; + my $backup_id = defined($vmid) ? "$type/$vmid" : "$type"; + printf("%-${maxlen}s %15s %10s\n", $backup->{volid}, $backup_id, $backup->{mark}); + } + }, + ], }; 1; -- 2.30.2