kanrisuru 0.2.7 → 0.3.1

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: '02938cd29be8b4f58c3bee34c23a9812f698bba6059527aff428bf33b14d042a'
4
- data.tar.gz: 2dd378d354a441deccc1e5eebfaaa27a45a042ddcadf483a2c5835e55515320c
3
+ metadata.gz: 61ecfd6fb284ffd9a3f3866846d89c8e92ac114ce49838a0613e4df29c69e5cc
4
+ data.tar.gz: 1a782563313983a22f55481d2c6bdb156c312d7ac09e98fbd2d79cc1c8776832
5
5
  SHA512:
6
- metadata.gz: 9e5986e22a6e3f6b0e11d2f1b4b6e6293b0e7ce90b7e5f848f5df27e06569a30060d42257d502c035b46c488ac3f2bad098dd267d180618a5843360ab1e4db7a
7
- data.tar.gz: d13bafb8ee5a585193e3e00a3ba16ab70f3eedad5666c9e4d5eb4036457d9db37cdda608ce9cce49fef978b789b3500e9142263fc1fbcd4aba5d10b1ac93d30a
6
+ metadata.gz: '0253078dba72eb5b276fa42e45afe5e3f397d54192c64dd53fd18c2e9104aa08d6c258f123f613c5987db8efddefc4a068e5dd73c5b9596550b6f5c52f1b1780'
7
+ data.tar.gz: 743ab69e8e58486655d0eeb0549e4490b40ebda8192a0df04ee6bca3f1bdbdf4e9c885e09f61339dffbfe4685125b3e2ed327850d9a356033178547ebbd49ca2
data/kanrisuru.gemspec CHANGED
@@ -9,19 +9,19 @@ Gem::Specification.new do |gem|
9
9
  gem.email = 'ryan@avamia.com'
10
10
  gem.license = 'MIT'
11
11
  gem.summary = 'Manage remote servers over ssh with ruby.'
12
+ gem.description = 'Manage remote servers over ssh with ruby.'
12
13
  gem.homepage = 'https://github.com/avamia/kanrisuru'
13
14
 
14
- gem.required_ruby_version = '>= 2.5.0'
15
- gem.required_rubygems_version = '>= 1.8.11'
15
+ gem.required_ruby_version = '>= 2.5.0'
16
16
 
17
- gem.add_development_dependency 'rspec', '>= 3.10.0'
18
- gem.add_development_dependency 'rubocop', '>= 1.12.1'
19
- gem.add_development_dependency 'rubocop-rspec', '>= 2.2.0'
20
- gem.add_development_dependency 'simplecov', '>= 0.21.2'
17
+ gem.add_development_dependency 'rspec', '~> 3.10'
18
+ gem.add_development_dependency 'rubocop', '~> 1.12'
19
+ gem.add_development_dependency 'rubocop-rspec', '~> 2.2'
20
+ gem.add_development_dependency 'simplecov', '~> 0.21'
21
21
 
22
- gem.add_runtime_dependency 'net-ping', '>= 2.0.8'
23
- gem.add_runtime_dependency 'net-scp', '>= 3.0.0'
24
- gem.add_runtime_dependency 'net-ssh', '>= 6.1.0'
22
+ gem.add_runtime_dependency 'net-ping', '~> 2.0'
23
+ gem.add_runtime_dependency 'net-scp', '~> 3.0'
24
+ gem.add_runtime_dependency 'net-ssh', '~> 6.1'
25
25
 
26
26
  gem.files = `git ls-files`.split("\n")
27
27
  gem.require_paths = ['lib']
@@ -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
@@ -341,8 +341,11 @@ module Kanrisuru
341
341
  end
342
342
  end
343
343
 
344
- current_row.description = description.strip
345
- rows << current_row
344
+ if current_row
345
+ current_row.description = description.strip
346
+ rows << current_row
347
+ end
348
+
346
349
  rows
347
350
  end
348
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.2.7'
4
+ VERSION = '0.3.1'
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,114 +1,114 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kanrisuru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.3.1
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-18 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
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.10.0
19
+ version: '3.10'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 3.10.0
26
+ version: '3.10'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubocop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.12.1
33
+ version: '1.12'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.12.1
40
+ version: '1.12'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rubocop-rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.2.0
47
+ version: '2.2'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 2.2.0
54
+ version: '2.2'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.21.2
61
+ version: '0.21'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.21.2
68
+ version: '0.21'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: net-ping
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 2.0.8
75
+ version: '2.0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 2.0.8
82
+ version: '2.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: net-scp
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 3.0.0
89
+ version: '3.0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 3.0.0
96
+ version: '3.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: net-ssh
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 6.1.0
103
+ version: '6.1'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 6.1.0
111
- description:
110
+ version: '6.1'
111
+ description: Manage remote servers over ssh with ruby.
112
112
  email: ryan@avamia.com
113
113
  executables: []
114
114
  extensions: []
@@ -218,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
218
  requirements:
219
219
  - - ">="
220
220
  - !ruby/object:Gem::Version
221
- version: 1.8.11
221
+ version: '0'
222
222
  requirements: []
223
223
  rubygems_version: 3.1.2
224
224
  signing_key: