cli: Thread -> pmap. exc2warn. ruby>=2.7
This commit is contained in:
parent
f780eccc6a
commit
f268fcc5f7
|
@ -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
|
||||
}).
|
||||
|
|
|
@ -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').
|
||||
|
|
|
@ -173,7 +173,7 @@ module Proxmox
|
|||
class <<self
|
||||
def __new__ data
|
||||
n = allocate
|
||||
n.send :__update__, data
|
||||
n.send :__update__, **data
|
||||
end
|
||||
private :__new__
|
||||
|
||||
|
@ -194,7 +194,7 @@ module Proxmox
|
|||
end
|
||||
end
|
||||
|
||||
def __update__ data
|
||||
def __update__ **data
|
||||
instance_variables.each do |k|
|
||||
remove_instance_variable k
|
||||
end
|
||||
|
@ -207,7 +207,7 @@ module Proxmox
|
|||
private :__update__
|
||||
|
||||
def refresh!
|
||||
__update__ rest_get( @rest_prefix)
|
||||
__update__ **rest_get( @rest_prefix)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -301,7 +301,7 @@ module Proxmox
|
|||
def refresh!
|
||||
d = rest_get @rest_prefix
|
||||
d[:starttime] &&= Time.at d[:starttime]
|
||||
__update__ d.merge( node: @node, upid: @upid, task: @task)
|
||||
__update__ **d.merge( node: @node, upid: @upid, task: @task)
|
||||
end
|
||||
|
||||
def __update__ **data
|
||||
|
@ -406,7 +406,7 @@ module Proxmox
|
|||
end
|
||||
|
||||
def refresh!
|
||||
__update__ rest_get( "#{@rest_prefix}/status/current").merge( node: @node, t: @t)
|
||||
__update__ **rest_get( "#{@rest_prefix}/status/current").merge( node: @node, t: @t)
|
||||
end
|
||||
|
||||
def __update__ **data
|
||||
|
@ -701,7 +701,7 @@ module Proxmox
|
|||
#}.map {|k,v| "#{k}=#{v}" }.join( ','),
|
||||
swap: tmplt.swap,
|
||||
unprivileged: tmplt.unprivileged,
|
||||
features: tmplt.features ? Proxmox::hash2cnfstr( tmplt.features) : nil,
|
||||
features: tmplt.features ? Proxmox::hash2cnfstr( *tmplt.features) : nil,
|
||||
}.delete_if {|k,v| v.nil? }
|
||||
|
||||
temp = LXC.send :__new__, node: node, vmid: options[:vmid], name: name, hostname: options[:hostname]
|
||||
|
@ -763,7 +763,7 @@ module Proxmox
|
|||
|
||||
def refresh!
|
||||
virt = @virt
|
||||
__update__( {state: nil}.merge( rest_get( "/cluster/ha/resources/#{virt.sid}")).merge( virt: virt))
|
||||
__update__ **{state: nil}.merge( rest_get( "/cluster/ha/resources/#{virt.sid}")).merge( virt: virt)
|
||||
self
|
||||
rescue RestClient::InternalServerError
|
||||
__update__ digest: nil, state: nil, virt: virt
|
||||
|
|
|
@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|||
# PVE-7 based on debian-11, so ruby 2.7 is default.
|
||||
# No support for ruby 2.5 anymore (PVE-6 based on debian-10)
|
||||
# Old behaviour will be droped.
|
||||
spec.required_ruby_version = Gem::Requirement.new "~> 2.7"
|
||||
spec.required_ruby_version = Gem::Requirement.new ">= 2.7"
|
||||
|
||||
spec.metadata["homepage_uri"] = spec.homepage
|
||||
spec.metadata["source_code_uri"] = spec.homepage
|
||||
|
|
Loading…
Reference in a new issue