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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d4403d2c47d0a7ad1227316669d3144c80e220c7ec06b78231d9dfba40dd15c
4
- data.tar.gz: 82d428b604bc88d4ad9d4db5c81eee48f235ff0dbac632ae4c73d6b2bd44e253
3
+ metadata.gz: 0af90de01a1f74dac6c799494f4e70fe13b534fc3b3bf95f3b333aa801d117e8
4
+ data.tar.gz: d8ce0656f04dec34d33c434093b7982e7cefe22869f8abd3ff4fa2ce574b224a
5
5
  SHA512:
6
- metadata.gz: e6082e769da895cc86203e0d77ff1d3bfaf3a570ace8ae67b5ad575392a5cdc6ab7232b23367a1725d65e53ef4fae5888fed811409aab6a22d108d0a5bea963b
7
- data.tar.gz: c453b9016a30df56c831f5589509805ae60544433ffb8124b9ea44373126e3ec91f57b8c1b1b6ff76e8d6e1caec6a626bdb095c476137207a106303cb756eb24
6
+ metadata.gz: b68f8317b05050d46dc938afd83eea40929bf7628caa2db280f091d111dc26f51a4f4875220938c3b8dcba2b55cd3c48ae5a6db997e65d708027029ce6d5d705
7
+ data.tar.gz: 41dc8f9345162f1003eb27f37f1429fc525073828271dde81716520ad8de1ad01ec806a0154fa1c4582c5cdfe4d030dfd4b8be891482e36e38bc05bc8e52c296
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  *.sw[pomnqrst]
2
2
  *.gem
3
+ Gemfile.lock
data/lib/pve/cli/base.rb CHANGED
@@ -27,6 +27,7 @@ def cli_base
27
27
  lambda {|n| to.virt n }
28
28
  end
29
29
  nodes = node ? Proxmox::Node.find_by_name( name) : Proxmox::Node.all
30
+ nodes.each &push
30
31
  nodes.
31
32
  flat_map {|n| [ Thread.new( n, &:lxc), Thread.new( n, &:qemu) ] }.
32
33
  each {|n| n.value.each &push }
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, "List CTs with status", aliases: [nil], &lambda {|node=nil|
12
+ ct_cli.cmd( :status, "Lists CTs with status", aliases: [nil], &lambda {|target=nil, sort: 'n', node: nil|
13
13
  connect
14
- to = TablizedOutput.new %w[Status HA ID Name Host Uptime CPU Mem/MiB Disk/MiB]
15
- nodes = Proxmox::Node.all
16
- nodes = nodes.select {|n| node == n.name } if node
17
- nodes.each do |n|
18
- n.lxc.each &to.method( :virt)
19
- end
20
- to.print order: [3]
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, "List VMs with status", aliases: [nil], &lambda {|node=nil|
13
+ qm.cmd( :status, "Lists CTs with status", aliases: [nil], &lambda {|target=nil, sort: 'n', node: nil|
14
14
  connect
15
- to = TablizedOutput.new %w[Status HA ID Name Host Uptime CPU Mem/MiB Disk/MiB]
16
- nodes = Proxmox::Node.all
17
- nodes = nodes.select {|n| node == n.name } if node
18
- nodes.each do |n|
19
- n.qemu.each &to.method( :virt)
20
- end
21
- to.print order: [3]
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 "%d B" % v if 512 > v
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
- #return "%.1f %s" % [v, m] if 10 > v
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
- "%d PetiByte" % v
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 '·' if 0 == i
46
- return "%d s" % i if 90 > i
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 "%d mi" % i if 90 > i
60
+ return units '%d ' % i, :mi if 90 > i
49
61
  i /= 60
50
- return "%d hou" % i if 36 > i
62
+ return units '%d ' % i, :hou if 36 > i
51
63
  i /= 24
52
- return "%d days" % i if 14 > i
64
+ return units '%d ' % i, :days if 14 > i
53
65
  j = i / 7
54
- return "%d weeks" % j if 25 > j
55
- i /= 365
56
- return "%.1f years" if 550 > i
57
- "%dy" % i
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
- #ls = ls.sort_by {|e| p e; order.map &e.method(:[]) } if order
153
- @stdout.printf format, *@header.flat_map {|s|['',s]}
154
- ls.each {|l| @stdout.printf format, *l.flat_map {|s| s.is_a?(ColoredString) ? [s.color_codes, s.string] : ["", s.to_s] } }
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
@@ -1,3 +1,3 @@
1
1
  module PVE
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.3'
3
3
  end
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.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-08 00:00:00.000000000 Z
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