kanrisuru 0.5.2 → 0.7.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: 577077bbfed12648f504d29d8cfc71c3b370c629517a0e245bd9a666d59647de
4
- data.tar.gz: c7172f53feae30e08ed8394077d091733624f0937925cf9e8c2778ef293341bf
3
+ metadata.gz: 4ffb2183c8f1a5610dd416259a663787076f79cb8502fe8656a52d2c2cd1a7e0
4
+ data.tar.gz: 43b63c2e14d7f29356cd110261ef1ba55aabd50e97830e4aea3770429625caf8
5
5
  SHA512:
6
- metadata.gz: 1bb1ae43f1dbb544356c781c76d78abe38a006efae79379f802059d1571c75fb9e67c5ff7ae34aa5ae243591eb96c4f733167aa434683f4a5fcb6b92975ff7fb
7
- data.tar.gz: a7b3cd0fe6804bd1ded0872b2d5cb42bb406cb5bd4572f5e40e689fe352ba2ce81162e5ceddb3cdadc9974217a37c7c4ac877ccb05012dab418fdb5d9117bee1
6
+ metadata.gz: c0b333f36fb00bd16177fe434522c2bd1717db0019d39dba681ab7810b786aca050e6ea79c2647a1bedf4f0bdb4d7e6ffb26079b2ad10d92d3b6da6e4372ee56
7
+ data.tar.gz: 17377294cc356a44b1a76c6d32bae36940d8ec43d31cdbf0716c4d347735a8d30591e94a8babc8f7cd70d68127f7177d6a2dd70015c4eb8132148868e47a227d
@@ -0,0 +1,17 @@
1
+ # How to contribute
2
+ Thank you for your interest in contributing to the Kanrisuru project. We appreciate any volunteers that want to help improve, grow and sustain the Kanrisuru code base!
3
+
4
+ ## Submitting a bug
5
+ * Do not open up a GitHub issue if the bug is a security vulnerability with the Kanrisuru project, instead send an email to engineeering@avamia.com for any security realted issues.
6
+ * Check if there's already an existing issue before submitting a [similar one](https://github.com/avamia/kanrisuru/issues).
7
+ * If you can't find a similar issue [open a new one](https://github.com/avamia/kanrisuru/issues/new?assignees=&labels=&template=bug_report.md). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
8
+
9
+ ## Adding a core feature
10
+ * We always welcome improving the core Kanrisuru project. If we are missing a core command available on most linux distros, this would be a place to add that type of functionality.
11
+ * Other ideas like performance optimization, additional testing, and ease of use are great ways of improving the project.
12
+ * If you want to create something outside of the core project, see the next section.
13
+
14
+ ## Adding a new module
15
+ * If you want to extent Kanrisuru beyond the underlying system code base or core module packages, the best way is to create a new gem, in the format of `kanrisuru-package`.
16
+ * This helps keep the core Kanrisuru package from too much bloat.
17
+ * See our developer module section to see how to build a new Kanrisuru module.
@@ -0,0 +1,33 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior:
15
+ 1. Go to '...'
16
+ 2. Click on '....'
17
+ 3. Scroll down to '....'
18
+ 4. See error
19
+
20
+ **Expected behavior**
21
+ A clear and concise description of what you expected to happen.
22
+
23
+ **Screenshots**
24
+ If applicable, add screenshots to help explain your problem.
25
+
26
+ **Desktop (please complete the following information):**
27
+ - OS: [e.g. Ubuntu]
28
+ - Version [e.g. 22]
29
+ - Ruby version: [e.g 2.7.4]
30
+
31
+
32
+ **Additional context**
33
+ Add any other context about the problem here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
data/.rubocop.yml CHANGED
@@ -20,6 +20,10 @@ Naming/InclusiveLanguage:
20
20
  - lib/kanrisuru/core/dmi.rb
21
21
  - spec/unit/core/dmi_spec.rb
22
22
 
23
+ Naming/MethodParameterName:
24
+ Exclude:
25
+ - spec/functional/os_package_spec.rb
26
+
23
27
  Metrics/AbcSize:
24
28
  Enabled: false
25
29
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,32 @@
1
+ ## Kanrisuru 0.7.2 (August 9, 2021) ##
2
+ * Fixed bug with the `os_method_cache` instance variable set in the namespaced instance of a host. This was causing collision issues inbetween host instances, where, hosts with the same aliased method name was getting overwritten (with a different OS), since the namespace instance variable existing on the host class definition wasn't getting reset inbetween host instantiations. Given that the `os_method_cache` is normally re-instantiated, this bug fix addresses this so that the `os_method_cache` is always defined on the host instance, ie:
3
+
4
+ ```ruby
5
+ host.instance_variable_get(:@os_method_cache)
6
+ host.instance_variable_set(:@os_method_cache, os_method_cache)
7
+ ```
8
+ This is done instead of being saved on the namespace module. With the previous bug fix of using namespaced keys, there's no way for a method to be overwritten otherwise with a global `os_method_cache`.
9
+
10
+ ## Kanrisuru 0.7.1 (August 8, 2021) ##
11
+ * Fix bug with `os_include` when caching namespace unbound methods, use the namespace in the
12
+ cache key to avoid any namespace collisions with the same method name, namely:
13
+ ```ruby
14
+ "#{namespace}.#{method_name}"
15
+ ```
16
+
17
+ ## Kanrisuru 0.7.0 (August 8, 2021) ##
18
+ * Simplify `FileInfo` struct for return object of `ls` command.
19
+ * Rename `size` to `fsize` for the `OpenFile` struct to avoid method naming conflicts of the struct class.
20
+ * Allow `os_include` and `os_collection` to define multiple groupings of methods with the same namespace.
21
+ * Add `clear` method for remote env class, to remove any session based env variables.
22
+ * Add `to_s` method to result for quick analysis of string based return values.
23
+ * Remove duplicate `numeric` method in the utils module.
24
+
25
+ ## Kanrisuru 0.6.0 (August 1, 2021) ##
26
+ * Add `lsof` implementation in system core module
27
+ * Fix changelog formatting
28
+ * Add changelog url to gemspec
29
+
1
30
  ## Kanrisuru 0.5.2 (July 30, 2021) ##
2
31
  * Add changelog documentation
3
32
  * Update documentation table with new tested core module
@@ -37,7 +66,6 @@
37
66
  * Fix `address_size` in `cpu` method call.
38
67
 
39
68
  ## Kanrisuru 0.3.0 (July 22, 2021) ##
40
-
41
69
  * Add `lscpu` system core module
42
70
  * Replace `cpu` module internal fetching of data from `cpu_info` to `lscpu` struct.
43
71
 
@@ -78,7 +106,7 @@
78
106
  ## Kanrisuru 0.2.1 (June 16, 2021) ##
79
107
  * Add first working release on rubygems.org
80
108
 
81
- ## Kanrisuru 0.2.0 (June 16, 2021) [YANKED]##
109
+ ## Kanrisuru 0.2.0 (June 16, 2021) [YANKED] ##
82
110
 
83
111
  ## Kanrisuru 0.1.0 (December 12, 2020) ##
84
112
  * Initialize repository, start working on project.
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
  [![Latest version](https://img.shields.io/github/license/avamia/kanrisuru)](https://github.com/avamia/kanrisuru/blob/main/LICENSE.txt) 
3
3
  ![GitHub repo size](https://img.shields.io/github/repo-size/avamia/kanrisuru) 
4
4
 
5
+ <p align='center'>
6
+ <img src="https://s3.us-east-2.amazonaws.com/kanrisuru.com/kanrisuru-banner-02.png" width="600" />
7
+ </p>
8
+
5
9
  # Kanrisuru
6
10
 
7
11
  Kanrisuru (manage) helps you remotely control infrastructure using Ruby. This is done over SSH. I'm working on building up some basic functionality to help quickly provision, deploy and manage a single host or cluster of hosts.
@@ -81,6 +85,8 @@ cluster.execute('uname') #=> {host: 'host1', result: 'Linux'}, {host: 'host2', r
81
85
  | Get CPU Info | cpu_info | lscpu | core | https://linux.die.net/man/1/lscpu | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
82
86
  | Get CPU architecture | lscpu | lscpu | core | https://linux.die.net/man/1/lscpu | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
83
87
  | Get kernel stastics | kernel_statistics | cat /proc/stat | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
88
+ | Get hardware BIOS info | dmi | dmidecode | core | https://linux.die.net/man/8/dmidecode | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
89
+ | Get open file details for processes | lsof | lsof | core | https://linux.die.net/man/8/lsof | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
84
90
  | Get Load Average | load_average | cat /proc/load_avg | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
85
91
  | Get RAM Available | free | cat /proc/meminfo | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
86
92
  | Get list of processes | ps | ps | core | https://linux.die.net/man/1/ps | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
data/kanrisuru.gemspec CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |gem|
27
27
  gem.require_paths = ['lib']
28
28
 
29
29
  gem.metadata = {
30
- 'source_code_uri' => 'https://github.com/avamia/kanrisuru/'
30
+ 'source_code_uri' => 'https://github.com/avamia/kanrisuru/',
31
+ 'changelog_uri' => 'https://github.com/avamia/kanrisuru/blob/main/CHANGELOG.md'
31
32
  }
32
33
  end
@@ -9,10 +9,10 @@ module Kanrisuru
9
9
 
10
10
  os_define :linux, :ls
11
11
  os_define :linux, :pwd
12
- os_define :linux, :whoami
13
- os_define :linux, :which
14
12
  os_define :linux, :realpath
15
13
  os_define :linux, :readlink
14
+ os_define :linux, :whoami
15
+ os_define :linux, :which
16
16
 
17
17
  FilePath = Struct.new(:path)
18
18
  FileInfoId = Struct.new(:inode, :mode, :memory_blocks, :uid, :gid, :fsize, :date, :path, :type)
@@ -46,7 +46,7 @@ module Kanrisuru
46
46
  type = values[1].include?('d') ? 'directory' : 'file'
47
47
  items <<
48
48
  if id
49
- FileInfoId.new(
49
+ FileInfo.new(
50
50
  values[0].to_i,
51
51
  Kanrisuru::Mode.new(values[1]),
52
52
  values[2].to_i,
@@ -16,6 +16,9 @@ module Kanrisuru
16
16
  os_define :linux, :kill
17
17
 
18
18
  os_define :linux, :kernel_statistics
19
+ os_define :linux, :kstat
20
+
21
+ os_define :linux, :lsof
19
22
 
20
23
  os_define :linux, :uptime
21
24
 
@@ -101,6 +104,18 @@ module Kanrisuru
101
104
 
102
105
  UserLoggedIn = Struct.new(:user, :tty, :ip, :login, :idle, :jcpu, :pcpu, :command)
103
106
 
107
+ OpenFile = Struct.new(
108
+ :command,
109
+ :pid,
110
+ :uid,
111
+ :file_descriptor,
112
+ :type,
113
+ :device,
114
+ :fsize,
115
+ :inode,
116
+ :name
117
+ )
118
+
104
119
  def load_env
105
120
  command = Kanrisuru::Command.new('env')
106
121
  execute_shell(command)
@@ -205,9 +220,9 @@ module Kanrisuru
205
220
  end
206
221
 
207
222
  def cpu_info(spec)
208
- Kanrisuru.logger.info {
223
+ Kanrisuru.logger.info do
209
224
  'DEPRECATION WARNING: cpu_info will be removed in the upcoming major release. Use lscpu instead.'
210
- }
225
+ end
211
226
 
212
227
  name =
213
228
  case spec
@@ -305,6 +320,60 @@ module Kanrisuru
305
320
  Kanrisuru::Result.new(command)
306
321
  end
307
322
 
323
+ def lsof(_opts = {})
324
+ command = Kanrisuru::Command.new('lsof -F pcuftDsin')
325
+
326
+ execute_shell(command)
327
+ Kanrisuru::Result.new(command) do |cmd|
328
+ lines = cmd.to_a
329
+
330
+ current_row = nil
331
+ current_pid = nil
332
+ current_user = nil
333
+ current_command = nil
334
+
335
+ rows = []
336
+
337
+ lines.each do |line|
338
+ case line
339
+ when /^p/
340
+ current_pid = parse_lsof(line, 'p').to_i
341
+ when /^c/
342
+ current_command = parse_lsof(line, 'c')
343
+ when /^u/
344
+ current_user = parse_lsof(line, 'u').to_i
345
+ when /^f/
346
+ rows << current_row if current_row
347
+
348
+ current_row = OpenFile.new
349
+ current_row.pid = current_pid
350
+ current_row.command = current_command
351
+ current_row.uid = current_user
352
+
353
+ current_row.file_descriptor = parse_lsof(line, 'f')
354
+ when /^t/
355
+ current_row.type = parse_lsof(line, 't')
356
+ when /^D/
357
+ current_row.device = parse_lsof(line, 'D')
358
+ when /^s/
359
+ current_row.fsize = parse_lsof(line, 's').to_i
360
+ when /^i/
361
+ current_row.inode = parse_lsof(line, 'i').to_i
362
+ when /^n/
363
+ current_row.name = parse_lsof(line, 'n')
364
+ end
365
+ end
366
+
367
+ rows << current_row if current_row
368
+
369
+ rows
370
+ end
371
+ end
372
+
373
+ def kstat
374
+ kernel_statistics
375
+ end
376
+
308
377
  def kernel_statistics
309
378
  command = Kanrisuru::Command.new('cat /proc/stat')
310
379
 
@@ -494,6 +563,10 @@ module Kanrisuru
494
563
 
495
564
  private
496
565
 
566
+ def parse_lsof(line, char)
567
+ line.split(char, 2)[1]
568
+ end
569
+
497
570
  def parse_policy_abbr(value)
498
571
  case value
499
572
  when '-'
@@ -8,7 +8,6 @@ module Kanrisuru
8
8
  def self.extended(base)
9
9
  base.instance_variable_set(:@os_method_properties, {})
10
10
  base.instance_variable_set(:@os_methods, Set.new)
11
- base.instance_variable_set(:@os_method_cache, {})
12
11
  end
13
12
 
14
13
  def os_define(os_name, method_name, options = {})
@@ -46,13 +45,19 @@ module Kanrisuru
46
45
  ## Define the namespace as an eigen class instance on the host.
47
46
  ## Namespaced instances will access core host methods
48
47
  ## with @host instance variable.
49
- namespace_class = Kanrisuru::Remote::Cluster.const_set(Kanrisuru::Util.camelize(namespace), Class.new)
50
- namespace_instance = Kanrisuru::Remote::Cluster.instance_variable_set("@#{namespace}", namespace_class.new)
51
48
 
52
- class_eval do
53
- define_method namespace do
54
- namespace_instance.instance_variable_set(:@cluster, self)
55
- namespace_instance
49
+ if Kanrisuru::Remote::Cluster.instance_variable_defined?("@#{namespace}")
50
+ namespace_class = Kanrisuru::Remote::Cluster.const_get(Kanrisuru::Util.camelize(namespace))
51
+ namespace_instance = instance_variable_get("@#{namespace}")
52
+ else
53
+ namespace_class = Kanrisuru::Remote::Cluster.const_set(Kanrisuru::Util.camelize(namespace), Class.new)
54
+ namespace_instance = Kanrisuru::Remote::Cluster.instance_variable_set("@#{namespace}", namespace_class.new)
55
+
56
+ class_eval do
57
+ define_method namespace do
58
+ namespace_instance.instance_variable_set(:@cluster, self)
59
+ namespace_instance
60
+ end
56
61
  end
57
62
  end
58
63
 
@@ -96,12 +101,6 @@ module Kanrisuru
96
101
  include_methods = (public_methods + protected_methods + private_methods).flatten
97
102
 
98
103
  include_method_bindings = proc do
99
- define_method 'os_method_cache' do
100
- @os_method_cache ||= {}
101
- end
102
-
103
- private :os_method_cache
104
-
105
104
  include_methods.each do |method_name|
106
105
  define_method method_name do |*args, &block|
107
106
  unbound_method = mod.instance_method(method_name)
@@ -132,17 +131,26 @@ module Kanrisuru
132
131
  ## Define the namespace as an eigen class instance within the host class.
133
132
  ## Namespaced instances will access core host methods
134
133
  ## with @host instance variable.
135
- namespace_class = Kanrisuru::Remote::Host.const_set(Kanrisuru::Util.camelize(namespace), Class.new)
136
- namespace_instance = Kanrisuru::Remote::Host.instance_variable_set("@#{namespace}", namespace_class.new)
137
134
 
138
- namespace_class.class_eval(&include_method_bindings)
135
+ ## Check to see if the namespace was defined. If so, additional methods will be appended to the
136
+ ## existing namespace class definition, otherwise, a new namespace class and instance will be
137
+ ## defined with the methods added.
138
+ if Kanrisuru::Remote::Host.instance_variable_defined?("@#{namespace}")
139
+ namespace_class = Kanrisuru::Remote::Host.const_get(Kanrisuru::Util.camelize(namespace))
140
+ namespace_instance = Kanrisuru::Remote::Host.instance_variable_get("@#{namespace}")
141
+ else
142
+ namespace_class = Kanrisuru::Remote::Host.const_set(Kanrisuru::Util.camelize(namespace), Class.new)
143
+ namespace_instance = Kanrisuru::Remote::Host.instance_variable_set("@#{namespace}", namespace_class.new)
139
144
 
140
- class_eval do
141
- define_method namespace do
142
- namespace_instance.instance_variable_set(:@host, self)
143
- namespace_instance
145
+ class_eval do
146
+ define_method namespace do
147
+ namespace_instance.instance_variable_set(:@host, self)
148
+ namespace_instance
149
+ end
144
150
  end
145
151
  end
152
+
153
+ namespace_class.class_eval(&include_method_bindings)
146
154
  else
147
155
  class_eval(&include_method_bindings)
148
156
  end
@@ -151,14 +159,16 @@ module Kanrisuru
151
159
  os_method_names.each do |method_name|
152
160
  if namespace
153
161
  namespace_class.class_eval do
162
+
154
163
  define_method method_name do |*args, &block|
155
164
  unbound_method = nil
156
165
 
157
- if os_method_cache.key?(method_name)
158
- unbound_method = os_method_cache[method_name]
159
- else
160
- host = namespace_instance.instance_variable_get(:@host)
166
+ host = namespace_instance.instance_variable_get(:@host)
167
+ os_method_cache = host.instance_variable_get(:@os_method_cache) || {}
161
168
 
169
+ if os_method_cache.key?("#{namespace}.#{method_name}")
170
+ unbound_method = os_method_cache["#{namespace}.#{method_name}"]
171
+ else
162
172
  ## Find the correct method to resolve based on the OS for the remote host.
163
173
  defined_method_name = host.resolve_os_method_name(os_method_properties, method_name)
164
174
  unless defined_method_name
@@ -171,7 +181,8 @@ module Kanrisuru
171
181
 
172
182
  ## Cache the unbound method on this host instance for faster resolution on
173
183
  ## the next invocation of this method
174
- os_method_cache[method_name] = unbound_method
184
+ os_method_cache["#{namespace}.#{method_name}"] = unbound_method
185
+ host.instance_variable_set(:@os_method_cache, os_method_cache)
175
186
  end
176
187
 
177
188
  ## Bind the method to host instance and
@@ -182,12 +193,13 @@ module Kanrisuru
182
193
  else
183
194
  define_method method_name do |*args, &block|
184
195
  unbound_method = nil
196
+
197
+ host = self
198
+ os_method_cache = host.instance_variable_get(:@os_method_cache) || {}
185
199
 
186
200
  if os_method_cache.key?(method_name)
187
201
  unbound_method = os_method_cache[method_name]
188
202
  else
189
- host = self
190
-
191
203
  ## Find the correct method to resolve based on the OS for the remote host.
192
204
  defined_method_name = host.resolve_os_method_name(os_method_properties, method_name)
193
205
  raise NoMethodError, "undefined method `#{method_name}' for #{self.class}" unless defined_method_name
@@ -199,6 +211,7 @@ module Kanrisuru
199
211
  ## Cache the unbound method on this host instance for faster resolution on
200
212
  ## the next invocation of this method
201
213
  os_method_cache[method_name] = unbound_method
214
+ host.instance_variable_set(:@os_method_cache, os_method_cache)
202
215
  end
203
216
 
204
217
  ## Bind the method to host instance and
@@ -11,6 +11,10 @@ module Kanrisuru
11
11
  @env
12
12
  end
13
13
 
14
+ def clear
15
+ @env = {}
16
+ end
17
+
14
18
  def to_s
15
19
  string = ''
16
20
  @env.each.with_index do |(key, value), index|
@@ -31,6 +31,10 @@ module Kanrisuru
31
31
  @data[prop]
32
32
  end
33
33
 
34
+ def to_s
35
+ @data.to_s
36
+ end
37
+
34
38
  def to_a
35
39
  @data.instance_of?(Array) ? @data : [@data]
36
40
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.5.2'
4
+ VERSION = '0.7.2'
5
5
  end
@@ -26,14 +26,20 @@ RSpec.describe Kanrisuru::Core::System do
26
26
 
27
27
  it 'gets environment variables' do
28
28
  result = host.load_env
29
-
30
- expect(result.success?).to be(true)
29
+ expect(result).to be_success
31
30
  expect(result.data).to be_instance_of(Hash)
32
31
  end
33
32
 
33
+ it 'gets open files' do
34
+ host.su('root')
35
+ result = host.lsof
36
+ expect(result).to be_success
37
+ expect(result.data).to be_instance_of(Array)
38
+ end
39
+
34
40
  it 'gets uptime' do
35
41
  result = host.uptime
36
- expect(result.success?).to eq(true)
42
+ expect(result).to be_success
37
43
 
38
44
  expect(result).to respond_to(
39
45
  :boot_time, :uptime, :seconds,
@@ -16,7 +16,7 @@ module Kanrisuru
16
16
  module TestNamespace
17
17
  extend Kanrisuru::OsPackage::Define
18
18
 
19
- os_define :unix_like, :tester
19
+ os_define :linux, :tester
20
20
  os_define :centos, :test_not_correct
21
21
 
22
22
  def tester
@@ -25,17 +25,82 @@ module Kanrisuru
25
25
 
26
26
  def test_not_correct; end
27
27
  end
28
+
29
+ module TestNamespaceAdditions
30
+ extend Kanrisuru::OsPackage::Define
31
+
32
+ os_define :linux, :add
33
+ os_define :linux, :minus
34
+
35
+ def add(a, b)
36
+ a + b
37
+ end
38
+
39
+ def minus(a, b)
40
+ a - b
41
+ end
42
+ end
43
+
44
+ module TestAliasNames
45
+ extend Kanrisuru::OsPackage::Define
46
+
47
+ os_define :fedora, :output_fedora, alias: :output
48
+ os_define :debian, :output_debian, alias: :output
49
+ os_define :sles, :output_sles, alias: :output
50
+
51
+ def output_debian
52
+ 'debian'
53
+ end
54
+
55
+ def output_fedora
56
+ 'fedora'
57
+ end
58
+
59
+ def output_sles
60
+ 'sles'
61
+ end
62
+ end
63
+
64
+ module TestAliasNamesNamespace
65
+ extend Kanrisuru::OsPackage::Define
66
+
67
+ os_define :fedora, :output_fedora, alias: :output
68
+ os_define :debian, :output_debian, alias: :output
69
+ os_define :sles, :output_sles, alias: :output
70
+
71
+ def output_debian
72
+ 'debian'
73
+ end
74
+
75
+ def output_fedora
76
+ 'fedora'
77
+ end
78
+
79
+ def output_sles
80
+ 'sles'
81
+ end
82
+ end
28
83
  end
29
84
 
30
85
  module Kanrisuru
31
86
  module Remote
32
87
  class Host
33
88
  os_include Kanrisuru::TestInclude
89
+
90
+ os_include Kanrisuru::TestAliasNames
91
+ os_include Kanrisuru::TestAliasNamesNamespace, namespace: :alias
92
+
93
+ os_include Kanrisuru::TestNamespaceAdditions, namespace: :asdf
34
94
  os_include Kanrisuru::TestNamespace, namespace: :asdf
35
95
  end
36
96
 
37
97
  class Cluster
38
98
  os_collection Kanrisuru::TestInclude
99
+
100
+ os_collection Kanrisuru::TestAliasNames
101
+ os_collection Kanrisuru::TestAliasNamesNamespace, namespace: :alias
102
+
103
+ os_collection Kanrisuru::TestNamespaceAdditions, namespace: :asdf
39
104
  os_collection Kanrisuru::TestNamespace, namespace: :asdf
40
105
  end
41
106
  end
@@ -64,12 +129,65 @@ RSpec.describe Kanrisuru::OsPackage do
64
129
 
65
130
  expect(host).to respond_to(:asdf)
66
131
  expect(host.asdf).to respond_to(:tester)
132
+ expect(host.asdf).to respond_to(:add)
133
+ expect(host.asdf).to respond_to(:minus)
134
+
67
135
  expect(host.asdf.tester).to eq 'hello namespace'
136
+ expect(host.asdf.add(1, 2)).to eq(3)
137
+ expect(host.asdf.minus(3, 2)).to eq(1)
138
+
68
139
  expect(host.tester).to eq('hello ubuntu')
140
+
69
141
  expect { host.asdf.test_not_correct }.to raise_error(NoMethodError)
70
142
  expect(cluster.asdf.tester).to be_instance_of(Array)
71
143
 
72
144
  host.disconnect
145
+ host2.disconnect
146
+ cluster.disconnect
147
+ end
148
+
149
+ it 'includes the correct alias named method' do
150
+ host1 = Kanrisuru::Remote::Host.new(host: 'ubuntu-host', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])
151
+ host2 = Kanrisuru::Remote::Host.new(host: 'centos-host', username: 'centos', keys: ['~/.ssh/id_rsa'])
152
+ host3 = Kanrisuru::Remote::Host.new(host: 'opensuse-host', username: 'opensuse', keys: ['~/.ssh/id_rsa'])
153
+
154
+ cluster = Kanrisuru::Remote::Cluster.new([host1, host2, host3])
155
+
156
+ expect(host1).to respond_to(:output)
157
+ expect(host2).to respond_to(:output)
158
+ expect(host3).to respond_to(:output)
159
+ expect(host1.output).to eq('debian')
160
+ expect(host2.output).to eq('fedora')
161
+ expect(host3.output).to eq('sles')
162
+
163
+ expect(cluster).to respond_to(:output)
164
+ expect(cluster.output).to eq([
165
+ {:host=>"ubuntu-host", :result=>"debian"},
166
+ {:host=>"centos-host", :result=>"fedora"},
167
+ {:host=>"opensuse-host", :result=>"sles"}
168
+ ])
169
+
170
+ expect(host1).to respond_to(:alias)
171
+ expect(host2).to respond_to(:alias)
172
+ expect(host3).to respond_to(:alias)
173
+ expect(host1.alias).to respond_to(:output)
174
+ expect(host2.alias).to respond_to(:output)
175
+ expect(host3.alias).to respond_to(:output)
176
+ expect(host1.alias.output).to eq('debian')
177
+ expect(host2.alias.output).to eq('fedora')
178
+ expect(host3.alias.output).to eq('sles')
179
+
180
+ expect(cluster).to respond_to(:alias)
181
+ expect(cluster.alias).to respond_to(:output)
182
+ expect(cluster.alias.output).to eq([
183
+ {:host=>"ubuntu-host", :result=>"debian"},
184
+ {:host=>"centos-host", :result=>"fedora"},
185
+ {:host=>"opensuse-host", :result=>"sles"}
186
+ ])
187
+
188
+ host1.disconnect
189
+ host2.disconnect
190
+ host3.disconnect
73
191
  cluster.disconnect
74
192
  end
75
193
  end
data/spec/spec_helper.rb CHANGED
@@ -4,7 +4,6 @@ require 'simplecov'
4
4
  SimpleCov.start
5
5
 
6
6
  require 'kanrisuru'
7
-
8
7
  require_relative 'helper/test_hosts'
9
8
 
10
9
  Kanrisuru.logger.level = Logger::WARN
@@ -11,7 +11,7 @@ RSpec.describe Kanrisuru::Core::Apt do
11
11
  expect(Kanrisuru::Core::Apt::PackageOverview.new).to respond_to(
12
12
  :package, :version, :suites, :architecture, :installed, :upgradeable, :automatic
13
13
  )
14
-
14
+
15
15
  expect(Kanrisuru::Core::Apt::PackageDetail.new).to respond_to(
16
16
  :package,
17
17
  :version,
@@ -10,9 +10,9 @@ RSpec.describe Kanrisuru::Core::IP do
10
10
 
11
11
  expect(Kanrisuru::Core::IP::IP_ROUTE_TYPES).to(
12
12
  eq(%w[
13
- unicast unreachable blackhole prohibit local
14
- broadcast throw nat via anycast multicast
15
- ])
13
+ unicast unreachable blackhole prohibit local
14
+ broadcast throw nat via anycast multicast
15
+ ])
16
16
  )
17
17
 
18
18
  expect(Kanrisuru::Core::IP::IPLinkProperty.new).to respond_to(
@@ -13,20 +13,20 @@ RSpec.describe Kanrisuru::Core::Socket do
13
13
  :rmem_alloc, :rcv_buf, :wmem_alloc, :snd_buf,
14
14
  :fwd_alloc, :wmem_queued, :ropt_mem, :back_log, :sock_drop
15
15
  )
16
- expect(Kanrisuru::Core::Socket::TCP_STATES).to eq(
16
+ expect(Kanrisuru::Core::Socket::TCP_STATES).to eq(
17
17
  %w[
18
18
  established syn-sent syn-recv
19
19
  fin-wait-1 fin-wait-2 time-wait
20
20
  closed close-wait last-ack listening closing
21
21
  ]
22
22
  )
23
- expect(Kanrisuru::Core::Socket::OTHER_STATES).to eq(
23
+ expect(Kanrisuru::Core::Socket::OTHER_STATES).to eq(
24
24
  %w[
25
25
  all connected synchronized bucket syn-recv
26
26
  big
27
27
  ]
28
28
  )
29
- expect(Kanrisuru::Core::Socket::TCP_STATE_ABBR).to eq(
29
+ expect(Kanrisuru::Core::Socket::TCP_STATE_ABBR).to eq(
30
30
  {
31
31
  'ESTAB' => 'established', 'LISTEN' => 'listening', 'UNCONN' => 'unconnected',
32
32
  'SYN-SENT' => 'syn-sent', 'SYN-RECV' => 'syn-recv', 'FIN-WAIT-1' => 'fin-wait-1',
@@ -75,5 +75,16 @@ RSpec.describe Kanrisuru::Core::System do
75
75
  expect(Kanrisuru::Core::System::UserLoggedIn.new).to respond_to(
76
76
  :user, :tty, :ip, :login, :idle, :jcpu, :pcpu, :command
77
77
  )
78
+ expect(Kanrisuru::Core::System::OpenFile.new).to respond_to(
79
+ :command,
80
+ :pid,
81
+ :uid,
82
+ :file_descriptor,
83
+ :type,
84
+ :device,
85
+ :fsize,
86
+ :inode,
87
+ :name
88
+ )
78
89
  end
79
90
  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.5.2
4
+ version: 0.7.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-30 00:00:00.000000000 Z
11
+ date: 2021-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -114,6 +114,9 @@ executables: []
114
114
  extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
+ - ".github/CONTRIBUTING.md"
118
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
119
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
117
120
  - ".gitignore"
118
121
  - ".rspec"
119
122
  - ".rubocop.yml"
@@ -226,6 +229,7 @@ licenses:
226
229
  - MIT
227
230
  metadata:
228
231
  source_code_uri: https://github.com/avamia/kanrisuru/
232
+ changelog_uri: https://github.com/avamia/kanrisuru/blob/main/CHANGELOG.md
229
233
  post_install_message:
230
234
  rdoc_options: []
231
235
  require_paths: