Task::Status implemented. rest_prefix is own method. debian template updated. Log-printing optimized.
This commit is contained in:
parent
890aa2a389
commit
38ea2125ff
|
@ -55,6 +55,17 @@ class PVE::Cli
|
||||||
exit 1 unless interactive? and r
|
exit 1 unless interactive? and r
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def task_log task, logn, limit = 1024
|
||||||
|
log = task.log start: logn, limit: limit
|
||||||
|
log = [] if [{n: 1, t: 'no content'}] == log
|
||||||
|
unless log.empty?
|
||||||
|
STDERR.printf "\r\e[J"
|
||||||
|
log.each {|l| puts l[:t] }
|
||||||
|
logn = log.last[:n]
|
||||||
|
end
|
||||||
|
logn
|
||||||
|
end
|
||||||
|
|
||||||
def wait task, secs: nil, text: nil
|
def wait task, secs: nil, text: nil
|
||||||
secs ||= 0.1
|
secs ||= 0.1
|
||||||
spinners, spin, logn = "▖▘▝▗", 0, 0
|
spinners, spin, logn = "▖▘▝▗", 0, 0
|
||||||
|
@ -62,23 +73,19 @@ class PVE::Cli
|
||||||
host = task.host&.name
|
host = task.host&.name
|
||||||
loop do
|
loop do
|
||||||
s = task.status
|
s = task.status
|
||||||
if s[:exitstatus]
|
logn = self.task_log task, logn
|
||||||
STDERR.printf "\r[%s] %s %s %s\e[J\n",
|
if s.finished?
|
||||||
host || s[:id],
|
loop do
|
||||||
case s[:exitstatus]
|
r = self.task_log task, logn
|
||||||
when "OK" then "\e[32;1m✓\e[0m"
|
break if 0 == logn - r
|
||||||
else "\e[31;1m✗\e[0m"
|
logn = r
|
||||||
end,
|
|
||||||
text && "#{text}:",
|
|
||||||
s[:status] == 'stopped' ? :finished : s[:status]
|
|
||||||
return task
|
|
||||||
end
|
end
|
||||||
log = task.log start: logn
|
STDERR.printf "\r[%s] %s %s %s\e[J\n",
|
||||||
log = [] if [{n: 1, t: 'no content'}] == log
|
host || s.id,
|
||||||
unless log.empty?
|
s.successfull? ? "\e[32;1m✓\e[0m" : "\e[31;1m✗\e[0m",
|
||||||
STDERR.printf "\r\e[J"
|
text && "#{text}:",
|
||||||
log.each {|l| puts l[:t] }
|
s.stopped? ? :finished : s.status
|
||||||
logn = log.last[:n]
|
return s
|
||||||
end
|
end
|
||||||
STDERR.printf "\r[%s] \e[33;1m%s\e[0m %s...\e[J",
|
STDERR.printf "\r[%s] \e[33;1m%s\e[0m %s...\e[J",
|
||||||
host || s[:id],
|
host || s[:id],
|
||||||
|
@ -99,9 +106,7 @@ class PVE::Cli
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
task = host.start
|
task = host.start
|
||||||
unless fire
|
wait task, text: "Starting" unless fire
|
||||||
wait task, text: "Starting"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop host, timeout: nil, fire: nil, secs: nil
|
def stop host, timeout: nil, fire: nil, secs: nil
|
||||||
|
@ -120,9 +125,13 @@ class PVE::Cli
|
||||||
options[:start] = fire && 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"
|
status = wait task, text: "Creating"
|
||||||
|
if status.successfull?
|
||||||
host = task.host.refresh!
|
host = task.host.refresh!
|
||||||
start host, timeout: timeout, secs: secs if start
|
start host, timeout: timeout, secs: secs if start
|
||||||
|
elsif not interactive?
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy ct, timeout: nil, fire: nil, secs: nil
|
def destroy ct, timeout: nil, fire: nil, secs: nil
|
||||||
|
|
|
@ -16,7 +16,7 @@ def cli_task
|
||||||
n.tasks.each do |t|
|
n.tasks.each do |t|
|
||||||
next unless t.upid == upid
|
next unless t.upid == upid
|
||||||
puts t.upid
|
puts t.upid
|
||||||
t.log.each {|l| puts l[:l] }
|
t.log( start: 0, limit: 1024).each {|l| puts l[:t] }
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -123,6 +123,10 @@ module Proxmox
|
||||||
n.send :__update__, data
|
n.send :__update__, data
|
||||||
end
|
end
|
||||||
private :__new__
|
private :__new__
|
||||||
|
|
||||||
|
def fetch predata
|
||||||
|
__new__( predata).refresh!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def respond_to? method
|
def respond_to? method
|
||||||
|
@ -147,8 +151,10 @@ module Proxmox
|
||||||
initialize
|
initialize
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
private :__update__
|
||||||
|
|
||||||
def refresh!
|
def refresh!
|
||||||
|
p self: self, refresh: @rest_prefix
|
||||||
__update__ rest_get( @rest_prefix)
|
__update__ rest_get( @rest_prefix)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -177,8 +183,12 @@ module Proxmox
|
||||||
@name =~ t or @vmid.to_s =~ t or @sid =~ t
|
@name =~ t or @vmid.to_s =~ t or @sid =~ t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rest_prefix
|
||||||
|
@rest_prefix ||= "/nodes/#{@node}"
|
||||||
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@rest_prefix = "/nodes/#{@node}"
|
rest_prefix
|
||||||
@sid = "nd:#{@node}"
|
@sid = "nd:#{@node}"
|
||||||
@name = @node
|
@name = @node
|
||||||
end
|
end
|
||||||
|
@ -211,21 +221,51 @@ module Proxmox
|
||||||
end
|
end
|
||||||
|
|
||||||
class Task < Base
|
class Task < Base
|
||||||
|
class Status < Base
|
||||||
|
def rest_prefix
|
||||||
|
@rest_prefix ||= '/nodes/%s/tasks/%s/status' % [@node.node, @upid]
|
||||||
|
end
|
||||||
|
|
||||||
|
def refresh!
|
||||||
|
d = rest_get @rest_prefix
|
||||||
|
d[:starttime] &&= Time.at d[:starttime]
|
||||||
|
d = {exitstatus: nil}.merge d
|
||||||
|
__update__ d.merge( node: @node, t: 'status', upid: @upid, task: @task)
|
||||||
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@rest_prefix = "/nodes/#{@node.node}/tasks/#{upid}"
|
rest_prefix
|
||||||
@sid = upid
|
@sid = upid
|
||||||
end
|
end
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
"#<#{self.class.name} #{upid}>"
|
h = instance_variables - %i[@node @task @sid @rest_prefix @upid @t]
|
||||||
|
h.map! {|k| "#{k[1..-1]}=#{instance_variable_get(k).inspect}" }
|
||||||
|
"#<#{self.class.name}|#{@upid} node=#{@node.node} #{h.join ' '}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
#def finished?
|
def running?() 'running' == @status end
|
||||||
# rest_get( "/nodes/#{node}/tasks/")
|
def finished?() 'stopped' == @status end
|
||||||
#end
|
alias stopped? finished?
|
||||||
|
def successfull?() stopped? ? 'OK' == @exitstatus : nil end
|
||||||
|
def failed?() stopped? ? 'OK' != @exitstatus : nil end
|
||||||
|
end
|
||||||
|
|
||||||
|
def rest_prefix
|
||||||
|
@rest_prefix = "/nodes/#{@node.node}/tasks/#{upid}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
rest_prefix
|
||||||
|
@sid = upid
|
||||||
|
end
|
||||||
|
|
||||||
|
def inspect
|
||||||
|
"#<#{self.class.name} #{@upid}>"
|
||||||
|
end
|
||||||
|
|
||||||
def status
|
def status
|
||||||
rest_get( "#{@rest_prefix}/status")
|
Status.fetch node: @node, task: self, upid: @upid
|
||||||
end
|
end
|
||||||
|
|
||||||
def log start: nil, limit: nil
|
def log start: nil, limit: nil
|
||||||
|
@ -235,8 +275,7 @@ module Proxmox
|
||||||
|
|
||||||
class Hosted < Base
|
class Hosted < Base
|
||||||
def refresh!
|
def refresh!
|
||||||
node, t = @node, @t
|
__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
|
end
|
||||||
|
|
||||||
def === t
|
def === t
|
||||||
|
@ -392,8 +431,12 @@ module Proxmox
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rest_prefix
|
||||||
|
@rest_prefix ||= "/nodes/%s/qemu/%d" % [@node.node, @vmid]
|
||||||
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@rest_prefix = "/nodes/%s/qemu/%d" % [@node.node, @vmid]
|
rest_prefix
|
||||||
@sid = "qm:#{@vmid}"
|
@sid = "qm:#{@vmid}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -507,8 +550,12 @@ module Proxmox
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rest_prefix
|
||||||
|
@rest_prefix ||= "/nodes/%s/lxc/%d" % [@node.node, @vmid]
|
||||||
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@rest_prefix = "/nodes/%s/lxc/%d" % [@node.node, @vmid]
|
rest_prefix
|
||||||
@sid = "ct:#{@vmid}"
|
@sid = "ct:#{@vmid}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -526,8 +573,12 @@ module Proxmox
|
||||||
end
|
end
|
||||||
|
|
||||||
class HA < Base
|
class HA < Base
|
||||||
|
def rest_prefix
|
||||||
|
@rest_prefix ||= "/cluster/ha/resources/#{virt.sid}"
|
||||||
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@rest_prefix = "/cluster/ha/resources/#{virt.sid}"
|
rest_prefix
|
||||||
end
|
end
|
||||||
|
|
||||||
class <<self
|
class <<self
|
||||||
|
|
|
@ -186,7 +186,8 @@ module PVE::CTTemplate
|
||||||
options.ostemplate ||
|
options.ostemplate ||
|
||||||
case ostype
|
case ostype
|
||||||
when 'debian'
|
when 'debian'
|
||||||
'local:vztmpl/debian-10-standard_10.5-1_amd64.tar.gz'
|
# TODO: how to determine which template?
|
||||||
|
'local:vztmpl/debian-10-standard_10.7-1_amd64.tar.gz'
|
||||||
else
|
else
|
||||||
raise ArgumentError, "OS-Template for ostype #{ostype} not found or ostemplate not provided."
|
raise ArgumentError, "OS-Template for ostype #{ostype} not found or ostemplate not provided."
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue