class PVE::Cli def cli_ct cli.sub :ct, "Containers", aliases: %w[lx lxc] do |ct_cli| ct_cli.cmd :list, "List CT-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.lxc.map {|c| c.vmid.to_i } end.sort.each {|c| puts c } } ct_cli.cmd :status, "List CTs with status", aliases: [nil], &lambda {|node=nil| connect to = TablizedOutput.new %w[Status HA ID Name Host Uptime CPU Mem/MiB Disk/MiB] nodes = Proxmox::Node.all nodes = nodes.select {|n| node == n.name } if node nodes.each do |n| n.lxc.each &to.method( :virt) end to.print order: [3] } ct_cli.cmd :enter, "Enter Console of CT", &lambda {|name_or_id| connect STDERR.puts "! #{$?.exitstatus}" unless Proxmox::LXC.find!( name_or_id).enter } ct_cli.cmd :exec, "Executes Command in CT", min: 4, &lambda {|name_or_id, *command| connect STDERR.puts "! #{$?.exitstatus}" unless Proxmox::LXC.find!( name_or_id).exec *command } ct_cli.cmd( :start, "Starts CT", min: 3, &lambda {|name_or_id, node: nil, fire:, timeout:, secs:| connect ct = Proxmox::LXC.find! name_or_id start ct, node: node, fire: fire, timeout: timeout, secs: secs }). opt( :node, "-nNODE", "--node=NODE", "On NODE (default, as is, so without migration)"). tap {|c| opts_wait c } ct_cli.cmd( :stop, "Stops CT", min: 3, &lambda {|name_or_id, fire: nil, timeout:, secs:| connect ct = Proxmox::LXC.find! name_or_id stop ct, fire: fire, timeout: timeout, secs: secs }).tap {|c| opts_wait c } ct_cli.cmd( :wait, "Wait till CT is in state", &lambda {|name_or_id, state, timeout: nil, secs: nil| connect ct = Proxmox::LXC.find! name_or_id wait ct, state, timeout: timeout, secs: secs }). opt( :timeout, "-tTIMEOUT", "--timeout=TIMEOUT", "Wait for max TIMEOUT seconds (default: endless)", default: nil). opt( :secs, "-sSECONDS", "--seconds=SECONDS", "Check every SECONDS for state (default: 0.2)", default: 0.2) ct_cli.cmd( :create, "Creates a new container", &lambda {|template, *options| #, fire:, timeout:, secs:, start:| if %w[-h --help].include? template STDERR.puts "Usage: ct create TEMPLATE -h # Shows template-related options" STDERR.puts " ct create TEMPLATE [OPTIONS] # Creates a container" exit 1 end ctopts = {} OptionParser.new do |opts| opts.banner = <