kanrisuru 0.2.9 → 0.3.0

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: 0be09a32fde3ad8b5856c2e4b215d20201a6de1d890f1ede3cf27e471dfd50fd
4
- data.tar.gz: 3573e66a75ce2fc88939e72bda7b915a7469506da713f19f8b80522a35849f58
3
+ metadata.gz: 596f187f09116db8bd36b6eb7a0864f440afdf9e34d784c6215793a5e335f4cd
4
+ data.tar.gz: 0056efd85ffcc42a36bf9086961c3f7438d5716f0cee580587fa48c60af3cfa5
5
5
  SHA512:
6
- metadata.gz: '08780b59675a42aeea9f523e253c23d393fa745bc66e73a5c79c6c3d6d6fa0462fa3e4ddf388b56668c32f80708671a1d2b9dbd6a9b918d4cecdfae37404a0f9'
7
- data.tar.gz: 07fd46b83cf7b0391ba4729ad16cdcc88e73b2aacc1c7457855833c60ac4b55defd22914fba9f9cbe48bf5df42cad1bf34d2ddefc6db0918d651710cbbe549d2
6
+ metadata.gz: f232ff04685236d29e2e8c5c2652ffb7b93e57ca36a7179158787df70553865d7516045e718d03c1bd8e3257a08c793b82941a4cbcb247c39beea667788d57df
7
+ data.tar.gz: af237e0803c4229b008f8ff9b3defae4df00d17af4dab9b51fe3f23797c8af406f4844befe43ed678b99685338a8d2c6e19d7c1e3fea919ccd2082e6059e8576
@@ -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
@@ -28,27 +28,63 @@ 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.byte_order
80
+ end
81
+
82
+ def hypervisor
83
+ @cpu_architecture.hypervisor_vendor
84
+ end
85
+
86
+ def virtualization_type
87
+ @cpu_architecture.virtualization_type
52
88
  end
53
89
 
54
90
  def hyperthreading?
@@ -58,10 +94,7 @@ module Kanrisuru
58
94
  private
59
95
 
60
96
  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
97
+ @cpu_architecture = @host.lscpu.data
65
98
  end
66
99
  end
67
100
  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
@@ -186,7 +186,7 @@ module Kanrisuru
186
186
  model: 'open_source',
187
187
  state: 'current',
188
188
  type: 'distribution'
189
- }
189
+ },
190
190
  }
191
191
 
192
192
  def self.family_include_distribution?(family, dist)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.2.9'
4
+ VERSION = '0.3.0'
5
5
  end
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.9
4
+ version: 0.3.0
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-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec