kanrisuru 0.2.9 → 0.4.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: 5d0fc79a97a3eebddc661982ea4a728af94aded3dbcf5bd5d7d8b0c03e9f5aaf
4
+ data.tar.gz: a37a3d8a00941a4842f3ce0502a1e88fe9ff50343c095f55094dc528f4bddfa4
5
5
  SHA512:
6
- metadata.gz: '08780b59675a42aeea9f523e253c23d393fa745bc66e73a5c79c6c3d6d6fa0462fa3e4ddf388b56668c32f80708671a1d2b9dbd6a9b918d4cecdfae37404a0f9'
7
- data.tar.gz: 07fd46b83cf7b0391ba4729ad16cdcc88e73b2aacc1c7457855833c60ac4b55defd22914fba9f9cbe48bf5df42cad1bf34d2ddefc6db0918d651710cbbe549d2
6
+ metadata.gz: 34521c6c7ed22da194e55037a4c9653717176e1b6526e79c272107fe57c711e5ffbd8a377c48df8008492910297bbe102d21713c41e5c33635264f32c3c5c231
7
+ data.tar.gz: f620bb3a94944cee7c08f0634d43c7b00a4bf00e9c3b64ac13a0934cf8afe01af3439b67dd2d563cecb5134084b2eb9b8845835e22959d00a3639251ffb15f1e
@@ -6,12 +6,13 @@ module Kanrisuru
6
6
  attr_writer :remote_user, :remote_shell, :remote_path, :remote_env
7
7
 
8
8
  def initialize(command)
9
+ @valid_exit_codes = [0]
9
10
  @raw_command = command
10
11
  @raw_result = []
11
12
  end
12
13
 
13
14
  def success?
14
- @exit_status&.zero?
15
+ @valid_exit_codes.include?(@exit_status)
15
16
  end
16
17
 
17
18
  def failure?
@@ -45,8 +46,7 @@ module Kanrisuru
45
46
  end
46
47
 
47
48
  env = @remote_env && !@remote_env.empty? ? "#{@remote_env} " : ''
48
-
49
- "#{env}sudo -u #{@remote_user} #{@remote_shell} -c -l \"#{evaluate}\""
49
+ "#{env}sudo -u #{@remote_user} #{@remote_shell} -c \"#{evaluate}\""
50
50
  else
51
51
  @raw_command
52
52
  end
@@ -95,5 +95,10 @@ module Kanrisuru
95
95
  def append_flag(arg, boolean = 'true')
96
96
  @raw_command = Kanrisuru::Util.present?(boolean) ? "#{@raw_command} #{arg}" : @raw_command
97
97
  end
98
+
99
+ def append_valid_exit_code(code)
100
+ @valid_exit_codes << code if code.instance_of?(Integer)
101
+ @valid_exit_codes.concat(code) if code.instance_of?(Array)
102
+ end
98
103
  end
99
104
  end
@@ -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
@@ -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,79 @@ 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
100
+ end
101
+
102
+ def flags
103
+ @cpu_architecture.flags
52
104
  end
53
105
 
54
106
  def hyperthreading?
@@ -58,10 +110,7 @@ module Kanrisuru
58
110
  private
59
111
 
60
112
  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
113
+ @cpu_architecture = @host.lscpu.data
65
114
  end
66
115
  end
67
116
  end
@@ -16,7 +16,7 @@ module Kanrisuru
16
16
  @username = opts[:username]
17
17
  @login_user = @username
18
18
 
19
- @port = opts[:port]
19
+ @port = opts[:port] || 22
20
20
  @password = opts[:password] if opts[:password]
21
21
  @keys = opts[:keys] if opts[:keys]
22
22
  @shell = opts[:shell] || '/bin/bash'
@@ -84,7 +84,7 @@ module Kanrisuru
84
84
  end
85
85
 
86
86
  def ssh
87
- @ssh ||= Net::SSH.start(@host, @username, keys: @keys, password: @password)
87
+ @ssh ||= Net::SSH.start(@host, @username, keys: @keys, password: @password, port: @port)
88
88
  end
89
89
 
90
90
  def ping?
@@ -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.9'
4
+ VERSION = '0.4.0'
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
 
@@ -24,7 +24,7 @@ RSpec.describe Kanrisuru::Remote::Os do
24
24
 
25
25
  case os_name
26
26
  when 'opensuse'
27
- expect(host.os.release).to eq('opensuse-leap')
27
+ expect(host.os.release).to eq('opensuse_leap')
28
28
  else
29
29
  expect(host.os.release).to eq(os_name)
30
30
  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.4.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-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec