pve 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/pve/cli/base.rb +1 -0
- data/lib/pve/cli/ct.rb +18 -9
- data/lib/pve/cli/qm.rb +18 -9
- data/lib/pve/helper.rb +45 -23
- data/lib/pve/version.rb +1 -1
- metadata +2 -3
- data/Gemfile.lock +0 -70
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0af90de01a1f74dac6c799494f4e70fe13b534fc3b3bf95f3b333aa801d117e8
|
4
|
+
data.tar.gz: d8ce0656f04dec34d33c434093b7982e7cefe22869f8abd3ff4fa2ce574b224a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b68f8317b05050d46dc938afd83eea40929bf7628caa2db280f091d111dc26f51a4f4875220938c3b8dcba2b55cd3c48ae5a6db997e65d708027029ce6d5d705
|
7
|
+
data.tar.gz: 41dc8f9345162f1003eb27f37f1429fc525073828271dde81716520ad8de1ad01ec806a0154fa1c4582c5cdfe4d030dfd4b8be891482e36e38bc05bc8e52c296
|
data/.gitignore
CHANGED
data/lib/pve/cli/base.rb
CHANGED
data/lib/pve/cli/ct.rb
CHANGED
@@ -9,16 +9,25 @@ def cli_ct
|
|
9
9
|
end.sort.each {|c| puts c }
|
10
10
|
}
|
11
11
|
|
12
|
-
ct_cli.cmd :status, "
|
12
|
+
ct_cli.cmd( :status, "Lists CTs with status", aliases: [nil], &lambda {|target=nil, sort: 'n', node: nil|
|
13
13
|
connect
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
node &&= /\A#{node}\z/
|
15
|
+
to = TablizedOutput.new %w[Status HA ID Name Host Uptime CPU/% Mem/MiB Mem/% Disk/MiB Disk/%]
|
16
|
+
push =
|
17
|
+
if target
|
18
|
+
target = /\A#{target}\z/
|
19
|
+
lambda {|n| to.virt n if n === target }
|
20
|
+
else
|
21
|
+
lambda {|n| to.virt n }
|
22
|
+
end
|
23
|
+
nodes = node ? Proxmox::Node.find_by_name( name) : Proxmox::Node.all
|
24
|
+
nodes.
|
25
|
+
map {|n| Thread.new( n, &:lxc) }.
|
26
|
+
each {|n| n.value.each &push }
|
27
|
+
to.print order: sort.each_char.map {|c| (2*c.ord[5]-1) * (' sainhucmd'.index( c.downcase)) }
|
28
|
+
}).
|
29
|
+
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)").
|
30
|
+
opt( :node, '-n', '--node=NODE', "List only hosted by this NODE")
|
22
31
|
|
23
32
|
ct_cli.cmd :enter, "Enter Console of CT", &lambda {|name_or_id|
|
24
33
|
connect
|
data/lib/pve/cli/qm.rb
CHANGED
@@ -10,16 +10,25 @@ def cli_qm
|
|
10
10
|
end.sort.each {|c| puts c }
|
11
11
|
}
|
12
12
|
|
13
|
-
qm.cmd :status, "
|
13
|
+
qm.cmd( :status, "Lists CTs with status", aliases: [nil], &lambda {|target=nil, sort: 'n', node: nil|
|
14
14
|
connect
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
node &&= /\A#{node}\z/
|
16
|
+
to = TablizedOutput.new %w[Status HA ID Name Host Uptime CPU/% Mem/MiB Mem/% Disk/MiB Disk/%]
|
17
|
+
push =
|
18
|
+
if target
|
19
|
+
target = /\A#{target}\z/
|
20
|
+
lambda {|n| to.virt n if n === target }
|
21
|
+
else
|
22
|
+
lambda {|n| to.virt n }
|
23
|
+
end
|
24
|
+
nodes = node ? Proxmox::Node.find_by_name( name) : Proxmox::Node.all
|
25
|
+
nodes.
|
26
|
+
map {|n| Thread.new( n, &:qemu) }.
|
27
|
+
each {|n| n.value.each &push }
|
28
|
+
to.print order: sort.each_char.map {|c| (2*c.ord[5]-1) * (' sainhucmd'.index( c.downcase)) }
|
29
|
+
}).
|
30
|
+
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)").
|
31
|
+
opt( :node, '-n', '--node=NODE', "List only hosted by this NODE")
|
23
32
|
|
24
33
|
qm.cmd :exec, "Executes Command in VM via qemu-guest-agent", min: 4, &lambda {|name_or_id, *command|
|
25
34
|
connect
|
data/lib/pve/helper.rb
CHANGED
@@ -13,17 +13,24 @@ end
|
|
13
13
|
|
14
14
|
|
15
15
|
class Measured
|
16
|
+
class V
|
17
|
+
attr_reader :value, :length
|
18
|
+
|
19
|
+
def initialize( value, length = nil) @value, @length = value, length || value.length end
|
20
|
+
def inspect() "#<Measured::V #{@value.inspect} (#{@length})>" end
|
21
|
+
alias :to_s :value
|
22
|
+
alias :to_str :value
|
23
|
+
end
|
24
|
+
|
16
25
|
class <<self
|
17
26
|
def bytes1 v
|
18
27
|
v = v.to_f
|
19
|
-
return
|
28
|
+
return units '%d ' % v , :B if 512 > v
|
20
29
|
%w[KiB MiBy GiByt TiByte ExiByte PetiByte].each_with_index do |m|
|
21
30
|
v /= 1024
|
22
|
-
|
23
|
-
#return "%d %s" % [v, m] if 512 > v
|
24
|
-
return "%.1f %s" % [v, m] if 512 > v
|
31
|
+
return units '%.1f ' % v, m if 512 > v
|
25
32
|
end
|
26
|
-
|
33
|
+
units '%d ' % v, :PetiByte
|
27
34
|
end
|
28
35
|
|
29
36
|
def bytes2 v
|
@@ -40,21 +47,28 @@ class Measured
|
|
40
47
|
end
|
41
48
|
alias bytes bytes2
|
42
49
|
|
50
|
+
def units val, unit
|
51
|
+
v = "#{val}\e[1;30m#{unit}\e[0m"
|
52
|
+
V.new v, v.length - 11
|
53
|
+
end
|
54
|
+
|
43
55
|
def seconds i
|
44
56
|
i = i.to_i
|
45
|
-
return
|
46
|
-
return
|
57
|
+
return V.new "\e[1;30m·\e[0m", 1 if 0 == i
|
58
|
+
return units '%d ' % i, :s if 90 > i
|
47
59
|
i /= 60
|
48
|
-
return
|
60
|
+
return units '%d ' % i, :mi if 90 > i
|
49
61
|
i /= 60
|
50
|
-
return
|
62
|
+
return units '%d ' % i, :hou if 36 > i
|
51
63
|
i /= 24
|
52
|
-
return
|
64
|
+
return units '%d ' % i, :days if 14 > i
|
53
65
|
j = i / 7
|
54
|
-
return
|
55
|
-
i
|
56
|
-
return
|
57
|
-
|
66
|
+
return units '%d ' % j, :weeks if 8 > j
|
67
|
+
j = i / 30
|
68
|
+
return units '%d ' % j, :months if 11 > j
|
69
|
+
i /= 365.0
|
70
|
+
return units '%.2f ' % i, :years if 550 > i
|
71
|
+
units '%d ' % i, :years
|
58
72
|
end
|
59
73
|
end
|
60
74
|
end
|
@@ -72,10 +86,8 @@ class ColoredString
|
|
72
86
|
|
73
87
|
def length() @string.length end
|
74
88
|
alias size length
|
75
|
-
#def to_str() self end
|
76
89
|
def to_s() "\e[#{@color_codes}m#{@string}\e[0m" end
|
77
90
|
alias to_str to_s
|
78
|
-
#alias inspect to_str
|
79
91
|
|
80
92
|
include Comparable
|
81
93
|
def <=>(o) @string <=> o.string end
|
@@ -101,7 +113,7 @@ class TablizedOutput
|
|
101
113
|
class V < B
|
102
114
|
attr_reader :v, :s
|
103
115
|
def initialize( v, s=nil) @v, @s = v, s || "#{v}" end
|
104
|
-
def to_s() @s end
|
116
|
+
def to_s() @s.to_s end
|
105
117
|
def length() @s.length end
|
106
118
|
def inspect() "#<TO:V #{@v.inspect} #{@s.inspect}>" end
|
107
119
|
end
|
@@ -113,11 +125,9 @@ class TablizedOutput
|
|
113
125
|
def inspect() "#<TO:Percentage #{@v}%>" end
|
114
126
|
|
115
127
|
def to_s
|
116
|
-
#y = w - (v*w).round
|
117
128
|
y = (v*w).round
|
118
129
|
x = (100*v).round
|
119
130
|
r = "%*s" % [w, 0==x ? '·' : x]
|
120
|
-
#"\e[0m#{r[0...y]}\e[1;4;#{0.75>v ? 32 : 31}m#{r[y..-1]}\e[0m"
|
121
131
|
"\e[1;4;#{0.75>v ? 32 : 31}m#{r[0...y]}\e[0m#{r[y..-1]}"
|
122
132
|
end
|
123
133
|
end
|
@@ -139,7 +149,6 @@ class TablizedOutput
|
|
139
149
|
end
|
140
150
|
|
141
151
|
def print order: nil
|
142
|
-
format = "#{@format.map {|f| "\e[%%sm%%#{case f when '<' then '-' else ' ' end}%ds\e[0m"}.join( ' ') % @maxs}\n"
|
143
152
|
ls = @lines
|
144
153
|
if order
|
145
154
|
eval <<-EOC, binding, __FILE__, 1+__LINE__
|
@@ -149,9 +158,22 @@ class TablizedOutput
|
|
149
158
|
}
|
150
159
|
EOC
|
151
160
|
end
|
152
|
-
|
153
|
-
|
154
|
-
|
161
|
+
@stdout.puts \
|
162
|
+
@header.each_with_index.map {|s, i|
|
163
|
+
"#{' ' * (@maxs[i] - s.length)}#{s}"
|
164
|
+
}.join( ' ')
|
165
|
+
ls.each_with_index do |l|
|
166
|
+
@stdout.puts \
|
167
|
+
l.each_with_index.map {|s, i|
|
168
|
+
pad = ' ' * (@maxs[i] - s.length)
|
169
|
+
case @format[i]
|
170
|
+
when '<'
|
171
|
+
"#{s}#{pad}"
|
172
|
+
else
|
173
|
+
"#{pad}#{s}"
|
174
|
+
end
|
175
|
+
}.join( ' ')
|
176
|
+
end
|
155
177
|
end
|
156
178
|
|
157
179
|
def virt v
|
data/lib/pve/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pve
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Knauf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dencli
|
@@ -104,7 +104,6 @@ extra_rdoc_files: []
|
|
104
104
|
files:
|
105
105
|
- ".gitignore"
|
106
106
|
- Gemfile
|
107
|
-
- Gemfile.lock
|
108
107
|
- LICENSE.txt
|
109
108
|
- README.adoc
|
110
109
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
pve (0.2.1)
|
5
|
-
activesupport (>= 2)
|
6
|
-
dencli (~> 0.4)
|
7
|
-
ipaddress (~> 0.8.3)
|
8
|
-
pmap (~> 1.1)
|
9
|
-
rest-client (~> 2.1)
|
10
|
-
|
11
|
-
GEM
|
12
|
-
remote: https://rubygems.org/
|
13
|
-
specs:
|
14
|
-
activesupport (6.1.4.1)
|
15
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
-
i18n (>= 1.6, < 2)
|
17
|
-
minitest (>= 5.1)
|
18
|
-
tzinfo (~> 2.0)
|
19
|
-
zeitwerk (~> 2.3)
|
20
|
-
concurrent-ruby (1.1.9)
|
21
|
-
dencli (0.5.3)
|
22
|
-
diff-lcs (1.4.4)
|
23
|
-
domain_name (0.5.20190701)
|
24
|
-
unf (>= 0.0.5, < 1.0.0)
|
25
|
-
http-accept (1.7.0)
|
26
|
-
http-cookie (1.0.4)
|
27
|
-
domain_name (~> 0.5)
|
28
|
-
i18n (1.8.11)
|
29
|
-
concurrent-ruby (~> 1.0)
|
30
|
-
ipaddress (0.8.3)
|
31
|
-
mime-types (3.4.1)
|
32
|
-
mime-types-data (~> 3.2015)
|
33
|
-
mime-types-data (3.2021.1115)
|
34
|
-
minitest (5.14.4)
|
35
|
-
netrc (0.11.0)
|
36
|
-
pmap (1.1.1)
|
37
|
-
rest-client (2.1.0)
|
38
|
-
http-accept (>= 1.7.0, < 2.0)
|
39
|
-
http-cookie (>= 1.0.2, < 2.0)
|
40
|
-
mime-types (>= 1.16, < 4.0)
|
41
|
-
netrc (~> 0.8)
|
42
|
-
rspec (3.10.0)
|
43
|
-
rspec-core (~> 3.10.0)
|
44
|
-
rspec-expectations (~> 3.10.0)
|
45
|
-
rspec-mocks (~> 3.10.0)
|
46
|
-
rspec-core (3.10.1)
|
47
|
-
rspec-support (~> 3.10.0)
|
48
|
-
rspec-expectations (3.10.1)
|
49
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
-
rspec-support (~> 3.10.0)
|
51
|
-
rspec-mocks (3.10.2)
|
52
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
-
rspec-support (~> 3.10.0)
|
54
|
-
rspec-support (3.10.3)
|
55
|
-
tzinfo (2.0.4)
|
56
|
-
concurrent-ruby (~> 1.0)
|
57
|
-
unf (0.1.4)
|
58
|
-
unf_ext
|
59
|
-
unf_ext (0.0.8)
|
60
|
-
zeitwerk (2.5.1)
|
61
|
-
|
62
|
-
PLATFORMS
|
63
|
-
x86_64-linux
|
64
|
-
|
65
|
-
DEPENDENCIES
|
66
|
-
pve!
|
67
|
-
rspec (~> 3.2)
|
68
|
-
|
69
|
-
BUNDLED WITH
|
70
|
-
2.2.15
|