kanrisuru 0.11.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -1
  3. data/CHANGELOG.md +26 -6
  4. data/README.md +19 -91
  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/dmi.rb +1 -1
  9. data/lib/kanrisuru/core/file.rb +4 -11
  10. data/lib/kanrisuru/core/find.rb +2 -6
  11. data/lib/kanrisuru/core/mount.rb +14 -15
  12. data/lib/kanrisuru/core/stream.rb +1 -2
  13. data/lib/kanrisuru/core/zypper.rb +6 -23
  14. data/lib/kanrisuru/os_package/collection.rb +58 -0
  15. data/lib/kanrisuru/os_package/define.rb +34 -0
  16. data/lib/kanrisuru/os_package/include.rb +163 -0
  17. data/lib/kanrisuru/os_package.rb +3 -245
  18. data/lib/kanrisuru/remote/fstab.rb +1 -1
  19. data/lib/kanrisuru/result.rb +5 -4
  20. data/lib/kanrisuru/version.rb +1 -1
  21. data/spec/functional/core/archive_spec.rb +2 -1
  22. data/spec/functional/core/mount_spec.rb +121 -0
  23. data/spec/functional/remote/cpu_spec.rb +1 -1
  24. data/spec/functional/result_spec.rb +150 -0
  25. data/spec/{hosts.json → helper/hosts.json} +0 -0
  26. data/spec/helper/simplecov.rb +21 -0
  27. data/spec/helper/stub_network.rb +20 -20
  28. data/spec/helper/test_hosts.rb +12 -2
  29. data/spec/integration/core/apt/debian_spec.rb +9 -0
  30. data/spec/integration/core/apt/ubuntu_spec.rb +9 -0
  31. data/spec/integration/core/archive/centos_spec.rb +9 -0
  32. data/spec/integration/core/archive/debian_spec.rb +9 -0
  33. data/spec/integration/core/archive/fedora_spec.rb +9 -0
  34. data/spec/integration/core/archive/opensuse_spec.rb +9 -0
  35. data/spec/integration/core/archive/rhel_spec.rb +9 -0
  36. data/spec/integration/core/archive/sles_spec.rb +9 -0
  37. data/spec/integration/core/archive/ubuntu_spec.rb +9 -0
  38. data/spec/integration/core/disk/centos_spec.rb +9 -0
  39. data/spec/integration/core/disk/debian_spec.rb +9 -0
  40. data/spec/integration/core/disk/fedora_spec.rb +9 -0
  41. data/spec/integration/core/disk/opensuse_spec.rb +9 -0
  42. data/spec/integration/core/disk/rhel_spec.rb +9 -0
  43. data/spec/integration/core/disk/sles_spec.rb +9 -0
  44. data/spec/integration/core/disk/ubuntu_spec.rb +9 -0
  45. data/spec/integration/core/dmi/centos_spec.rb +9 -0
  46. data/spec/integration/core/dmi/debian_spec.rb +9 -0
  47. data/spec/integration/core/dmi/fedora_spec.rb +9 -0
  48. data/spec/integration/core/dmi/opensuse_spec.rb +9 -0
  49. data/spec/integration/core/dmi/rhel_spec.rb +9 -0
  50. data/spec/integration/core/dmi/sles_spec.rb +9 -0
  51. data/spec/integration/core/dmi/ubuntu_spec.rb +9 -0
  52. data/spec/integration/core/file/centos_spec.rb +9 -0
  53. data/spec/integration/core/file/debian_spec.rb +9 -0
  54. data/spec/integration/core/file/fedora_spec.rb +9 -0
  55. data/spec/integration/core/file/opensuse_spec.rb +9 -0
  56. data/spec/integration/core/file/rhel_spec.rb +9 -0
  57. data/spec/integration/core/file/sles_spec.rb +9 -0
  58. data/spec/integration/core/file/ubuntu_spec.rb +9 -0
  59. data/spec/integration/core/find/centos_spec.rb +9 -0
  60. data/spec/integration/core/find/debian_spec.rb +9 -0
  61. data/spec/integration/core/find/fedora_spec.rb +9 -0
  62. data/spec/integration/core/find/opensuse_spec.rb +9 -0
  63. data/spec/integration/core/find/rhel_spec.rb +9 -0
  64. data/spec/integration/core/find/sles_spec.rb +9 -0
  65. data/spec/integration/core/find/ubuntu_spec.rb +9 -0
  66. data/spec/integration/core/group/centos_spec.rb +9 -0
  67. data/spec/integration/core/group/debian_spec.rb +9 -0
  68. data/spec/integration/core/group/fedora_spec.rb +9 -0
  69. data/spec/integration/core/group/opensuse_spec.rb +9 -0
  70. data/spec/integration/core/group/rhel_spec.rb +9 -0
  71. data/spec/integration/core/group/sles_spec.rb +9 -0
  72. data/spec/integration/core/group/ubuntu_spec.rb +9 -0
  73. data/spec/integration/core/ip/centos_spec.rb +9 -0
  74. data/spec/integration/core/ip/debian_spec.rb +9 -0
  75. data/spec/integration/core/ip/fedora_spec.rb +9 -0
  76. data/spec/integration/core/ip/opensuse_spec.rb +9 -0
  77. data/spec/integration/core/ip/rhel_spec.rb +9 -0
  78. data/spec/integration/core/ip/sles_spec.rb +9 -0
  79. data/spec/integration/core/ip/ubuntu_spec.rb +9 -0
  80. data/spec/integration/core/path/centos_spec.rb +9 -0
  81. data/spec/integration/core/path/debian_spec.rb +9 -0
  82. data/spec/integration/core/path/fedora_spec.rb +9 -0
  83. data/spec/integration/core/path/opensuse_spec.rb +9 -0
  84. data/spec/integration/core/path/rhel_spec.rb +9 -0
  85. data/spec/integration/core/path/sles_spec.rb +9 -0
  86. data/spec/integration/core/path/ubuntu_spec.rb +9 -0
  87. data/spec/integration/core/socket/centos_spec.rb +9 -0
  88. data/spec/integration/core/socket/debian_spec.rb +9 -0
  89. data/spec/integration/core/socket/fedora_spec.rb +9 -0
  90. data/spec/integration/core/socket/opensuse_spec.rb +9 -0
  91. data/spec/integration/core/socket/rhel_spec.rb +9 -0
  92. data/spec/integration/core/socket/sles_spec.rb +9 -0
  93. data/spec/integration/core/socket/ubuntu_spec.rb +9 -0
  94. data/spec/integration/core/stat/centos_spec.rb +9 -0
  95. data/spec/integration/core/stat/debian_spec.rb +9 -0
  96. data/spec/integration/core/stat/fedora_spec.rb +9 -0
  97. data/spec/integration/core/stat/opensuse_spec.rb +9 -0
  98. data/spec/integration/core/stat/rhel_spec.rb +9 -0
  99. data/spec/integration/core/stat/sles_spec.rb +9 -0
  100. data/spec/integration/core/stat/ubuntu_spec.rb +9 -0
  101. data/spec/integration/core/stream/centos_spec.rb +9 -0
  102. data/spec/integration/core/stream/debian_spec.rb +9 -0
  103. data/spec/integration/core/stream/fedora_spec.rb +9 -0
  104. data/spec/integration/core/stream/opensuse_spec.rb +9 -0
  105. data/spec/integration/core/stream/rhel_spec.rb +9 -0
  106. data/spec/integration/core/stream/sles_spec.rb +9 -0
  107. data/spec/integration/core/stream/ubuntu_spec.rb +9 -0
  108. data/spec/integration/core/system/centos_spec.rb +9 -0
  109. data/spec/integration/core/system/debian_spec.rb +9 -0
  110. data/spec/integration/core/system/fedora_spec.rb +9 -0
  111. data/spec/integration/core/system/opensuse_spec.rb +9 -0
  112. data/spec/integration/core/system/rhel_spec.rb +9 -0
  113. data/spec/integration/core/system/sles_spec.rb +9 -0
  114. data/spec/integration/core/system/ubuntu_spec.rb +9 -0
  115. data/spec/integration/core/transfer/centos_spec.rb +9 -0
  116. data/spec/integration/core/transfer/debian_spec.rb +9 -0
  117. data/spec/integration/core/transfer/fedora_spec.rb +9 -0
  118. data/spec/integration/core/transfer/opensuse_spec.rb +9 -0
  119. data/spec/integration/core/transfer/rhel_spec.rb +9 -0
  120. data/spec/integration/core/transfer/sles_spec.rb +9 -0
  121. data/spec/integration/core/transfer/ubuntu_spec.rb +9 -0
  122. data/spec/integration/core/user/centos_spec.rb +9 -0
  123. data/spec/integration/core/user/debian_spec.rb +9 -0
  124. data/spec/integration/core/user/fedora_spec.rb +9 -0
  125. data/spec/integration/core/user/opensuse_spec.rb +9 -0
  126. data/spec/integration/core/user/rhel_spec.rb +9 -0
  127. data/spec/integration/core/user/sles_spec.rb +9 -0
  128. data/spec/integration/core/user/ubuntu_spec.rb +9 -0
  129. data/spec/integration/core/yum/centos_spec.rb +9 -0
  130. data/spec/integration/core/yum/fedora_spec.rb +9 -0
  131. data/spec/integration/core/yum/rhel_spec.rb +9 -0
  132. data/spec/integration/core/zypper/opensuse_spec.rb +9 -0
  133. data/spec/integration/core/zypper/sles_spec.rb +9 -0
  134. data/spec/integration/remote/cluster/ubuntu_spec.rb +9 -0
  135. data/spec/integration/remote/cpu/centos_spec.rb +9 -0
  136. data/spec/integration/remote/cpu/debian_spec.rb +9 -0
  137. data/spec/integration/remote/cpu/fedora_spec.rb +9 -0
  138. data/spec/integration/remote/cpu/opensuse_spec.rb +9 -0
  139. data/spec/integration/remote/cpu/rhel_spec.rb +9 -0
  140. data/spec/integration/remote/cpu/sles_spec.rb +9 -0
  141. data/spec/integration/remote/cpu/ubuntu_spec.rb +9 -0
  142. data/spec/integration/remote/env/centos_spec.rb +9 -0
  143. data/spec/integration/remote/env/debian_spec.rb +9 -0
  144. data/spec/integration/remote/env/fedora_spec.rb +9 -0
  145. data/spec/integration/remote/env/opensuse_spec.rb +9 -0
  146. data/spec/integration/remote/env/rhel_spec.rb +9 -0
  147. data/spec/integration/remote/env/sles_spec.rb +9 -0
  148. data/spec/integration/remote/env/ubuntu_spec.rb +9 -0
  149. data/spec/integration/remote/fstab/centos_spec.rb +9 -0
  150. data/spec/integration/remote/fstab/debian_spec.rb +9 -0
  151. data/spec/integration/remote/fstab/fedora_spec.rb +9 -0
  152. data/spec/integration/remote/fstab/opensuse_spec.rb +9 -0
  153. data/spec/integration/remote/fstab/rhel_spec.rb +9 -0
  154. data/spec/integration/remote/fstab/sles_spec.rb +9 -0
  155. data/spec/integration/remote/fstab/ubuntu_spec.rb +9 -0
  156. data/spec/integration/remote/host/centos_spec.rb +9 -0
  157. data/spec/integration/remote/host/debian_spec.rb +9 -0
  158. data/spec/integration/remote/host/fedora_spec.rb +9 -0
  159. data/spec/integration/remote/host/opensuse_spec.rb +9 -0
  160. data/spec/integration/remote/host/rhel_spec.rb +9 -0
  161. data/spec/integration/remote/host/sles_spec.rb +9 -0
  162. data/spec/integration/remote/host/ubuntu_spec.rb +9 -0
  163. data/spec/integration/remote/memory/centos_spec.rb +9 -0
  164. data/spec/integration/remote/memory/debian_spec.rb +9 -0
  165. data/spec/integration/remote/memory/fedora_spec.rb +9 -0
  166. data/spec/integration/remote/memory/opensuse_spec.rb +9 -0
  167. data/spec/integration/remote/memory/rhel_spec.rb +9 -0
  168. data/spec/integration/remote/memory/sles_spec.rb +9 -0
  169. data/spec/integration/remote/memory/ubuntu_spec.rb +9 -0
  170. data/spec/integration/remote/os/centos_spec.rb +9 -0
  171. data/spec/integration/remote/os/debian_spec.rb +9 -0
  172. data/spec/integration/remote/os/fedora_spec.rb +9 -0
  173. data/spec/integration/remote/os/opensuse_spec.rb +9 -0
  174. data/spec/integration/remote/os/rhel_spec.rb +9 -0
  175. data/spec/integration/remote/os/sles_spec.rb +9 -0
  176. data/spec/integration/remote/os/ubuntu_spec.rb +9 -0
  177. data/spec/integration/remote/remote_file/centos_spec.rb +9 -0
  178. data/spec/integration/remote/remote_file/debian_spec.rb +9 -0
  179. data/spec/integration/remote/remote_file/fedora_spec.rb +9 -0
  180. data/spec/integration/remote/remote_file/opensuse_spec.rb +9 -0
  181. data/spec/integration/remote/remote_file/rhel_spec.rb +9 -0
  182. data/spec/integration/remote/remote_file/sles_spec.rb +9 -0
  183. data/spec/integration/remote/remote_file/ubuntu_spec.rb +9 -0
  184. data/spec/spec_helper.rb +4 -4
  185. data/spec/support/shared_examples/integration/core/apt.rb +117 -0
  186. data/spec/support/shared_examples/integration/core/archive.rb +221 -0
  187. data/spec/support/shared_examples/integration/core/disk.rb +91 -0
  188. data/spec/support/shared_examples/integration/core/dmi.rb +34 -0
  189. data/spec/support/shared_examples/integration/core/file.rb +357 -0
  190. data/spec/support/shared_examples/integration/core/find.rb +50 -0
  191. data/spec/support/shared_examples/integration/core/group.rb +62 -0
  192. data/spec/support/shared_examples/integration/core/ip.rb +68 -0
  193. data/spec/support/shared_examples/integration/core/path.rb +90 -0
  194. data/spec/support/shared_examples/integration/core/socket.rb +27 -0
  195. data/spec/support/shared_examples/integration/core/stat.rb +95 -0
  196. data/spec/support/shared_examples/integration/core/stream.rb +112 -0
  197. data/spec/support/shared_examples/integration/core/system.rb +155 -0
  198. data/spec/support/shared_examples/integration/core/transfer.rb +101 -0
  199. data/spec/support/shared_examples/integration/core/user.rb +72 -0
  200. data/spec/support/shared_examples/integration/core/yum.rb +115 -0
  201. data/spec/support/shared_examples/integration/core/zypper.rb +196 -0
  202. data/spec/{integration/remote/cluster_spec.rb → support/shared_examples/integration/remote/cluster.rb} +2 -2
  203. data/spec/support/shared_examples/integration/remote/cpu.rb +38 -0
  204. data/spec/support/shared_examples/integration/remote/env_spec.rb +33 -0
  205. data/spec/support/shared_examples/integration/remote/fstab.rb +89 -0
  206. data/spec/support/shared_examples/integration/remote/host.rb +65 -0
  207. data/spec/support/shared_examples/integration/remote/memory.rb +27 -0
  208. data/spec/support/shared_examples/integration/remote/os.rb +60 -0
  209. data/spec/support/shared_examples/integration/remote/remote_file.rb +172 -0
  210. data/spec/unit/command_spec.rb +18 -0
  211. metadata +204 -30
  212. data/spec/integration/core/apt_spec.rb +0 -120
  213. data/spec/integration/core/archive_spec.rb +0 -228
  214. data/spec/integration/core/disk_spec.rb +0 -94
  215. data/spec/integration/core/dmi_spec.rb +0 -37
  216. data/spec/integration/core/file_spec.rb +0 -368
  217. data/spec/integration/core/find_spec.rb +0 -53
  218. data/spec/integration/core/group_spec.rb +0 -65
  219. data/spec/integration/core/ip_spec.rb +0 -71
  220. data/spec/integration/core/path_spec.rb +0 -93
  221. data/spec/integration/core/socket_spec.rb +0 -31
  222. data/spec/integration/core/stat_spec.rb +0 -98
  223. data/spec/integration/core/stream_spec.rb +0 -117
  224. data/spec/integration/core/system_spec.rb +0 -143
  225. data/spec/integration/core/transfer_spec.rb +0 -108
  226. data/spec/integration/core/user_spec.rb +0 -76
  227. data/spec/integration/core/yum_spec.rb +0 -118
  228. data/spec/integration/core/zypper_spec.rb +0 -199
  229. data/spec/integration/remote/cpu_spec.rb +0 -41
  230. data/spec/integration/remote/env_spec.rb +0 -36
  231. data/spec/integration/remote/fstab_spec.rb +0 -92
  232. data/spec/integration/remote/host_spec.rb +0 -68
  233. data/spec/integration/remote/memory_spec.rb +0 -29
  234. data/spec/integration/remote/os_spec.rb +0 -63
  235. data/spec/integration/remote/remote_file_spec.rb +0 -180
  236. data/spec/zz_reboot_spec.rb +0 -46
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71358a615946331ad5e1d4a0d6cd51523981ad046d788e5e189ba2c0f49c136e
4
- data.tar.gz: 7b6bec928fcd0b0dc05a77a83a8b5dc224d3f54f1ae162911dd742f90cf8ef81
3
+ metadata.gz: 5c3224eaa762b9db3ba0544a1fd7195f477cd6681cd4f5ddf9638e512d476c5f
4
+ data.tar.gz: c592a88c34b8ecd9446cccaa800f14f34e48f9cccec6bde70142b11218e194e0
5
5
  SHA512:
6
- metadata.gz: 26d0eff2b5548b07af887865f3b899e0e30d16ac4cfb1033eb761be282141156f3e24818d8257f432dfdd2a0687ceac4dee8abf2e7b6dfc9d5313950633ecf1a
7
- data.tar.gz: 63e244ee640721f7ad653e77d915f150420c9c97949d5f7f441818c13b2c5015fb9c7cb43b503ceff49076823455e3164c06de3e773e8b885f9bb1684e0c1672
6
+ metadata.gz: 491f30a9148d1c99897eaec94de93357875e4c9dfa41cf86005eeeab2d7fe72fad63726bc0493b5ac2b4058f8ae70d4804778dee8a9e7a802e054c2374346e1d
7
+ data.tar.gz: 67c4732c93718dd1e49f86b2c06986cccef3e38887ade89815cbb091b026af63427b6ad108ff26847e33874109decb78466ed5d3ca98875401414e376c7fd0e0
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,11 +1,32 @@
1
+ ## Kanrisuru 0.13.0 (December 06, 2021) ##
2
+ * Add functional test cases for `Kanrisuru::Result` class.
3
+ * Refactor integration tests for better parallelization with the `parallel_tests` gem. This dropped overall test time from 35 minutes, to 22 minutes after first integration with 1 processor. After scaling upto 8 core machine, the run time dropped to 16 minutes, but was still sending the entire test file to a processor. By splitting up each host test into a seperate file, the run time dropped to a little over 9 minutes. There's probably a way to optimize which test gets run together, but overall a much better scenario.
4
+
5
+ ## Kanrisuru 0.12.1 (December 05, 2021) ##
6
+ * Fix typo in spec.
7
+ * Cleanup bad code style.
8
+
9
+ ## Kanrisuru 0.12.0 (December 05, 2021) ##
10
+ * Add functional test cases for `mount` command.
11
+ * Fix typos and command preperation for `mount` command.
12
+ * Refactor `os_package` module into smaller modules for `Kanrisuru::OsPackage::Collection`, `Kanrisuru::OsPackage::Define`, and `Kanrisuru::OsPackage::Include`.
13
+ * Add `append_array` to `command` class for easy string to array conversion for variable option passing.
14
+ * Cleanup bad coding styles.
15
+ * Add parallel testing support for long running integration tests on remote servers.
16
+ * Refactor specs to use variable spec_dir path for parallel testing on remote hosts with possible overwriting at the same time.
17
+
18
+ ## Kanrisuru 0.11.1 (December 04, 2021) ##
19
+ * Cleanup self-assignment branches
20
+ * Fix linting issues.
21
+
1
22
  ## Kanrisuru 0.11.0 (December 04, 2021) ##
2
23
  * Add codequality badge, cleanup code linting issues.
3
24
  * Fix `fstab` issue with blkid device return type.
4
- * Fix `find` spec with sudo permissions.
25
+ * Fix `find` spec with sudo permissions.
5
26
  * Change `stub_network` result override to use `block.call` with a conditional check for indvidual command stubs.
6
27
  * Add `architecture` method to `cpu`.
7
28
  * Add functional test cases for `cpu` class.
8
- * Add more unit test cases.
29
+ * Add more unit test cases.
9
30
 
10
31
  ## Kanrisuru 0.10.0 (December 03, 2021) ##
11
32
  * Add `stub_command` and `unstub_command` to mock indvidual command results from a remote server.
@@ -199,10 +220,9 @@ cache key to avoid any namespace collisions with the same method name, namely:
199
220
  * Force "-" to "\_" from `os-release` release name in `host.os` module.
200
221
 
201
222
  ## Kanrisuru 0.2.5 (July 16, 2021) ##
202
- * Update gem depedencies to non-zero values
203
- * Change summary and description fields for `apt`
204
- * Move `normalize_size` from `apt` core module, to
205
- `Kanrisuru::Util::Bits` class.
223
+ * Update gem depedencies to non-zero values.
224
+ * Change summary and description fields for `apt`.
225
+ * Move `normalize_size` from `apt` core module, to `Kanrisuru::Util::Bits` class.
206
226
  * Add additional test cases for `apt` core module.
207
227
  * Add `-hi` to `who` command to explicility print out ip address for user.
208
228
  * Update `inode?` command to execute without shell user.
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.
@@ -28,14 +35,17 @@ gem 'kanrisuru'
28
35
 
29
36
  And then execute:
30
37
 
31
- $ bundle install
38
+ ```bash
39
+ $ bundle install
40
+ ```
32
41
 
33
42
  Or install it yourself as:
34
43
 
35
- $ gem install kanrisuru
44
+ ```bash
45
+ $ gem install kanrisuru
46
+ ```
36
47
 
37
48
  ## Usage
38
-
39
49
  Run basic commands you would have access to while running on a remote host or on a cluster of hosts.
40
50
 
41
51
  ### Host
@@ -79,88 +89,6 @@ cluster = Kanrisuru::Remote::Cluster.new(host, {host: 'host2', username: 'alice'
79
89
  cluster.execute('uname') #=> {host: 'host1', result: 'Linux'}, {host: 'host2', result: 'Linux'}
80
90
  ```
81
91
 
82
- ## Methods and Testing
83
-
84
- | Description | Ruby | Shell | Module | Man | Debian | Ubuntu | Fedora | Centos | RHEL | openSUSE | SLES |
85
- |---------------------------------------|------------------|--------------------|--------|--------------------------------------|--------|--------|--------|--------|------|----------|------|
86
- | **System** | | | | | | | | | | | |
87
- | Get CPU Info | cpu_info | lscpu | core | https://linux.die.net/man/1/lscpu | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
88
- | Get CPU architecture | lscpu | lscpu | core | https://linux.die.net/man/1/lscpu | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
89
- | Get kernel stastics | kernel_statistics | cat /proc/stat | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
90
- | Get hardware BIOS info | dmi | dmidecode | core | https://linux.die.net/man/8/dmidecode | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
91
- | Get open file details for processes | lsof | lsof | core | https://linux.die.net/man/8/lsof | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
92
- | Get Load Average | load_average | cat /proc/load_avg | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
93
- | Get RAM Available | free | cat /proc/meminfo | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
94
- | Get list of processes | ps | ps | core | https://linux.die.net/man/1/ps | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
95
- | Get Env vars | load_env | env | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
96
- | Kill process | kill | kill | core | https://linux.die.net/man/1/kill | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
97
- | Get uptime of system | uptime | cat /proc/uptime | core | https://linux.die.net/man/1/uptime | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
98
- | Get who's logged in | w | w | core | https://linux.die.net/man/1/w | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
99
- | Reboot machine | reboot | shutdown | core | https://linux.die.net/man/8/reboot | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
100
- | Poweroff machine | poweroff | shutdown | core | https://linux.die.net/man/8/shutdown | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
101
- | **Disk** | | | | | | | | | | | |
102
- | Get Disk Space | df | df | core | https://linux.die.net/man/1/df | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
103
- | Get Disk Usage | du | du | core | https://linux.die.net/man/1/du | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
104
- | List block devices | lsblk | lsblk | core | https://linux.die.net/man/8/lsblk | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
105
- | Get block device attributes | blkid | blikd | core | https://linux.die.net/man/8/blkid | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
106
- | **Mount** | | | | | | | | | | | |
107
- | Mount a filesystem | mount | mount | core | https://linux.die.net/man/8/mount | | | | | | | |
108
- | Unmount a filesystem | umount | umount | core | https://linux.die.net/man/8/umount | | | | | | | |
109
- | **Group** | | | | | | | | | | | |
110
- | Get Group Id | get_gid | getent group | core | https://linux.die.net/man/1/getent | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
111
- | Get Group | get_group | grep /etc/group | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
112
- | Create Group | create_group | groupadd | core | https://linux.die.net/man/8/groupadd | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
113
- | Update Group | update_group | groupmod | core | https://linux.die.net/man/8/groupmod | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
114
- | Delete Group | delete_group | groupdel | core | https://linux.die.net/man/8/groupdel | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
115
- | **User** | | | | | | | | | | | |
116
- | Get User Id | get_uid | id -u | core | https://linux.die.net/man/1/id | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
117
- | Get User | get_user | id | core | https://linux.die.net/man/1/id | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
118
- | Create User | create_user | useradd | core | https://linux.die.net/man/8/useradd | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
119
- | Update User | update_user | usermod | core | https://linux.die.net/man/8/usermod | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
120
- | Delete User | delete_user | userdel | core | https://linux.die.net/man/8/userdel | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
121
- | **Path** | | | | | | | | | | | |
122
- | List files and directories | ls | ls | core | https://linux.die.net/man/1/ls | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
123
- | Get Current Dir | pwd | pwd | core | https://linux.die.net/man/1/pwd | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
124
- | Get Current User | whoami | whoami | core | https://linux.die.net/man/1/whoami | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
125
- | Get Full Path of Shell Command | which | which | core | https://linux.die.net/man/1/which | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
126
- | Real Path | realpath | realpath | core | https://linux.die.net/man/1/realpath | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
127
- | Read link | readlink | readlink | core | https://linux.die.net/man/1/readlink | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
128
- | Change Dir | cd | cd | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
129
- | **File** | | | | | | | | | | | |
130
- | "Find file, dir, special file device" | find | find | core | https://linux.die.net/man/1/find | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
131
- | Stat file info | stat | stat | core | https://linux.die.net/man/1/stat | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
132
- | Change Permission of file / folder | chmod | chmod | core | https://linux.die.net/man/1/chmod | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
133
- | Change Ownership of file / folder | chown | chown | core | https://linux.die.net/man/1/chown | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
134
- | Hard Link File | ln | ln | core | https://linux.die.net/man/1/ln | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
135
- | Soft Link File / Dir | ln_s | ln | core | https://linux.die.net/man/1/ln | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
136
- | Create Directory | mkdir | mkdir | core | https://linux.die.net/man/1/mkdir | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
137
- | Remove file / directory | rm | rm | core | https://linux.die.net/man/1/rm | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
138
- | Remove Directory | rmdir | rm | core | https://linux.die.net/man/1/rm | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
139
- | Touch File | touch | touch | core | https://linux.die.net/man/1/touch | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
140
- | Copy file / directory | cp | cp | core | https://linux.die.net/man/1/cp | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
141
- | Move file / directory | mv | mv | core | https://linux.die.net/man/1/mv | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
142
- | "Get file line, word, and char count" | wc | wc | core | https://linux.die.net/man/1/wc | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
143
- | **Stream** | | | | | | | | | | | |
144
- | Get content from beginning of file | head | head | core | https://linux.die.net/man/1/head | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
145
- | Get content from end of file | tail | tail | core | https://linux.die.net/man/1/tail | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
146
- | Read a chunk from a file by lines | reach_file_chunk | tail and head | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
147
- | Echo to stdout or to file | echo | echo | core | https://linux.die.net/man/1/echo | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
148
- | Get all content from a file | cat | cat | core | https://linux.die.net/man/1/cat | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
149
- | Sed | sed | sed | core | https://linux.die.net/man/1/sed | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
150
- | **Archive** | | | | | | | | | | | |
151
- | Tar Files | tar | tar | core | https://linux.die.net/man/1/tar | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
152
- | **Network** | | | | | | | | | | | |
153
- | Manage network devices | ip | ip | core | https://linux.die.net/man/8/ip | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
154
- | Get Socket Details | ss | ss | core | https://linux.die.net/man/8/ss | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
155
- | **Transfer** | | | | | | | | | | | |
156
- | Upload to remote server | upload | scp | core | https://linux.die.net/man/1/scp | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
157
- | Download from remote server | download | scp | core | https://linux.die.net/man/1/scp | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
158
- | Wget | wget | wget | core | https://linux.die.net/man/1/wget | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
159
- | **Packages** | | | | | | | | | | | |
160
- | Apt | apt | apt | core | https://linux.die.net/man/1/apt | [x] | [x] | | | | | |
161
- | Yum | yum | yum | core | https://linux.die.net/man/1/yum | | | [x] | [x] | [x] | | |
162
- | Zypper | zypper | zypper | core | https://en.opensuse.org/SDB:Zypper_manual | | | | | | [x] | [x] |
163
-
164
92
  ## Development
165
93
 
166
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.instance_of?(String) ? [paths] : paths
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)
@@ -511,7 +511,7 @@ module Kanrisuru
511
511
  return unless Kanrisuru::Util.present?(opts[:types])
512
512
 
513
513
  types = opts[:types]
514
- types = types.instance_of?(Array) ? types : [types]
514
+ types = [types] if types.instance_of?(String)
515
515
 
516
516
  types.each do |type|
517
517
  type = parse_dmi_type(type)
@@ -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.instance_of?(String) ? [source] : source
69
- command << source.join(' ')
67
+ command.append_array(source)
70
68
  else
71
- source = source.instance_of?(String) ? [source] : source
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.instance_of?(String) ? [files] : files
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.instance_of?(String) ? [repos] : repos
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.instance_of?(Array) ? services : [services]
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.instance_of?(String) ? [services] : services
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