]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/CLI/pvesm.pm
pvesm list: right align size column
[pve-storage.git] / PVE / CLI / pvesm.pm
index 161b0a343e7e62b6c126a939b76c20dce854bc62..510faba0882bd43d7f1ef1f85498e2768777a89f 100755 (executable)
@@ -117,28 +117,30 @@ __PACKAGE__->register_method ({
 my $print_content = sub {
     my ($list) = @_;
 
-    my $maxlenname = 0;
+    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 "%-${maxlenname}s %5s %10d %d\n", $volid,
-       $info->{format}, $info->{size}, $info->{vmid};
+       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 "%-${maxlenname}s %5s %10d\n", $volid,
-       $info->{format}, $info->{size};
+       printf "$basefmt\n", $volid, $info->{format}, $info->{content}, $info->{size};
     }
 };
 
@@ -310,9 +312,12 @@ __PACKAGE__->register_method ({
            my ($cidr, $ip, $subnet) = ($1, $2, $3);
            if ($subnet) { # got real CIDR notation, not just IP
                my $ips = PVE::Network::get_local_ip_from_cidr($cidr);
-               die "Unable to get single local IP address in network '$cidr'\n"
-                   if scalar(@$ips) != 1;
-               $ip = @$ips[0];
+               die "Unable to get any local IP address in network '$cidr'\n"
+                   if scalar(@$ips) < 1;
+               die "Got multiple local IP address in network '$cidr'\n"
+                   if scalar(@$ips) > 1;
+
+               $ip = $ips->[0];
            }
            my $family = PVE::Tools::get_host_address_family($ip);
            my $port = PVE::Tools::next_migrate_port($family, $ip);
@@ -503,7 +508,7 @@ __PACKAGE__->register_method ({
        type => 'array',
        items => {
            type => "object",
-           properties => { 
+           properties => {
                volname => {
                    description => "The volume name.",
                    type => 'string',