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
|
secs ||= 0.1
|
||||||
spinners, spin, logn = "▖▘▝▗", 0, 0
|
spinners, spin, logn = "▖▘▝▗", 0, 0
|
||||||
STDERR.puts task.upid
|
STDERR.puts task.upid
|
||||||
|
host = task.host&.name
|
||||||
loop do
|
loop do
|
||||||
s = task.status
|
s = task.status
|
||||||
if s[:exitstatus]
|
if s[:exitstatus]
|
||||||
STDERR.printf "\r[%s] %s %s\e[J\n",
|
STDERR.printf "\r[%s] %s %s %s\e[J\n",
|
||||||
task.host ? task.host.name : s[:id],
|
host || s[:id],
|
||||||
case s[:exitstatus]
|
case s[:exitstatus]
|
||||||
when "OK" then "\e[32;1m✓\e[0m"
|
when "OK" then "\e[32;1m✓\e[0m"
|
||||||
else "\e[31;1m✗\e[0m"
|
else "\e[31;1m✗\e[0m"
|
||||||
end,
|
end,
|
||||||
s[:status]
|
text && "#{text}:",
|
||||||
|
s[:status] == 'stopped' ? :finished : s[:status]
|
||||||
return task
|
return task
|
||||||
end
|
end
|
||||||
log = task.log start: logn
|
log = task.log start: logn
|
||||||
|
@ -78,7 +80,10 @@ class PVE::Cli
|
||||||
log.each {|l| puts l[:t] }
|
log.each {|l| puts l[:t] }
|
||||||
logn = log.last[:n]
|
logn = log.last[:n]
|
||||||
end
|
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
|
sleep secs
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -112,12 +117,12 @@ class PVE::Cli
|
||||||
end
|
end
|
||||||
|
|
||||||
def create klass, template, timeout: nil, fire: nil, secs: nil, start: nil, **options
|
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
|
task = klass.create template, **options
|
||||||
return if fire
|
return if fire
|
||||||
wait task, text: "Creating"
|
wait task, text: "Creating"
|
||||||
host = task.host.refresh!
|
host = task.host.refresh!
|
||||||
start host, timeout: timeout, secs: secs
|
start host, timeout: timeout, secs: secs if start
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy ct, timeout: nil, fire: nil, secs: nil
|
def destroy ct, timeout: nil, fire: nil, secs: nil
|
||||||
|
@ -151,7 +156,7 @@ class PVE::Cli
|
||||||
def call *argv
|
def call *argv
|
||||||
cli.call *argv
|
cli.call *argv
|
||||||
rescue RestClient::ExceptionWithResponse
|
rescue RestClient::ExceptionWithResponse
|
||||||
STDERR.puts "#$! - #{$!.response} (#{$!.class})", $!.backtrace.map {|b|" #{b}"}
|
STDERR.puts "#$! - #{$!.response} (#{$!.class})" #, $!.backtrace.map {|b|" #{b}"}
|
||||||
rescue UsageError, DenCli::UsageError
|
rescue UsageError, DenCli::UsageError
|
||||||
STDERR.puts $!
|
STDERR.puts $!
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -65,9 +65,11 @@ def cli_ct
|
||||||
end
|
end
|
||||||
ctopts = {}
|
ctopts = {}
|
||||||
OptionParser.new do |opts|
|
OptionParser.new do |opts|
|
||||||
|
ctt = PVE::CTTemplate.const_get template.classify
|
||||||
opts.banner = <<EOU
|
opts.banner = <<EOU
|
||||||
Usage: ct create #{template} [options]
|
Usage: ct create #{template} [options]
|
||||||
|
|
||||||
|
#{ctt.help}
|
||||||
Options: (*=Required)
|
Options: (*=Required)
|
||||||
EOU
|
EOU
|
||||||
opts.on '-h', '--help', " Help!" do
|
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( '-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( '-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 }
|
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)|
|
ctt.requirements.each do |name, (type, req, desc, *args)|
|
||||||
req = req ? "*" : " "
|
req = req ? "*" : " "
|
||||||
case type
|
case type
|
||||||
|
@ -98,12 +99,19 @@ EOU
|
||||||
create Proxmox::LXC, template, **ctopts
|
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
|
connect
|
||||||
ct = Proxmox::LXC.find! name_or_id
|
ct = Proxmox::LXC.find! name_or_id
|
||||||
STDOUT.puts ct.config.to_json
|
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:|
|
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
|
raise UsageError, "Name/ID is not what you want to destroy" unless name_or_id == i_really_want_to_destroy
|
||||||
connect
|
connect
|
||||||
|
|
|
@ -331,6 +331,11 @@ module Proxmox
|
||||||
r.delete :delete if r[:delete].empty?
|
r.delete :delete if r[:delete].empty?
|
||||||
rest_put "#{@rest_prefix}/config", r
|
rest_put "#{@rest_prefix}/config", r
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class Qemu < Hosted
|
class Qemu < Hosted
|
||||||
|
|
Loading…
Reference in a new issue