public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH storage 1/2] pvesm: reformat cmd definitions
@ 2021-09-27  7:09 Lorenz Stechauner
  2021-09-27  7:09 ` [pve-devel] [PATCH storage 2/2] fix #3633: pvesm: use print_api_results Lorenz Stechauner
  2021-09-27 12:36 ` [pve-devel] [PATCH storage 1/2] pvesm: reformat cmd definitions Thomas Lamprecht
  0 siblings, 2 replies; 3+ messages in thread
From: Lorenz Stechauner @ 2021-09-27  7:09 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Lorenz Stechauner <l.stechauner@proxmox.com>
---
 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





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

* [pve-devel] [PATCH storage 2/2] fix #3633: pvesm: use print_api_results
  2021-09-27  7:09 [pve-devel] [PATCH storage 1/2] pvesm: reformat cmd definitions Lorenz Stechauner
@ 2021-09-27  7:09 ` Lorenz Stechauner
  2021-09-27 12:36 ` [pve-devel] [PATCH storage 1/2] pvesm: reformat cmd definitions Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Lorenz Stechauner @ 2021-09-27  7:09 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Lorenz Stechauner <l.stechauner@proxmox.com>
---
 PVE/CLI/pvesm.pm | 144 ++++++-----------------------------------------
 1 file changed, 18 insertions(+), 126 deletions(-)

diff --git a/PVE/CLI/pvesm.pm b/PVE/CLI/pvesm.pm
index 7afbe22..7bb363c 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',
@@ -594,14 +532,16 @@ our $cmddef = {
 	'index',
 	[],
 	{ node => $nodename },
-	$print_status,
+	$print_api_result,
+	$PVE::RESTHandler::standard_output_options,
     ],
     list => [
 	"PVE::API2::Storage::Content",
 	'index',
 	['storage'],
 	{ node => $nodename },
-	$print_content,
+	$print_api_result,
+	$PVE::RESTHandler::standard_output_options,
     ],
     alloc => [
 	"PVE::API2::Storage::Content",
@@ -625,91 +565,48 @@ our $cmddef = {
 	    '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};
-		}
-	    },
+	    $print_api_result,
+	    $PVE::RESTHandler::standard_output_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};
-		}
-	    },
+	    $print_api_result,
+	    $PVE::RESTHandler::standard_output_options,
 	],
 	glusterfs => [
 	    "PVE::API2::Storage::Scan",
 	    'glusterfsscan',
 	    ['server'],
 	    { node => $nodename },
-	    sub  {
-		my $res = shift;
-
-		foreach my $rec (@$res) {
-		    printf "%s\n", $rec->{volname};
-		}
-	    },
+	    $print_api_result,
+	    $PVE::RESTHandler::standard_output_options,
 	],
 	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};
-		}
-	    },
+	    $print_api_result,
+	    $PVE::RESTHandler::standard_output_options,
 	],
 	lvm => [
 	    "PVE::API2::Storage::Scan",
 	    'lvmscan',
 	    [],
 	    { node => $nodename },
-	    sub  {
-		my $res = shift;
-		foreach my $rec (@$res) {
-		    printf "$rec->{vg}\n";
-		}
-	    },
+	    $print_api_result,
+	    $PVE::RESTHandler::standard_output_options,
 	],
 	lvmthin => [
 	    "PVE::API2::Storage::Scan",
 	    'lvmthinscan',
 	    ['vg'],
 	    { node => $nodename },
-	    sub  {
-		my $res = shift;
-		foreach my $rec (@$res) {
-		    printf "$rec->{lv}\n";
-		}
-	    },
+	    $print_api_result,
+	    $PVE::RESTHandler::standard_output_options,
 	],
 	pbs => [
 	    "PVE::API2::Storage::Scan",
@@ -724,13 +621,8 @@ our $cmddef = {
 	    'zfsscan',
 	    [],
 	    { node => $nodename },
-	    sub  {
-		my $res = shift;
-
-		foreach my $rec (@$res) {
-		    printf "$rec->{pool}\n";
-		}
-	    },
+	    $print_api_result,
+	    $PVE::RESTHandler::standard_output_options,
 	],
     },
     nfsscan => { alias => 'scan nfs' },
-- 
2.30.2





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

* Re: [pve-devel] [PATCH storage 1/2] pvesm: reformat cmd definitions
  2021-09-27  7:09 [pve-devel] [PATCH storage 1/2] pvesm: reformat cmd definitions Lorenz Stechauner
  2021-09-27  7:09 ` [pve-devel] [PATCH storage 2/2] fix #3633: pvesm: use print_api_results Lorenz Stechauner
@ 2021-09-27 12:36 ` Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Lamprecht @ 2021-09-27 12:36 UTC (permalink / raw)
  To: Proxmox VE development discussion, Lorenz Stechauner

On 27.09.21 09:09, Lorenz Stechauner wrote:
> Signed-off-by: Lorenz Stechauner <l.stechauner@proxmox.com>
> ---
>  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'] ],

above is <= 100 and even <= 80 cc, and we want to avoid line bloat in general,
as while overly long lines are not ideal, splitting basically on a per-word basis
isn't either.

It's totally fine in an hash/map definition to have some lines single ones and
some not.

> -    set => [ "PVE::API2::Storage::Config", 'update', ['storage'] ],

same

> -    remove => [ "PVE::API2::Storage::Config", 'delete', ['storage'] ],

same

> -    status => [ "PVE::API2::Storage::Status", 'index', [],

same (but would need to use the <= 100 cc limit, which is fine here.

> -		{ node => $nodename }, $print_status ],
> -    list => [ "PVE::API2::Storage::Content", 'index', ['storage'],

fwiw, we could have a `my $API = 'PVE::API2::Storage::';` before the cmddef and
use string interpolation, e.g.:

list => [ "${API}::Content", 'index', ['storage'], { node => $nodename }, $print_content ],

no hard feelings, but given that there's a lot of API module-path repetition and
it adds quite a bit to the line length it could be worth it..

> -	      { 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;
> 





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

end of thread, other threads:[~2021-09-27 12:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27  7:09 [pve-devel] [PATCH storage 1/2] pvesm: reformat cmd definitions Lorenz Stechauner
2021-09-27  7:09 ` [pve-devel] [PATCH storage 2/2] fix #3633: pvesm: use print_api_results Lorenz Stechauner
2021-09-27 12:36 ` [pve-devel] [PATCH storage 1/2] pvesm: reformat cmd definitions Thomas Lamprecht

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