ct resize implemented. wait shows “finished” instead of “stopped”. ct create starts ct only if --start
This commit is contained in:
parent
618b6fbefe
commit
cf9093bafb
|
@ -59,16 +59,18 @@ class PVE::Cli
|
|||
secs ||= 0.1
|
||||
spinners, spin, logn = "▖▘▝▗", 0, 0
|
||||
STDERR.puts task.upid
|
||||
host = task.host&.name
|
||||
loop do
|
||||
s = task.status
|
||||
if s[:exitstatus]
|
||||
STDERR.printf "\r[%s] %s %s\e[J\n",
|
||||
task.host ? task.host.name : s[:id],
|
||||
STDERR.printf "\r[%s] %s %s %s\e[J\n",
|
||||
host || s[:id],
|
||||
case s[:exitstatus]
|
||||
when "OK" then "\e[32;1m✓\e[0m"
|
||||
else "\e[31;1m✗\e[0m"
|
||||
end,
|
||||
s[:status]
|
||||
text && "#{text}:",
|
||||
s[:status] == 'stopped' ? :finished : s[:status]
|
||||
return task
|
||||
end
|
||||
log = task.log start: logn
|
||||
|
@ -78,7 +80,10 @@ class PVE::Cli
|
|||
log.each {|l| puts l[:t] }
|
||||
logn = log.last[:n]
|
||||
end
|
||||
STDERR.printf "\r[%s] \e[33;1m%s\e[0m %s...\e[J", task.host ? task.host.name : s[:id], spinners[spin = (spin + 1) % 4], text || "Working"
|
||||
STDERR.printf "\r[%s] \e[33;1m%s\e[0m %s...\e[J",
|
||||
host || s[:id],
|
||||
spinners[spin = (spin + 1) % 4],
|
||||
text || "Working"
|
||||
sleep secs
|
||||
end
|
||||
end
|
||||
|
@ -112,12 +117,12 @@ class PVE::Cli
|
|||
end
|
||||
|
||||
def create klass, template, timeout: nil, fire: nil, secs: nil, start: nil, **options
|
||||
options[:start] = true if fire and start
|
||||
options[:start] = fire && start
|
||||
task = klass.create template, **options
|
||||
return if fire
|
||||
wait task, text: "Creating"
|
||||
host = task.host.refresh!
|
||||
start host, timeout: timeout, secs: secs
|
||||
start host, timeout: timeout, secs: secs if start
|
||||
end
|
||||
|
||||
def destroy ct, timeout: nil, fire: nil, secs: nil
|
||||
|
@ -151,7 +156,7 @@ class PVE::Cli
|
|||
def call *argv
|
||||
cli.call *argv
|
||||
rescue RestClient::ExceptionWithResponse
|
||||
STDERR.puts "#$! - #{$!.response} (#{$!.class})", $!.backtrace.map {|b|" #{b}"}
|
||||
STDERR.puts "#$! - #{$!.response} (#{$!.class})" #, $!.backtrace.map {|b|" #{b}"}
|
||||
rescue UsageError, DenCli::UsageError
|
||||
STDERR.puts $!
|
||||
exit 1
|
||||
|
|
|
@ -65,9 +65,11 @@ def cli_ct
|
|||
end
|
||||
ctopts = {}
|
||||
OptionParser.new do |opts|
|
||||
ctt = PVE::CTTemplate.const_get template.classify
|
||||
opts.banner = <<EOU
|
||||
Usage: ct create #{template} [options]
|
||||
|
||||
#{ctt.help}
|
||||
Options: (*=Required)
|
||||
EOU
|
||||
opts.on '-h', '--help', " Help!" do
|
||||
|
@ -79,7 +81,6 @@ EOU
|
|||
opts.on( '-f', '--[no-]-fire', " Do not wait till running") {|v| ctopts[:start] = v }
|
||||
opts.on( '-t', '--timeout=TIMEOUT', " Wait for max TIMEOUT seconds (default: endless)") {|v| ctopts[:timeout] = v }
|
||||
opts.on( '-s', '--seconds=SECONDS', " Check every SECONDS for state (default: 0.2)") {|v| ctopts[:seconds] = v }
|
||||
ctt = PVE::CTTemplate.const_get template.classify
|
||||
ctt.requirements.each do |name, (type, req, desc, *args)|
|
||||
req = req ? "*" : " "
|
||||
case type
|
||||
|
@ -98,12 +99,19 @@ EOU
|
|||
create Proxmox::LXC, template, **ctopts
|
||||
})
|
||||
|
||||
ct_cli.cmd( :config, '', &lambda {|name_or_id|
|
||||
ct_cli.cmd( :config, 'Shows current config', &lambda {|name_or_id|
|
||||
connect
|
||||
ct = Proxmox::LXC.find! name_or_id
|
||||
STDOUT.puts ct.config.to_json
|
||||
})
|
||||
|
||||
ct_cli.cmd( :resize, 'Resize a disk', &lambda {|name_or_id, disk, size|
|
||||
connect
|
||||
ct = Proxmox::LXC.find! name_or_id
|
||||
task = ct.resize disk, size
|
||||
wait task, text: "Resizing #{ct.sid} #{disk} to #{size}"
|
||||
})
|
||||
|
||||
ct_cli.cmd( :destroy, '', min: 7, &lambda {|name_or_id, fire:, secs:, timeout:, i_really_want_to_destroy:|
|
||||
raise UsageError, "Name/ID is not what you want to destroy" unless name_or_id == i_really_want_to_destroy
|
||||
connect
|
||||
|
|
|
@ -331,6 +331,11 @@ module Proxmox
|
|||
r.delete :delete if r[:delete].empty?
|
||||
rest_put "#{@rest_prefix}/config", r
|
||||
end
|
||||
|
||||
def resize disk, size
|
||||
upid = rest_put "#{@rest_prefix}/resize", disk: disk, size: size
|
||||
Task.send :__new__, node: node, host: @temp, upid: upid
|
||||
end
|
||||
end
|
||||
|
||||
class Qemu < Hosted
|
||||
|
|
Loading…
Reference in a new issue