diff --git a/lib/pve/cli/base.rb b/lib/pve/cli/base.rb index 9c23cc5..3b244a9 100644 --- a/lib/pve/cli/base.rb +++ b/lib/pve/cli/base.rb @@ -2,6 +2,13 @@ require 'pmap' class PVE::Cli + def exc2warn dret, exc = Exception + yield + rescue exc + warn "#{$!} (#{$!.class})" + dret + end + using IPAddress::ToSWithNetmaskForNetworks def cli_base @@ -18,8 +25,9 @@ def cli_base cli.cmd( :status, "Lists Nodes/VMs/CTs with status", &lambda {|target=nil, sort:, node: nil, status: nil, tags: nil| hosting_table target: target, status: status, sort: sort, tags: tags do |push| node_opt( node). - each( &push).lazy. - flat_map {|n| [ Thread.new( n, &:lxc), Thread.new( n, &:qemu) ] }. + each( &push). + flat_map {|n| [ n.method(:lxc), n.method(:qemu) ] }. + flat_pmap {|m| m.call }. each {|n| n.value.each &push } end }). diff --git a/lib/pve/cli/ct.rb b/lib/pve/cli/ct.rb index e7debb0..170fad3 100644 --- a/lib/pve/cli/ct.rb +++ b/lib/pve/cli/ct.rb @@ -4,16 +4,14 @@ def cli_ct ct_cli.cmd :list, "List CT-IDs", aliases: ['ls'], &lambda {|node=nil| connect nodes = node ? Proxmox::Node.find_by_name( name) : Proxmox::Node.all - nodes.flat_map do |n| - n.lxc.map {|c| c.vmid.to_i } + nodes.flat_pmap do |n| + exc2warn( []) { n.lxc.map {|c| c.vmid.to_i } } end.sort.each {|c| puts c } } ct_cli.cmd( :status, "Lists CTs 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. - map {|n| Thread.new n, &:lxc }. - each {|n| n.value.each &push } + node_opt( node).peach {|n| exc2warn( nil) { n.lxc.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/proxmox.rb b/lib/pve/proxmox.rb index f335140..98b7550 100644 --- a/lib/pve/proxmox.rb +++ b/lib/pve/proxmox.rb @@ -173,7 +173,7 @@ module Proxmox class < 2.7" + spec.required_ruby_version = Gem::Requirement.new ">= 2.7" spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = spec.homepage