From 9786e145c13748e1d27c14e96017296b9df44e7f Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Sat, 21 Sep 2024 14:54:42 +0200 Subject: [PATCH] more cli: Thread -> pmap. exc2warn --- lib/pve/cli/base.rb | 3 +-- lib/pve/cli/qm.rb | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/pve/cli/base.rb b/lib/pve/cli/base.rb index 3b244a9..1c5dcc9 100644 --- a/lib/pve/cli/base.rb +++ b/lib/pve/cli/base.rb @@ -27,8 +27,7 @@ def cli_base node_opt( node). each( &push). flat_map {|n| [ n.method(:lxc), n.method(:qemu) ] }. - flat_pmap {|m| m.call }. - each {|n| n.value.each &push } + peach {|m| exc2warn( nil) { m.call.each &push } } end }). opt( :sort, '-s', '--sort=COLUMNS', "Sort by COLUMNs eg hn for host and name ([s]tatus, h[a], [i]d, [n]ame (default), [h]ost, [u]ptime, [c]pu, [m]em, [d]isk)", default: 'n'). diff --git a/lib/pve/cli/qm.rb b/lib/pve/cli/qm.rb index 0635c8d..f8b7e0e 100644 --- a/lib/pve/cli/qm.rb +++ b/lib/pve/cli/qm.rb @@ -5,8 +5,8 @@ def cli_qm connect nodes = Proxmox::Node.all nodes = nodes.select {|n| node == n.name } if node - nodes.flat_map do |n| - n.qemu.map {|c| c.vmid.to_i } + nodes.flat_pmap do |n| + exc2warn( []) { n.qemu.map {|c| c.vmid.to_i } } end.sort.each {|c| puts c } } @@ -53,9 +53,7 @@ def cli_qm qm_cli.cmd( :status, "Lists VMs with status", aliases: [nil], &lambda {|target=nil, sort: nil, node: nil, status: nil, tags: nil| hosting_table target: target, status: status, sort: sort, tags: tags do |push| - node_opt( node).lazy. - flat_map {|n| [ Thread.new( n, &:qemu) ] }. - each {|n| n.value.each &push } + node_opt( node).flat_pmap( &:qemu).peach &push end }). opt( :sort, '-s', '--sort=COLUMNS', "Sort by COLUMNs eg hn for host and name ([s]tatus, h[a], [i]d, [n]ame (default), [h]ost, [u]ptime, [c]pu, [m]em, [d]isk)", default: 'n').