kanrisuru 0.11.1 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -1
  3. data/CHANGELOG.md +9 -0
  4. data/README.md +13 -88
  5. data/kanrisuru.gemspec +1 -0
  6. data/lib/kanrisuru/command.rb +7 -0
  7. data/lib/kanrisuru/core/archive.rb +11 -35
  8. data/lib/kanrisuru/core/file.rb +4 -11
  9. data/lib/kanrisuru/core/find.rb +2 -6
  10. data/lib/kanrisuru/core/mount.rb +14 -15
  11. data/lib/kanrisuru/core/stream.rb +1 -2
  12. data/lib/kanrisuru/core/zypper.rb +6 -23
  13. data/lib/kanrisuru/os_package/collection.rb +58 -0
  14. data/lib/kanrisuru/os_package/define.rb +34 -0
  15. data/lib/kanrisuru/os_package/include.rb +163 -0
  16. data/lib/kanrisuru/os_package.rb +3 -245
  17. data/lib/kanrisuru/remote/fstab.rb +1 -1
  18. data/lib/kanrisuru/result.rb +5 -4
  19. data/lib/kanrisuru/version.rb +1 -1
  20. data/spec/functional/core/archive_spec.rb +2 -1
  21. data/spec/functional/core/mount_spec.rb +121 -0
  22. data/spec/helper/stub_network.rb +1 -1
  23. data/spec/helper/test_hosts.rb +11 -1
  24. data/spec/integration/core/apt_spec.rb +2 -3
  25. data/spec/integration/core/archive_spec.rb +8 -13
  26. data/spec/integration/core/disk_spec.rb +2 -3
  27. data/spec/integration/core/dmi_spec.rb +2 -3
  28. data/spec/integration/core/file_spec.rb +4 -13
  29. data/spec/integration/core/find_spec.rb +2 -3
  30. data/spec/integration/core/group_spec.rb +2 -3
  31. data/spec/integration/core/ip_spec.rb +2 -3
  32. data/spec/integration/core/path_spec.rb +2 -3
  33. data/spec/integration/core/socket_spec.rb +2 -4
  34. data/spec/integration/core/stat_spec.rb +2 -3
  35. data/spec/integration/core/stream_spec.rb +6 -9
  36. data/spec/integration/core/system_spec.rb +2 -3
  37. data/spec/integration/core/transfer_spec.rb +4 -9
  38. data/spec/integration/core/user_spec.rb +2 -4
  39. data/spec/integration/core/yum_spec.rb +2 -3
  40. data/spec/integration/core/zypper_spec.rb +2 -3
  41. data/spec/integration/remote/cpu_spec.rb +2 -3
  42. data/spec/integration/remote/env_spec.rb +2 -3
  43. data/spec/integration/remote/fstab_spec.rb +2 -3
  44. data/spec/integration/remote/host_spec.rb +2 -3
  45. data/spec/integration/remote/memory_spec.rb +2 -2
  46. data/spec/integration/remote/os_spec.rb +2 -3
  47. data/spec/integration/remote/remote_file_spec.rb +9 -15
  48. data/spec/spec_helper.rb +12 -3
  49. data/spec/unit/command_spec.rb +18 -0
  50. metadata +21 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb936ab5bcccbaa1d4f4b3d97b7bd810aba4e0a1915027e87d5e62fdb1bc8fbb
4
- data.tar.gz: 5ea1754c5c23dbc4c1d3af3ee922e840b60ac4938573528e66773405d183f60d
3
+ metadata.gz: f1401e8534eead10f860fbe8c4bd90397571d391ff4581c74d8ae427e4c32afa
4
+ data.tar.gz: bbba84a50446bc323ff21980c65ef1a0ff14dc316b8f731da0ee55c914ea2160
5
5
  SHA512:
6
- metadata.gz: 2af6ba4a5774c8f78fe051aaa0cb57ddcb4914d3c633e5b47febfa84d9291ae421f317d800faca714c8442574d77150e6a2b5d3c4dfc308a93dc538e666a83c5
7
- data.tar.gz: 3b8316665eba3a34c3f961c890df1be79f1cb3772a7dbd1838cda6dfe1b2b5db983476122ef8e0f1f3262fba5e8d0580821006f8f39181112a3b03f0fe0ad7b5
6
+ metadata.gz: 3f89283777add5671cbb00d7294c204911aa8591a00582c11c560df1091be1cb459afe94450d468b2f85c17df3883805fb1776b2f49ef85846bbc2664c49a10e
7
+ data.tar.gz: 653788aa5d5f84a4290b7462437ce1cdc42be954b834c0c2398a7704ac8b3b0346718fbb0b423ad1770579960c8b3a371c6f6fc4b5688dabb75c175e55ea26d3
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --format documentation
1
+ --format progress
2
2
  --color
3
3
  --require spec_helper
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## Kanrisuru 0.12.0 (December 05, 20201) ##
2
+ * Add functional test cases for `mount` command.
3
+ * Fix typos and command preperation for `mount` command.
4
+ * Refactor `os_package` module into smaller modules for `Kanrisuru::OsPackage::Collection`, `Kanrisuru::OsPackage::Define`, and `Kanrisuru::OsPackage::Include`.
5
+ * Add `append_array` to `command` class for easy string to array conversion for variable option passing.
6
+ * Cleanup bad coding styles.
7
+ * Add parallel testing support for long running integration tests on remote servers.
8
+ * Refactor specs to use variable spec_dir path for parallel testing on remote hosts with possible overwriting at the same time.
9
+
1
10
  ## Kanrisuru 0.11.1 (December 04, 2021) ##
2
11
  * Cleanup self-assignment branches
3
12
  * Fix linting issues.
data/README.md CHANGED
@@ -1,13 +1,20 @@
1
- [![Latest version](https://img.shields.io/gem/v/kanrisuru?style=flat-square)](https://rubygems.org/gems/kanrisuru) 
2
- [![Latest version](https://img.shields.io/github/license/avamia/kanrisuru)](https://github.com/avamia/kanrisuru/blob/main/LICENSE.txt) 
3
- ![GitHub repo size](https://img.shields.io/github/repo-size/avamia/kanrisuru) 
4
- ![Codecov](https://img.shields.io/codecov/c/gh/avamia/kanrisuru?token=2Q1BE106B2) 
5
- ![Codacy grade](https://img.shields.io/codacy/grade/9e839eb160bc445ea4e81b64cef22b27) 
6
-
7
1
  <p align='center'>
8
2
  <img src="https://s3.us-east-2.amazonaws.com/kanrisuru.com/kanrisuru-banner-02.png" width="600" />
9
3
  </p>
10
4
 
5
+ <p align="center">
6
+ <a href="https://rubygems.org/gems/kanrisuru">
7
+ <img src="https://img.shields.io/gem/v/kanrisuru?style=flat-square" alt="Latest version" />
8
+ </a>
9
+ <a href="https://github.com/avamia/kanrisuru/blob/main/LICENSE.txt">
10
+ <img src="https://img.shields.io/github/license/avamia/kanrisuru" alt="Latest version" />
11
+ </a>
12
+ <img src="https://img.shields.io/github/repo-size/avamia/kanrisuru" alt="GitHub repo size" />
13
+ <img src="https://img.shields.io/codecov/c/gh/avamia/kanrisuru?token=2Q1BE106B2" alt="Codecov" />
14
+ <img src="https://img.shields.io/codacy/grade/9e839eb160bc445ea4e81b64cef22b27" alt="Codacy grade" />
15
+ <img src="https://img.shields.io/codeclimate/maintainability/avamia/kanrisuru" alt="Code Climate maintainability" />
16
+ </p>
17
+
11
18
  # Kanrisuru
12
19
 
13
20
  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.
@@ -82,88 +89,6 @@ cluster = Kanrisuru::Remote::Cluster.new(host, {host: 'host2', username: 'alice'
82
89
  cluster.execute('uname') #=> {host: 'host1', result: 'Linux'}, {host: 'host2', result: 'Linux'}
83
90
  ```
84
91
 
85
- ## Methods and Testing
86
-
87
- | Description | Ruby | Shell | Module | Man | Debian | Ubuntu | Fedora | Centos | RHEL | openSUSE | SLES |
88
- |---------------------------------------|------------------|--------------------|--------|--------------------------------------|--------|--------|--------|--------|------|----------|------|
89
- | **System** | | | | | | | | | | | |
90
- | Get CPU Info | cpu_info | lscpu | core | https://linux.die.net/man/1/lscpu | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
91
- | Get CPU architecture | lscpu | lscpu | core | https://linux.die.net/man/1/lscpu | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
92
- | Get kernel stastics | kernel_statistics | cat /proc/stat | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
93
- | Get hardware BIOS info | dmi | dmidecode | core | https://linux.die.net/man/8/dmidecode | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
94
- | Get open file details for processes | lsof | lsof | core | https://linux.die.net/man/8/lsof | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
95
- | Get Load Average | load_average | cat /proc/load_avg | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
96
- | Get RAM Available | free | cat /proc/meminfo | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
97
- | Get list of processes | ps | ps | core | https://linux.die.net/man/1/ps | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
98
- | Get Env vars | load_env | env | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
99
- | Kill process | kill | kill | core | https://linux.die.net/man/1/kill | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
100
- | Get uptime of system | uptime | cat /proc/uptime | core | https://linux.die.net/man/1/uptime | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
101
- | Get who's logged in | w | w | core | https://linux.die.net/man/1/w | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
102
- | Reboot machine | reboot | shutdown | core | https://linux.die.net/man/8/reboot | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
103
- | Poweroff machine | poweroff | shutdown | core | https://linux.die.net/man/8/shutdown | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
104
- | **Disk** | | | | | | | | | | | |
105
- | Get Disk Space | df | df | core | https://linux.die.net/man/1/df | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
106
- | Get Disk Usage | du | du | core | https://linux.die.net/man/1/du | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
107
- | List block devices | lsblk | lsblk | core | https://linux.die.net/man/8/lsblk | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
108
- | Get block device attributes | blkid | blikd | core | https://linux.die.net/man/8/blkid | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
109
- | **Mount** | | | | | | | | | | | |
110
- | Mount a filesystem | mount | mount | core | https://linux.die.net/man/8/mount | | | | | | | |
111
- | Unmount a filesystem | umount | umount | core | https://linux.die.net/man/8/umount | | | | | | | |
112
- | **Group** | | | | | | | | | | | |
113
- | Get Group Id | get_gid | getent group | core | https://linux.die.net/man/1/getent | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
114
- | Get Group | get_group | grep /etc/group | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
115
- | Create Group | create_group | groupadd | core | https://linux.die.net/man/8/groupadd | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
116
- | Update Group | update_group | groupmod | core | https://linux.die.net/man/8/groupmod | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
117
- | Delete Group | delete_group | groupdel | core | https://linux.die.net/man/8/groupdel | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
118
- | **User** | | | | | | | | | | | |
119
- | Get User Id | get_uid | id -u | core | https://linux.die.net/man/1/id | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
120
- | Get User | get_user | id | core | https://linux.die.net/man/1/id | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
121
- | Create User | create_user | useradd | core | https://linux.die.net/man/8/useradd | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
122
- | Update User | update_user | usermod | core | https://linux.die.net/man/8/usermod | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
123
- | Delete User | delete_user | userdel | core | https://linux.die.net/man/8/userdel | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
124
- | **Path** | | | | | | | | | | | |
125
- | List files and directories | ls | ls | core | https://linux.die.net/man/1/ls | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
126
- | Get Current Dir | pwd | pwd | core | https://linux.die.net/man/1/pwd | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
127
- | Get Current User | whoami | whoami | core | https://linux.die.net/man/1/whoami | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
128
- | Get Full Path of Shell Command | which | which | core | https://linux.die.net/man/1/which | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
129
- | Real Path | realpath | realpath | core | https://linux.die.net/man/1/realpath | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
130
- | Read link | readlink | readlink | core | https://linux.die.net/man/1/readlink | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
131
- | Change Dir | cd | cd | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
132
- | **File** | | | | | | | | | | | |
133
- | "Find file, dir, special file device" | find | find | core | https://linux.die.net/man/1/find | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
134
- | Stat file info | stat | stat | core | https://linux.die.net/man/1/stat | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
135
- | Change Permission of file / folder | chmod | chmod | core | https://linux.die.net/man/1/chmod | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
136
- | Change Ownership of file / folder | chown | chown | core | https://linux.die.net/man/1/chown | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
137
- | Hard Link File | ln | ln | core | https://linux.die.net/man/1/ln | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
138
- | Soft Link File / Dir | ln_s | ln | core | https://linux.die.net/man/1/ln | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
139
- | Create Directory | mkdir | mkdir | core | https://linux.die.net/man/1/mkdir | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
140
- | Remove file / directory | rm | rm | core | https://linux.die.net/man/1/rm | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
141
- | Remove Directory | rmdir | rm | core | https://linux.die.net/man/1/rm | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
142
- | Touch File | touch | touch | core | https://linux.die.net/man/1/touch | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
143
- | Copy file / directory | cp | cp | core | https://linux.die.net/man/1/cp | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
144
- | Move file / directory | mv | mv | core | https://linux.die.net/man/1/mv | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
145
- | "Get file line, word, and char count" | wc | wc | core | https://linux.die.net/man/1/wc | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
146
- | **Stream** | | | | | | | | | | | |
147
- | Get content from beginning of file | head | head | core | https://linux.die.net/man/1/head | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
148
- | Get content from end of file | tail | tail | core | https://linux.die.net/man/1/tail | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
149
- | Read a chunk from a file by lines | reach_file_chunk | tail and head | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
150
- | Echo to stdout or to file | echo | echo | core | https://linux.die.net/man/1/echo | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
151
- | Get all content from a file | cat | cat | core | https://linux.die.net/man/1/cat | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
152
- | Sed | sed | sed | core | https://linux.die.net/man/1/sed | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
153
- | **Archive** | | | | | | | | | | | |
154
- | Tar Files | tar | tar | core | https://linux.die.net/man/1/tar | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
155
- | **Network** | | | | | | | | | | | |
156
- | Manage network devices | ip | ip | core | https://linux.die.net/man/8/ip | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
157
- | Get Socket Details | ss | ss | core | https://linux.die.net/man/8/ss | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
158
- | **Transfer** | | | | | | | | | | | |
159
- | Upload to remote server | upload | scp | core | https://linux.die.net/man/1/scp | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
160
- | Download from remote server | download | scp | core | https://linux.die.net/man/1/scp | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
161
- | Wget | wget | wget | core | https://linux.die.net/man/1/wget | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
162
- | **Packages** | | | | | | | | | | | |
163
- | Apt | apt | apt | core | https://linux.die.net/man/1/apt | [x] | [x] | | | | | |
164
- | Yum | yum | yum | core | https://linux.die.net/man/1/yum | | | [x] | [x] | [x] | | |
165
- | Zypper | zypper | zypper | core | https://en.opensuse.org/SDB:Zypper_manual | | | | | | [x] | [x] |
166
-
167
92
  ## Development
168
93
 
169
94
  After checking out the repo, run `bin/setup` to install dependencies.
data/kanrisuru.gemspec CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
14
14
 
15
15
  gem.required_ruby_version = '>= 2.5.0'
16
16
 
17
+ gem.add_development_dependency 'parallel_tests', '~> 3.7'
17
18
  gem.add_development_dependency 'rspec', '~> 3.10'
18
19
  gem.add_development_dependency 'rubocop', '~> 1.12'
19
20
  gem.add_development_dependency 'rubocop-rspec', '~> 2.2'
@@ -84,6 +84,13 @@ module Kanrisuru
84
84
  append_value("| #{value}")
85
85
  end
86
86
 
87
+ def append_array(value)
88
+ return unless Kanrisuru::Util.present?(value)
89
+
90
+ value = [value] if value.instance_of?(String)
91
+ append_value(value.join(' '))
92
+ end
93
+
87
94
  def append_value(value)
88
95
  @raw_command = "#{@raw_command} #{value}"
89
96
  end
@@ -10,18 +10,16 @@ module Kanrisuru
10
10
  FilePath = Struct.new(:path)
11
11
 
12
12
  def tar(action, file, opts = {})
13
- compress = opts[:compress]
14
13
  paths = opts[:paths]
15
14
  exclude = opts[:exclude]
16
- directory = opts[:directory]
17
15
 
18
16
  command = Kanrisuru::Command.new('tar --restrict')
19
17
 
20
- directory = realpath(directory, strip: true).path if directory
18
+ directory = opts[:directory] ? realpath(opts[:directory], strip: true).path : nil
21
19
  command.append_arg('-C', directory)
22
20
  command.append_arg('-f', file)
23
21
 
24
- set_compression(command, compress) if compress
22
+ set_compression(command, opts[:compress]) if opts[:compress]
25
23
 
26
24
  case action
27
25
  when 'list', 't'
@@ -58,10 +56,7 @@ module Kanrisuru
58
56
  command.append_flag('--unlink-first', opts[:unlink_first])
59
57
  command.append_flag('--recursive-unlink', opts[:recursive_unlink])
60
58
 
61
- if Kanrisuru::Util.present?(paths)
62
- paths = [paths] if paths.instance_of?(String)
63
- command << paths.join(' ')
64
- end
59
+ command.append_array(paths)
65
60
 
66
61
  execute_shell(command)
67
62
  Kanrisuru::Result.new(command)
@@ -70,46 +65,31 @@ module Kanrisuru
70
65
  command.append_flag('--multi-volume', opts[:multi_volume])
71
66
 
72
67
  if Kanrisuru::Util.present?(exclude)
73
- exclude_options = exclude.instance_of?(String) ? [exclude] : exclude
74
- exclude_options.each do |exclude_option|
75
- command << "--exclude=#{exclude_option}"
68
+ options = exclude.instance_of?(String) ? [exclude] : exclude
69
+ options.each do |option|
70
+ command << "--exclude=#{option}"
76
71
  end
77
72
  end
78
73
 
79
- if Kanrisuru::Util.present?(paths)
80
- paths = paths.instance_of?(String) ? [paths] : paths
81
- command << paths.join(' ')
82
- end
74
+ command.append_array(paths)
83
75
 
84
76
  execute_shell(command)
85
77
  Kanrisuru::Result.new(command)
86
78
  when 'append', 'r'
87
79
  command.append_flag('-r')
88
-
89
- if Kanrisuru::Util.present?(paths)
90
- paths = paths.instance_of?(String) ? [paths] : paths
91
- command << paths.join(' ')
92
- end
80
+ command.append_array(paths)
93
81
 
94
82
  execute_shell(command)
95
83
  Kanrisuru::Result.new(command)
96
84
  when 'catenate', 'concat', 'A'
97
85
  command.append_flag('-A')
98
-
99
- if Kanrisuru::Util.present?(paths)
100
- paths = paths.instance_of?(String) ? [paths] : paths
101
- command << paths.join(' ')
102
- end
86
+ command.append_array(paths)
103
87
 
104
88
  execute_shell(command)
105
89
  Kanrisuru::Result.new(command)
106
90
  when 'update', 'u'
107
91
  command.append_flag('-u')
108
-
109
- if Kanrisuru::Util.present?(paths)
110
- paths = paths.instance_of?(String) ? [paths] : paths
111
- command << paths.join(' ')
112
- end
92
+ command.append_array(paths)
113
93
 
114
94
  execute_shell(command)
115
95
  Kanrisuru::Result.new(command)
@@ -122,11 +102,7 @@ module Kanrisuru
122
102
  when 'delete'
123
103
  command.append_flag('--delete')
124
104
  command.append_arg('--occurrence', opts[:occurrence])
125
-
126
- if Kanrisuru::Util.present?(paths)
127
- paths = paths.instance_of?(String) ? [paths] : paths
128
- command << paths.join(' ')
129
- end
105
+ command.append_array(paths)
130
106
 
131
107
  execute_shell(command)
132
108
  Kanrisuru::Result.new(command)
@@ -64,12 +64,9 @@ module Kanrisuru
64
64
  command << dest
65
65
  elsif opts[:target_directory]
66
66
  command.append_arg('-t', dest)
67
-
68
- source = [source] if source.instance_of?(String)
69
- command << source.join(' ')
67
+ command.append_array(source)
70
68
  else
71
- source = [source] if source.instance_of?(String)
72
- command << source.join(' ')
69
+ command.append_array(source)
73
70
  command << dest
74
71
  end
75
72
 
@@ -108,13 +105,9 @@ module Kanrisuru
108
105
  command << dest
109
106
  elsif opts[:target_directory]
110
107
  command.append_arg('-t', dest)
111
-
112
- source = source.instance_of?(String) ? [source] : source
113
- command << source.join(' ')
108
+ command.append_array(source)
114
109
  else
115
- source = source.instance_of?(String) ? [source] : source
116
-
117
- command << source.join(' ')
110
+ command.append_array(source)
118
111
  command << dest
119
112
  end
120
113
 
@@ -30,13 +30,9 @@ module Kanrisuru
30
30
  end
31
31
 
32
32
  if Kanrisuru::Util.present?(paths)
33
- if paths.instance_of?(Array)
34
- paths = paths.join(' ')
35
- elsif paths.class != String
36
- raise ArgumentError, 'Invalid paths type'
37
- end
33
+ raise ArgumentError, 'Invalid paths type' unless [String, Array].include?(paths.class)
38
34
 
39
- command << paths
35
+ command.append_array(paths)
40
36
  end
41
37
 
42
38
  command.append_flag('-executable', opts[:executable])
@@ -10,9 +10,6 @@ module Kanrisuru
10
10
 
11
11
  def mount(opts = {})
12
12
  type = opts[:type]
13
- all = opts[:all]
14
- device = opts[:device]
15
- directory = opts[:directory]
16
13
 
17
14
  bind_old = opts[:bind_old]
18
15
  bind_new = opts[:bind_new]
@@ -39,13 +36,12 @@ module Kanrisuru
39
36
  else
40
37
  command.append_arg('-L', opts[:label])
41
38
  command.append_arg('-U', opts[:uuid])
42
- command.append_flag('-n', opts[:no_mtab])
43
39
  command.append_flag('-f', opts[:fake])
44
40
  command.append_flag('-i', opts[:internal_only])
45
41
  command.append_flag('-s', opts[:sloppy])
46
42
 
47
43
  command.append_flag('--no-mtab', opts[:no_mtab])
48
- command.append_flag('--no-canonicalizeb', opts[:no_canonicalize])
44
+ command.append_flag('--no-canonicalize', opts[:no_canonicalize])
49
45
 
50
46
  fs_options = nil
51
47
  if Kanrisuru::Util.present?(type)
@@ -55,14 +51,14 @@ module Kanrisuru
55
51
  fs_options = Kanrisuru::Remote::Fstab::Options.new('common', fs_opts)
56
52
  end
57
53
 
58
- if Kanrisuru::Util.present?(all)
54
+ if Kanrisuru::Util.present?(opts[:all])
59
55
  command.append_flag('-a')
60
56
  add_test_opts(command, opts[:test_opts], type)
61
57
  else
62
58
  command.append_arg('-o', fs_options.to_s)
63
59
 
64
- command << device if Kanrisuru::Util.present?(device)
65
- command << directory if Kanrisuru::Util.present?(directory)
60
+ command << opts[:device] if Kanrisuru::Util.present?(opts[:device])
61
+ command << opts[:directory] if Kanrisuru::Util.present?(opts[:directory])
66
62
  end
67
63
  end
68
64
 
@@ -75,12 +71,6 @@ module Kanrisuru
75
71
  type = opts[:type]
76
72
  command = Kanrisuru::Command.new('umount')
77
73
 
78
- if Kanrisuru::Util.present?(all)
79
- command.append_flag('-a')
80
- add_type(command, type)
81
- add_test_opts(command, opts[:test_opts], type)
82
- end
83
-
84
74
  command.append_flag('--fake', opts[:fake])
85
75
  command.append_flag('--no-canonicalize', opts[:no_canonicalize])
86
76
  command.append_flag('-n', opts[:no_mtab])
@@ -90,6 +80,15 @@ module Kanrisuru
90
80
  command.append_flag('-l', opts[:lazy])
91
81
  command.append_flag('-f', opts[:force])
92
82
 
83
+ if Kanrisuru::Util.present?(all)
84
+ command.append_flag('-a')
85
+ add_type(command, type)
86
+ add_test_opts(command, opts[:test_opts], type)
87
+ else
88
+ command << opts[:device] if Kanrisuru::Util.present?(opts[:device])
89
+ command << opts[:directory] if Kanrisuru::Util.present?(opts[:directory])
90
+ end
91
+
93
92
  execute_shell(command)
94
93
 
95
94
  Kanrisuru::Result.new(command)
@@ -115,7 +114,7 @@ module Kanrisuru
115
114
 
116
115
  test_types.each do |t|
117
116
  device_opts = Kanrisuru::Util::FsMountOpts.get_device(t)
118
- raise ArugmentError, "Invalid fstype: #{t}" unless device_opts
117
+ raise ArgumentError, "Invalid fstype: #{t}" unless device_opts
119
118
  end
120
119
 
121
120
  command.append_arg('-t', type)
@@ -95,8 +95,7 @@ module Kanrisuru
95
95
  command.append_flag('-b', opts[:number_nonblank])
96
96
  command.append_flag('-A', opts[:show_all])
97
97
 
98
- files = [files] if files.instance_of?(String)
99
- command << files.join(' ')
98
+ command.append_array(files)
100
99
 
101
100
  append_file(command, opts)
102
101
  execute_shell(command)
@@ -181,8 +181,7 @@ module Kanrisuru
181
181
  command.append_flag('--metadata', opts[:metadata])
182
182
  command.append_flag('--raw-metadata', opts[:raw_metadata])
183
183
  command.append_flag('--all', opts[:all])
184
-
185
- command << opts[:repos]
184
+ command.append_array(opts[:repos])
186
185
 
187
186
  execute_shell(command)
188
187
 
@@ -276,11 +275,7 @@ module Kanrisuru
276
275
  command.append_arg('--medium-type', opts[:medium_type])
277
276
  end
278
277
 
279
- repos = opts[:repos]
280
- if Kanrisuru::Util.present?(repos)
281
- repos = [repos] if repos.instance_of?(String)
282
- command << repos.join(' ')
283
- end
278
+ command.append_array(opts[:repos])
284
279
 
285
280
  execute_shell(command)
286
281
 
@@ -336,11 +331,7 @@ module Kanrisuru
336
331
  command.append_arg('--media-type', opts[:media_type])
337
332
  end
338
333
 
339
- repos = opts[:repos]
340
- if Kanrisuru::Util.present?(repos)
341
- repos = repos.instance_of?(String) ? [repos] : repos
342
- command << repos.join(' ')
343
- end
334
+ command.append_array(opts[:repos])
344
335
 
345
336
  execute_shell(command)
346
337
 
@@ -372,11 +363,7 @@ module Kanrisuru
372
363
  command.append_flag('--refresh', opts[:refresh])
373
364
  command.append_flag('--no-refresh', opts[:no_refresh])
374
365
 
375
- services = opts[:services]
376
- if Kanrisuru::Util.present?(services)
377
- services = [services] if services.instance_of?(String)
378
- command << services.join(' ')
379
- end
366
+ command.append_array(opts[:services])
380
367
 
381
368
  execute_shell(command)
382
369
 
@@ -386,15 +373,11 @@ module Kanrisuru
386
373
  def zypper_remove_service(opts)
387
374
  command = Kanrisuru::Command.new('zypper')
388
375
  zypper_global_opts(command, opts)
376
+
389
377
  command << 'removeservice'
390
378
  command.append_flag('--loose-auth', opts[:loose_auth])
391
379
  command.append_flag('--loose-query', opts[:loose_query])
392
-
393
- services = opts[:services]
394
- if Kanrisuru::Util.present?(services)
395
- services = [services] if services.instance_of?(String)
396
- command << services.join(' ')
397
- end
380
+ command.append_array(opts[:services])
398
381
 
399
382
  execute_shell(command)
400
383
 
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kanrisuru
4
+ module OsPackage
5
+ module Collection
6
+ def os_collection(mod, opts = {})
7
+ os_method_properties = mod.instance_variable_get(:@os_method_properties)
8
+ os_method_names = os_method_properties.keys
9
+
10
+ namespace = opts[:namespace]
11
+ namespace_instance = nil
12
+
13
+ if namespace
14
+ ## Define the namespace as an eigen class instance on the host.
15
+ ## Namespaced instances will access core host methods
16
+ ## with @host instance variable.
17
+
18
+ if Kanrisuru::Remote::Cluster.instance_variable_defined?("@#{namespace}")
19
+ namespace_class = Kanrisuru::Remote::Cluster.const_get(Kanrisuru::Util.camelize(namespace))
20
+ namespace_instance = instance_variable_get("@#{namespace}")
21
+ else
22
+ namespace_class = Kanrisuru::Remote::Cluster.const_set(Kanrisuru::Util.camelize(namespace), Class.new)
23
+ namespace_instance = Kanrisuru::Remote::Cluster.instance_variable_set("@#{namespace}", namespace_class.new)
24
+
25
+ class_eval do
26
+ define_method namespace do
27
+ namespace_instance.instance_variable_set(:@cluster, self)
28
+ namespace_instance
29
+ end
30
+ end
31
+ end
32
+
33
+ namespace_class.class_eval do
34
+ os_method_names.each do |method_name|
35
+ define_method method_name do |*args, &block|
36
+ cluster = namespace_instance.instance_variable_get(:@cluster)
37
+ hosts = cluster.instance_variable_get(:@hosts)
38
+ hosts.map do |host_addr, host|
39
+ { host: host_addr, result: host.send(namespace).send(method_name, *args, &block) }
40
+ end
41
+ end
42
+ end
43
+ end
44
+ else
45
+ class_eval do
46
+ os_method_names.each do |method_name|
47
+ define_method method_name do |*args, &block|
48
+ @hosts.map do |host_addr, host|
49
+ { host: host_addr, result: host.send(method_name, *args, &block) }
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kanrisuru
4
+ module OsPackage
5
+ module Define
6
+ def self.extended(base)
7
+ base.instance_variable_set(:@os_method_properties, {})
8
+ base.instance_variable_set(:@os_methods, Set.new)
9
+ end
10
+
11
+ def os_define(os_name, method_name, options = {})
12
+ unique_method_name = options[:alias] || method_name
13
+
14
+ @os_methods.add(method_name)
15
+
16
+ if @os_method_properties.key?(unique_method_name)
17
+ params = {
18
+ os_name: os_name.to_s,
19
+ method_name: method_name,
20
+ options: options
21
+ }
22
+
23
+ @os_method_properties[unique_method_name].prepend(params)
24
+ else
25
+ @os_method_properties[unique_method_name] = [{
26
+ os_name: os_name.to_s,
27
+ method_name: method_name,
28
+ options: options
29
+ }]
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end