kanrisuru 0.2.8 → 0.3.2

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: 34a295375b187db49db38cccaa4fdd155d706378b1615d58744aa62f9172cada
4
- data.tar.gz: ed2e0995c40b0fa3902100377bb275e1413d98caf13bbd60b04bceb122d81301
3
+ metadata.gz: 11e237cfa6bdcf5f231733fab93be901be7a6d53ed673eb2feeb54ae4baf2b14
4
+ data.tar.gz: 79e61aafc54f47534a79600ac60a93ec0b9dd82033a2875f84d6ee339ae8fec1
5
5
  SHA512:
6
- metadata.gz: df90e5eca434eb978f0396919571f08c976aed094f096b62988368fcc93b2a1177c46e947aceb732273f420cd28d7ebd8ccf4db532398ddbdd87e7d4ccf8afc6
7
- data.tar.gz: 8c0b99e559e4f50610532dc57ef5ff0bb544259deac214cf03edcab3463f904e5935bcc4e6cdf041a4b231a44476df51084d3ba7570d8d4978dae14c31ca31d8
6
+ metadata.gz: f762e2d07da08086f33ff878652d3f459a5cfcc7e76fdaeebfbfc0c37d827953ba20536bb6e714b751809505961ebd657716bde47af6d2c0975852d5772d6f03
7
+ data.tar.gz: b4a05943b967a4ddddcc0b29c2036a50997463279dee649831efb64f775aabdf0fa384f03732fa06d0cbcb07e061f59c9046b4e812b1e8faed218a12677b36ad
data/kanrisuru.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.description = 'Manage remote servers over ssh with ruby.'
13
13
  gem.homepage = 'https://github.com/avamia/kanrisuru'
14
14
 
15
- gem.required_ruby_version = '>= 2.5.0'
15
+ gem.required_ruby_version = '>= 2.5.0'
16
16
 
17
17
  gem.add_development_dependency 'rspec', '~> 3.10'
18
18
  gem.add_development_dependency 'rubocop', '~> 1.12'
@@ -16,7 +16,6 @@ require_relative 'core/ip'
16
16
  require_relative 'core/socket'
17
17
  require_relative 'core/apt'
18
18
  require_relative 'core/yum'
19
- require_relative 'core/zypper'
20
19
 
21
20
  module Kanrisuru
22
21
  module Remote
@@ -37,7 +36,6 @@ module Kanrisuru
37
36
  os_include Kanrisuru::Core::Socket
38
37
  os_include Kanrisuru::Core::Apt
39
38
  os_include Kanrisuru::Core::Yum
40
- os_include Kanrisuru::Core::Zypper
41
39
  end
42
40
 
43
41
  class Cluster
@@ -56,7 +54,6 @@ module Kanrisuru
56
54
  os_collection Kanrisuru::Core::Socket
57
55
  os_collection Kanrisuru::Core::Apt
58
56
  os_collection Kanrisuru::Core::Yum
59
- os_collection Kanrisuru::Core::Zypper
60
57
  end
61
58
  end
62
59
  end
@@ -44,6 +44,7 @@ module Kanrisuru
44
44
  date = DateTime.parse("#{values[6]} #{values[7]} #{values[8]}")
45
45
 
46
46
  type = values[1].include?('d') ? 'directory' : 'file'
47
+
47
48
  items <<
48
49
  if id
49
50
  FileInfoId.new(
@@ -9,6 +9,7 @@ module Kanrisuru
9
9
 
10
10
  os_define :linux, :load_env
11
11
  os_define :linux, :cpu_info
12
+ os_define :linux, :lscpu
12
13
  os_define :linux, :load_average
13
14
  os_define :linux, :free
14
15
  os_define :linux, :ps
@@ -22,6 +23,43 @@ module Kanrisuru
22
23
  os_define :linux, :reboot
23
24
  os_define :linux, :poweroff
24
25
 
26
+ CPUArchitectureVulnerability = Struct.new(
27
+ :name,
28
+ :data
29
+ )
30
+
31
+ CPUArchitecture = Struct.new(
32
+ :architecture,
33
+ :cores,
34
+ :byte_order,
35
+ :address_sizes,
36
+ :operation_modes,
37
+ :online_cpus,
38
+ :threads_per_core,
39
+ :cores_per_socket,
40
+ :sockets,
41
+ :numa_mode,
42
+ :vendor_id,
43
+ :cpu_family,
44
+ :model,
45
+ :model_name,
46
+ :stepping,
47
+ :cpu_mhz,
48
+ :cpu_max_mhz,
49
+ :cpu_min_mhz,
50
+ :bogo_mips,
51
+ :virtualization,
52
+ :hypervisor_vendor,
53
+ :virtualization_type,
54
+ :l1d_cache,
55
+ :l1i_cache,
56
+ :l2_cache,
57
+ :l3_cache,
58
+ :numa_nodes,
59
+ :vulnerabilities,
60
+ :flags
61
+ )
62
+
25
63
  ProcessInfo = Struct.new(
26
64
  :uid, :user, :gid, :group, :ppid, :pid,
27
65
  :cpu_usage, :memory_usage, :stat, :priority,
@@ -52,6 +90,91 @@ module Kanrisuru
52
90
  end
53
91
  end
54
92
 
93
+ def lscpu
94
+ command = Kanrisuru::Command.new('lscpu')
95
+
96
+ execute_shell(command)
97
+
98
+ Kanrisuru::Result.new(command) do |cmd|
99
+ lines = cmd.to_a
100
+
101
+ result = CPUArchitecture.new
102
+ result.vulnerabilities = []
103
+ result.numa_nodes = []
104
+
105
+ lines.each do |line|
106
+ values = line.split(': ', 2)
107
+
108
+ field = values[0].strip
109
+ data = values[1].strip
110
+
111
+ case field
112
+ when 'Architecture'
113
+ result.architecture = data
114
+ when 'CPU op-mode(s)'
115
+ result.operation_modes = data.split(', ')
116
+ when 'Byte Order'
117
+ result.byte_order = data
118
+ when 'Address sizes'
119
+ result.address_sizes = data.split(', ')
120
+ when 'CPU(s)'
121
+ result.cores = data.to_i
122
+ when 'On-line CPU(s) list'
123
+ result.online_cpus = data.to_i
124
+ when 'Thread(s) per core'
125
+ result.threads_per_core = data.to_i
126
+ when 'Core(s) per socket'
127
+ result.cores_per_socket = data.to_i
128
+ when 'Socket(s)'
129
+ result.sockets = data.to_i
130
+ when 'NUMA node(s)'
131
+ result.numa_nodes = data.to_i
132
+ when 'Vendor ID'
133
+ result.vendor_id = data
134
+ when 'CPU family'
135
+ result.cpu_family = data.to_i
136
+ when 'Model'
137
+ result.model = data.to_i
138
+ when 'Model name'
139
+ result.model_name = data
140
+ when 'Stepping'
141
+ result.stepping = data.to_i
142
+ when 'CPU MHz'
143
+ result.cpu_mhz = data.to_f
144
+ when 'CPU max MHz'
145
+ result.cpu_max_mhz = data.to_f
146
+ when 'CPU min MHz'
147
+ result.cpu_min_mhz = data.to_f
148
+ when 'CPUBogoMIPS'
149
+ result.bogo_mips = data.to_f
150
+ when 'Virtualization'
151
+ result.virtualization = data
152
+ when 'Hypervisor vendor'
153
+ result.hypervisor_vendor = data
154
+ when 'Virtualization type'
155
+ result.virtualization_type = data
156
+ when 'L1d cache'
157
+ result.l1d_cache = data
158
+ when 'L1i cache'
159
+ result.l1i_cache = data
160
+ when 'L2 cache'
161
+ result.l2_cache = data
162
+ when 'L3 cache'
163
+ result.l3_cache = data
164
+ when /^Numa node/
165
+ result.numa_nodes << data.split(',')
166
+ when /^Vulnerability/
167
+ name = field.split('Vulnerability ')[1]
168
+ result.vulnerabilities << CPUArchitectureVulnerability.new(name, data)
169
+ when 'Flags'
170
+ result.flags = data.split
171
+ end
172
+ end
173
+
174
+ result
175
+ end
176
+ end
177
+
55
178
  def cpu_info(spec)
56
179
  name =
57
180
  case spec
@@ -345,7 +345,7 @@ module Kanrisuru
345
345
  current_row.description = description.strip
346
346
  rows << current_row
347
347
  end
348
-
348
+
349
349
  rows
350
350
  end
351
351
  end
@@ -28,27 +28,75 @@ module Kanrisuru
28
28
  end
29
29
 
30
30
  def sockets
31
- @sockets_count
31
+ @cpu_architecture.sockets
32
32
  end
33
33
 
34
34
  def cores
35
- @logical_cores_count
35
+ @cpu_architecture.cores
36
36
  end
37
37
 
38
38
  def total
39
- @logical_cores_count
39
+ @cpu_architecture.cores
40
40
  end
41
41
 
42
42
  def count
43
- @logical_cores_count
43
+ @cpu_architecture.cores
44
44
  end
45
45
 
46
46
  def threads_per_core
47
- @threads_per_core_count
47
+ @cpu_architecture.threads_per_core
48
48
  end
49
49
 
50
50
  def cores_per_socket
51
- @cores_per_socket_count
51
+ @cpu_architecture.cores_per_socket
52
+ end
53
+
54
+ def numa_nodes
55
+ @cpu_architecture.numa_nodes
56
+ end
57
+
58
+ def vendor_id
59
+ @cpu_architecture.vendor_id
60
+ end
61
+
62
+ def cpu_family
63
+ @cpu_architecture.cpu_family
64
+ end
65
+
66
+ def model
67
+ @cpu_architecture.model
68
+ end
69
+
70
+ def model_name
71
+ @cpu_architecture.model_name
72
+ end
73
+
74
+ def byte_order
75
+ @cpu_architecture.byte_order
76
+ end
77
+
78
+ def address_size
79
+ @cpu_architecture.address_size
80
+ end
81
+
82
+ def cpu_mhz
83
+ @cpu_architecture.cpu_mhz
84
+ end
85
+
86
+ def cpu_max_mhz
87
+ @cpu_architecture.cpu_max_mhz
88
+ end
89
+
90
+ def cpu_min_mhz
91
+ @cpu_architecture.cpu_min_mhz
92
+ end
93
+
94
+ def hypervisor
95
+ @cpu_architecture.hypervisor_vendor
96
+ end
97
+
98
+ def virtualization_type
99
+ @cpu_architecture.virtualization_type
52
100
  end
53
101
 
54
102
  def hyperthreading?
@@ -58,10 +106,7 @@ module Kanrisuru
58
106
  private
59
107
 
60
108
  def initialize_linux
61
- @sockets_count = @host.cpu_info('sockets').to_i
62
- @cores_per_socket_count = @host.cpu_info('cores_per_socket').to_i
63
- @threads_per_core_count = @host.cpu_info('threads').to_i
64
- @logical_cores_count = @host.cpu_info('cores').to_i
109
+ @cpu_architecture = @host.lscpu.data
65
110
  end
66
111
  end
67
112
  end
@@ -67,7 +67,7 @@ module Kanrisuru
67
67
  def append_file!
68
68
  @file.append do |f|
69
69
  @entries.each do |_, entry|
70
- f << entry.to_s if entry[:new]
70
+ f << entry[:entry].to_s if entry[:new]
71
71
  end
72
72
  end
73
73
 
@@ -78,13 +78,22 @@ module Kanrisuru
78
78
  def write_file!
79
79
  @file.write do |f|
80
80
  @entries.each do |_, entry|
81
- f << entry.to_s
81
+ f << entry[:entry].to_s
82
82
  end
83
83
  end
84
84
 
85
85
  reload!
86
86
  end
87
87
 
88
+ def to_s
89
+ lines = []
90
+ @entries.each do |_, entry|
91
+ lines << entry[:entry].to_s
92
+ end
93
+
94
+ lines.join("\n")
95
+ end
96
+
88
97
  def reload!
89
98
  init_from_os
90
99
  end
@@ -13,11 +13,11 @@ module Kanrisuru
13
13
  case unit.downcase
14
14
  when 'b'
15
15
  Kanrisuru::Util::Bits.convert_bytes(size, :byte, :kilobyte)
16
- when 'kb', 'k', 'kib'
16
+ when 'kb', 'k'
17
17
  size
18
- when 'mb', 'm', 'mib'
18
+ when 'mb', 'm'
19
19
  Kanrisuru::Util::Bits.convert_from_mb(size, :kilobyte).to_i
20
- when 'gb', 'g', 'gib'
20
+ when 'gb', 'g'
21
21
  Kanrisuru::Util::Bits.convert_from_gb(size, :kilobyte).to_i
22
22
  end
23
23
  end
@@ -136,7 +136,7 @@ module Kanrisuru
136
136
  def self.[](signal)
137
137
  return unless valid?(signal)
138
138
 
139
- if key.instance_of?(Integer)
139
+ if signal.instance_of?(Integer)
140
140
  @linux_inverted[signal]
141
141
  else
142
142
  @linux[translate(signal)]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.2.8'
4
+ VERSION = '0.3.2'
5
5
  end
@@ -18,6 +18,12 @@ RSpec.describe Kanrisuru::Core::System do
18
18
  host.disconnect
19
19
  end
20
20
 
21
+ it 'gets cpu details' do
22
+ result = host.lscpu
23
+ expect(result).to be_success
24
+ expect(result.data).to be_instance_of(Kanrisuru::Core::System::CPUArchitecture)
25
+ end
26
+
21
27
  it 'gets environment variables' do
22
28
  result = host.load_env
23
29
 
@@ -16,6 +16,22 @@ RSpec.describe Kanrisuru::Remote::Fstab do
16
16
  host.disconnect
17
17
  end
18
18
 
19
+ it 'outputs string version of fstab' do
20
+ host.su('root')
21
+
22
+ result = host.cat('/etc/fstab')
23
+ expect(result).to be_success
24
+ raw_file_lines = []
25
+ result.each do |line|
26
+ next if line.match(/^#/) || line == ''
27
+
28
+ raw_file_lines << line.split.join(' ')
29
+ end
30
+
31
+ raw_file_output = raw_file_lines.join("\n")
32
+ expect(raw_file_output).to eq(host.fstab.to_s)
33
+ end
34
+
19
35
  it 'parses fstab' do
20
36
  host.su('root')
21
37
  fstab = host.fstab
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kanrisuru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Mammina
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-20 00:00:00.000000000 Z
11
+ date: 2021-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec