pve/lib/pve/cli/qm.rb

41 lines
1.6 KiB
Ruby

class PVE::Cli
def cli_qm
cli.sub :qm, "Virtual Machines", aliases: %w[v vm qemu], &lambda {|qm|
qm.cmd :list, "List VM-IDs", aliases: ['ls'], &lambda {|node=nil|
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 }
end.sort.each {|c| puts c }
}
qm.cmd( :status, "Lists CTs with status", aliases: [nil], &lambda {|target=nil, sort: nil, node: nil, status: nil|
hosting_table target: target, state: state, sort: sort do |push|
node_opt( node).
each( &push).lazy.
flat_map {|n| [ Thread.new( n, &:lxc), Thread.new( n, &:qemu) ] }.
each {|n| n.value.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').
opt( :node, '-n', '--node=NODE', "List only hosted by this NODE").
opt( :status, '-S', '--status=STATUS', "Filter for status (running, stopped, ...) (default: no filter)")
qm.cmd :exec, "Executes Command in VM via qemu-guest-agent", min: 4, &lambda {|name_or_id, *command|
connect
STDERR.puts "! #{$?.exitstatus}" unless Proxmox::Qemu.find!( name_or_id).exec *command
}
qm.cmd( :resize, 'Resize a disk', &lambda {|name_or_id, disk, size|
connect
qm = Proxmox::Qemu.find! name_or_id
task = qm.resize disk, size
wait task, text: "Resizing #{qm.sid} #{disk} to #{size}"
})
qm.cmd 'help', '', aliases: ['-h', '--help'], &lambda {|*args| help qm, *args }
}
end
end