kanrisuru 0.2.4 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/kanrisuru.gemspec +8 -8
- data/lib/kanrisuru/core.rb +6 -0
- data/lib/kanrisuru/core/apt.rb +12 -25
- data/lib/kanrisuru/core/file.rb +1 -1
- data/lib/kanrisuru/core/path.rb +0 -1
- data/lib/kanrisuru/core/stat.rb +1 -2
- data/lib/kanrisuru/core/system.rb +2 -1
- data/lib/kanrisuru/core/yum.rb +389 -0
- data/lib/kanrisuru/remote/os.rb +3 -1
- data/lib/kanrisuru/util/bits.rb +19 -0
- data/lib/kanrisuru/util/os_family.rb +17 -9
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/core/apt_spec.rb +21 -0
- data/spec/functional/core/yum_spec.rb +160 -0
- data/spec/unit/template_spec.rb +0 -2
- data/spec/unit/util_spec.rb +1 -0
- metadata +34 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34a295375b187db49db38cccaa4fdd155d706378b1615d58744aa62f9172cada
|
4
|
+
data.tar.gz: ed2e0995c40b0fa3902100377bb275e1413d98caf13bbd60b04bceb122d81301
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df90e5eca434eb978f0396919571f08c976aed094f096b62988368fcc93b2a1177c46e947aceb732273f420cd28d7ebd8ccf4db532398ddbdd87e7d4ccf8afc6
|
7
|
+
data.tar.gz: 8c0b99e559e4f50610532dc57ef5ff0bb544259deac214cf03edcab3463f904e5935bcc4e6cdf041a4b231a44476df51084d3ba7570d8d4978dae14c31ca31d8
|
data/README.md
CHANGED
@@ -146,6 +146,9 @@ cluster.execute('uname') #=> {host: 'host1', result: 'Linux'}, {host: 'host2', r
|
|
146
146
|
| Upload to remote server | upload | scp | core | https://linux.die.net/man/1/scp | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
147
147
|
| Download from remote server | download | scp | core | https://linux.die.net/man/1/scp | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
148
148
|
| Wget | wget | wget | core | https://linux.die.net/man/1/wget | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
149
|
+
| **Packages** | | | | | | | | | | | |
|
150
|
+
| Apt | apt | apt | core | https://linux.die.net/man/1/apt | [x] | [x] | | | | | |
|
151
|
+
| Yum | yum | yum | core | https://linux.die.net/man/1/yum | | | [x] | [x] | [x] | | |
|
149
152
|
|
150
153
|
## Development
|
151
154
|
|
data/kanrisuru.gemspec
CHANGED
@@ -9,19 +9,19 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.email = 'ryan@avamia.com'
|
10
10
|
gem.license = 'MIT'
|
11
11
|
gem.summary = 'Manage remote servers over ssh with ruby.'
|
12
|
+
gem.description = 'Manage remote servers over ssh with ruby.'
|
12
13
|
gem.homepage = 'https://github.com/avamia/kanrisuru'
|
13
14
|
|
14
15
|
gem.required_ruby_version = '>= 2.5.0'
|
15
|
-
gem.required_rubygems_version = '>= 1.8.11'
|
16
16
|
|
17
|
-
gem.add_development_dependency 'rspec'
|
18
|
-
gem.add_development_dependency 'rubocop'
|
19
|
-
gem.add_development_dependency 'rubocop-rspec'
|
20
|
-
gem.add_development_dependency 'simplecov'
|
17
|
+
gem.add_development_dependency 'rspec', '~> 3.10'
|
18
|
+
gem.add_development_dependency 'rubocop', '~> 1.12'
|
19
|
+
gem.add_development_dependency 'rubocop-rspec', '~> 2.2'
|
20
|
+
gem.add_development_dependency 'simplecov', '~> 0.21'
|
21
21
|
|
22
|
-
gem.add_runtime_dependency 'net-ping'
|
23
|
-
gem.add_runtime_dependency 'net-scp'
|
24
|
-
gem.add_runtime_dependency 'net-ssh'
|
22
|
+
gem.add_runtime_dependency 'net-ping', '~> 2.0'
|
23
|
+
gem.add_runtime_dependency 'net-scp', '~> 3.0'
|
24
|
+
gem.add_runtime_dependency 'net-ssh', '~> 6.1'
|
25
25
|
|
26
26
|
gem.files = `git ls-files`.split("\n")
|
27
27
|
gem.require_paths = ['lib']
|
data/lib/kanrisuru/core.rb
CHANGED
@@ -15,6 +15,8 @@ require_relative 'core/transfer'
|
|
15
15
|
require_relative 'core/ip'
|
16
16
|
require_relative 'core/socket'
|
17
17
|
require_relative 'core/apt'
|
18
|
+
require_relative 'core/yum'
|
19
|
+
require_relative 'core/zypper'
|
18
20
|
|
19
21
|
module Kanrisuru
|
20
22
|
module Remote
|
@@ -34,6 +36,8 @@ module Kanrisuru
|
|
34
36
|
os_include Kanrisuru::Core::IP
|
35
37
|
os_include Kanrisuru::Core::Socket
|
36
38
|
os_include Kanrisuru::Core::Apt
|
39
|
+
os_include Kanrisuru::Core::Yum
|
40
|
+
os_include Kanrisuru::Core::Zypper
|
37
41
|
end
|
38
42
|
|
39
43
|
class Cluster
|
@@ -51,6 +55,8 @@ module Kanrisuru
|
|
51
55
|
os_collection Kanrisuru::Core::IP
|
52
56
|
os_collection Kanrisuru::Core::Socket
|
53
57
|
os_collection Kanrisuru::Core::Apt
|
58
|
+
os_collection Kanrisuru::Core::Yum
|
59
|
+
os_collection Kanrisuru::Core::Zypper
|
54
60
|
end
|
55
61
|
end
|
56
62
|
end
|
data/lib/kanrisuru/core/apt.rb
CHANGED
@@ -119,7 +119,7 @@ module Kanrisuru
|
|
119
119
|
lines.shift
|
120
120
|
|
121
121
|
result = []
|
122
|
-
lines.each
|
122
|
+
lines.each do |line|
|
123
123
|
item = parse_apt_line(line)
|
124
124
|
next unless item
|
125
125
|
|
@@ -210,17 +210,17 @@ module Kanrisuru
|
|
210
210
|
rows = []
|
211
211
|
|
212
212
|
current_row = nil
|
213
|
-
|
213
|
+
description = ''
|
214
214
|
|
215
215
|
lines.each do |line|
|
216
216
|
next if line == 'WARNING: apt does not have a stable CLI interface. Use with caution in scripts.'
|
217
|
-
next if [
|
217
|
+
next if ['', nil, '.'].include?(line)
|
218
218
|
|
219
219
|
case line
|
220
220
|
when /^Package:/
|
221
221
|
unless current_row.nil?
|
222
|
-
current_row.
|
223
|
-
|
222
|
+
current_row.description = description.strip
|
223
|
+
description = ''
|
224
224
|
rows << current_row
|
225
225
|
end
|
226
226
|
|
@@ -241,9 +241,11 @@ module Kanrisuru
|
|
241
241
|
when /^Bugs:/
|
242
242
|
current_row.bugs = extract_single_line(line)
|
243
243
|
when /^Installed-Size:/
|
244
|
-
|
244
|
+
size = Kanrisuru::Util::Bits.normalize_size(extract_single_line(line))
|
245
|
+
current_row.install_size = size
|
245
246
|
when /^Download-Size:/
|
246
|
-
|
247
|
+
size = Kanrisuru::Util::Bits.normalize_size(extract_single_line(line))
|
248
|
+
current_row.download_size = size
|
247
249
|
when /^Depends:/
|
248
250
|
current_row.dependencies = parse_comma_values(extract_single_line(line))
|
249
251
|
when /^Provides:/
|
@@ -269,13 +271,13 @@ module Kanrisuru
|
|
269
271
|
when /^APT-Manual-Installed:/
|
270
272
|
current_row.apt_manual_installed = extract_single_line(line) == 'yes'
|
271
273
|
when /^Description:/
|
272
|
-
current_row.
|
274
|
+
current_row.summary = extract_single_line(line)
|
273
275
|
else
|
274
|
-
|
276
|
+
description += " #{line.strip}"
|
275
277
|
end
|
276
278
|
end
|
277
279
|
|
278
|
-
current_row.
|
280
|
+
current_row.description = description.strip
|
279
281
|
rows << current_row
|
280
282
|
rows
|
281
283
|
end
|
@@ -294,21 +296,6 @@ module Kanrisuru
|
|
294
296
|
AptSource.new(url, dist, architecture)
|
295
297
|
end
|
296
298
|
|
297
|
-
def normalize_size(string)
|
298
|
-
size, unit = string.split
|
299
|
-
size = size.to_i
|
300
|
-
case unit.downcase
|
301
|
-
when 'b'
|
302
|
-
Kanrisuru::Util::Bits.convert_bytes(size, :byte, :kilobyte)
|
303
|
-
when 'kb'
|
304
|
-
size
|
305
|
-
when 'mb'
|
306
|
-
Kanrisuru::Util::Bits.convert_from_mb(size, :kilobyte).to_i
|
307
|
-
when 'gb'
|
308
|
-
Kanrisuru::Util::Bits.convert_from_gb(size, :kilobyte).to_i
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
299
|
def parse_apt_line(line)
|
313
300
|
values = line.split('/')
|
314
301
|
return if values.length < 2
|
data/lib/kanrisuru/core/file.rb
CHANGED
data/lib/kanrisuru/core/path.rb
CHANGED
data/lib/kanrisuru/core/stat.rb
CHANGED
@@ -15,6 +15,7 @@ module Kanrisuru
|
|
15
15
|
os_define :linux, :kill
|
16
16
|
|
17
17
|
os_define :linux, :uptime
|
18
|
+
|
18
19
|
os_define :linux, :w
|
19
20
|
os_define :linux, :who
|
20
21
|
|
@@ -184,7 +185,7 @@ module Kanrisuru
|
|
184
185
|
|
185
186
|
def w(opts = {})
|
186
187
|
users = opts[:users]
|
187
|
-
command = Kanrisuru::Command.new('w -
|
188
|
+
command = Kanrisuru::Command.new('w -hi')
|
188
189
|
|
189
190
|
command << users if Kanrisuru::Util.present?(users)
|
190
191
|
|
@@ -0,0 +1,389 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
module Kanrisuru
|
6
|
+
module Core
|
7
|
+
module Yum
|
8
|
+
extend OsPackage::Define
|
9
|
+
|
10
|
+
os_define :fedora, :yum
|
11
|
+
|
12
|
+
YumPackageOverview = Struct.new(:package, :architecture, :version, :installed)
|
13
|
+
YumPackageSearchResult = Struct.new(:package, :architecture, :summary)
|
14
|
+
YumPackageDetail = Struct.new(
|
15
|
+
:package,
|
16
|
+
:version,
|
17
|
+
:release,
|
18
|
+
:architecture,
|
19
|
+
:install_size,
|
20
|
+
:source,
|
21
|
+
:yum_id,
|
22
|
+
:repository,
|
23
|
+
:summary,
|
24
|
+
:url,
|
25
|
+
:license,
|
26
|
+
:description
|
27
|
+
)
|
28
|
+
|
29
|
+
YumRepolist = Struct.new(
|
30
|
+
:id,
|
31
|
+
:name,
|
32
|
+
:status,
|
33
|
+
:revision,
|
34
|
+
:packages,
|
35
|
+
:available_packages,
|
36
|
+
:repo_size,
|
37
|
+
:mirrors,
|
38
|
+
:metalink,
|
39
|
+
:updated,
|
40
|
+
:baseurl,
|
41
|
+
:expire,
|
42
|
+
:filters,
|
43
|
+
:filename
|
44
|
+
)
|
45
|
+
|
46
|
+
def yum(action, opts = {})
|
47
|
+
case action
|
48
|
+
when 'install'
|
49
|
+
yum_install(opts)
|
50
|
+
when 'localinstall'
|
51
|
+
yum_localinstall(opts)
|
52
|
+
when 'list'
|
53
|
+
yum_list(opts)
|
54
|
+
when 'search'
|
55
|
+
yum_search(opts)
|
56
|
+
when 'info'
|
57
|
+
yum_info(opts)
|
58
|
+
when 'repolist'
|
59
|
+
yum_repolist(opts)
|
60
|
+
when 'clean'
|
61
|
+
yum_clean(opts)
|
62
|
+
when 'remove'
|
63
|
+
yum_remove(opts)
|
64
|
+
when 'autoremove'
|
65
|
+
yum_autoremove(opts)
|
66
|
+
when 'erase'
|
67
|
+
yum_erase(opts)
|
68
|
+
when 'update'
|
69
|
+
yum_update(opts)
|
70
|
+
when 'upgrade'
|
71
|
+
yum_upgrade(opts)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def yum_install(opts)
|
78
|
+
command = Kanrisuru::Command.new('yum install')
|
79
|
+
command.append_flag('-y')
|
80
|
+
|
81
|
+
packages = Kanrisuru::Util.string_join_array(opts[:packages], ' ')
|
82
|
+
command << packages
|
83
|
+
|
84
|
+
execute_shell(command)
|
85
|
+
Kanrisuru::Result.new(command)
|
86
|
+
end
|
87
|
+
|
88
|
+
def yum_localinstall(opts)
|
89
|
+
command = Kanrisuru::Command.new('yum localinstall')
|
90
|
+
yum_disable_repo(command, opts[:disable_repo])
|
91
|
+
command.append_flag('-y')
|
92
|
+
|
93
|
+
if Kanrisuru::Util.present?(opts[:repos])
|
94
|
+
repos = Kanrisuru::Util.string_join_array(opts[:repos], ' ')
|
95
|
+
command << repos
|
96
|
+
end
|
97
|
+
|
98
|
+
execute_shell(command)
|
99
|
+
|
100
|
+
Kanrisuru::Result.new(command)
|
101
|
+
end
|
102
|
+
|
103
|
+
def yum_list(opts)
|
104
|
+
command = Kanrisuru::Command.new('yum list')
|
105
|
+
|
106
|
+
yum_disable_repo(command, opts[:disable_repo])
|
107
|
+
|
108
|
+
command.append_flag('all', opts[:all])
|
109
|
+
command.append_flag('available', opts[:available])
|
110
|
+
command.append_flag('updates', opts[:updates])
|
111
|
+
command.append_flag('installed', opts[:installed])
|
112
|
+
command.append_flag('extras', opts[:extras])
|
113
|
+
command.append_flag('obsoletes', opts[:obsoletes])
|
114
|
+
|
115
|
+
command << opts[:query] if Kanrisuru::Util.present?(opts[:query])
|
116
|
+
|
117
|
+
pipe_output_newline(command)
|
118
|
+
|
119
|
+
execute_shell(command)
|
120
|
+
|
121
|
+
Kanrisuru::Result.new(command) do |cmd|
|
122
|
+
lines = cmd.to_a
|
123
|
+
result = []
|
124
|
+
lines.each do |line|
|
125
|
+
item = parse_yum_line(line)
|
126
|
+
next unless item
|
127
|
+
|
128
|
+
result << item
|
129
|
+
end
|
130
|
+
|
131
|
+
result
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def yum_remove(opts)
|
136
|
+
command = Kanrisuru::Command.new('yum remove')
|
137
|
+
command.append_flag('-y')
|
138
|
+
|
139
|
+
packages = Kanrisuru::Util.string_join_array(opts[:packages], ' ')
|
140
|
+
raise ArugmentError, "can't remove yum" if packages.include?('yum')
|
141
|
+
|
142
|
+
command << packages
|
143
|
+
|
144
|
+
execute_shell(command)
|
145
|
+
Kanrisuru::Result.new(command)
|
146
|
+
end
|
147
|
+
|
148
|
+
def yum_clean(opts)
|
149
|
+
command = Kanrisuru::Command.new('yum clean')
|
150
|
+
|
151
|
+
command.append_flag('dbcache', opts[:dbcache])
|
152
|
+
command.append_flag('expire-cache', opts[:expire_cache])
|
153
|
+
command.append_flag('metadata', opts[:metadata])
|
154
|
+
command.append_flag('packages', opts[:packages])
|
155
|
+
command.append_flag('headers', opts[:headers])
|
156
|
+
command.append_flag('rpmdb', opts[:rpmdb])
|
157
|
+
command.append_flag('all', opts[:all])
|
158
|
+
|
159
|
+
execute_shell(command)
|
160
|
+
|
161
|
+
Kanrisuru::Result.new(command)
|
162
|
+
end
|
163
|
+
|
164
|
+
def yum_autoremove(_opts)
|
165
|
+
command = Kanrisuru::Command.new('yum autoremove')
|
166
|
+
command.append_flag('-y')
|
167
|
+
execute_shell(command)
|
168
|
+
Kanrisuru::Result.new(command)
|
169
|
+
end
|
170
|
+
|
171
|
+
def yum_erase(opts)
|
172
|
+
command = Kanrisuru::Command.new('yum erase')
|
173
|
+
command.append_flag('-y')
|
174
|
+
|
175
|
+
packages = Kanrisuru::Util.string_join_array(opts[:packages], ' ')
|
176
|
+
raise ArugmentError, "can't erase yum" if packages.include?('yum')
|
177
|
+
|
178
|
+
command << packages
|
179
|
+
|
180
|
+
execute_shell(command)
|
181
|
+
Kanrisuru::Result.new(command)
|
182
|
+
end
|
183
|
+
|
184
|
+
def yum_update(_opts)
|
185
|
+
command = Kanrisuru::Command.new('yum update')
|
186
|
+
command.append_flag('-y')
|
187
|
+
execute_shell(command)
|
188
|
+
Kanrisuru::Result.new(command)
|
189
|
+
end
|
190
|
+
|
191
|
+
def yum_upgrade(_opts)
|
192
|
+
command = Kanrisuru::Command.new('yum upgrade')
|
193
|
+
command.append_flag('-y')
|
194
|
+
execute_shell(command)
|
195
|
+
Kanrisuru::Result.new(command)
|
196
|
+
end
|
197
|
+
|
198
|
+
def yum_search(opts)
|
199
|
+
command = Kanrisuru::Command.new('yum search')
|
200
|
+
command.append_flag('all', opts[:all])
|
201
|
+
command << Kanrisuru::Util.string_join_array(opts[:packages], ' ')
|
202
|
+
|
203
|
+
pipe_output_newline(command)
|
204
|
+
|
205
|
+
execute_shell(command)
|
206
|
+
|
207
|
+
Kanrisuru::Result.new(command) do |cmd|
|
208
|
+
lines = cmd.to_a
|
209
|
+
|
210
|
+
result = []
|
211
|
+
lines.each do |line|
|
212
|
+
line = line.gsub(/\s{2}/, '')
|
213
|
+
values = line.split(' : ')
|
214
|
+
next if values.length != 2
|
215
|
+
|
216
|
+
full_name = values[0]
|
217
|
+
name, architecture = full_name.split('.')
|
218
|
+
summary = values[1]
|
219
|
+
|
220
|
+
result << YumPackageSearchResult.new(name, architecture, summary)
|
221
|
+
end
|
222
|
+
|
223
|
+
result
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
def yum_repolist(opts)
|
228
|
+
command = Kanrisuru::Command.new('yum repolist')
|
229
|
+
command.append_flag('--verbose')
|
230
|
+
|
231
|
+
command << Kanrisuru::Util.string_join_array(opts[:repos], ' ') if opts[:repos]
|
232
|
+
|
233
|
+
execute_shell(command)
|
234
|
+
|
235
|
+
Kanrisuru::Result.new(command) do |cmd|
|
236
|
+
lines = cmd.to_a
|
237
|
+
|
238
|
+
rows = []
|
239
|
+
current_row = nil
|
240
|
+
|
241
|
+
lines.each do |line|
|
242
|
+
case line
|
243
|
+
when /^Repo-id/
|
244
|
+
if current_row
|
245
|
+
rows << current_row
|
246
|
+
current_row = nil
|
247
|
+
end
|
248
|
+
|
249
|
+
current_row = YumRepolist.new
|
250
|
+
current_row.id = extract_single_yum_line(line)
|
251
|
+
when /^Repo-name/
|
252
|
+
current_row.name = extract_single_yum_line(line)
|
253
|
+
when /^Repo-revision/
|
254
|
+
current_row.revision = extract_single_yum_line(line).to_i
|
255
|
+
when /^Repo-updated/, /^Updated/
|
256
|
+
text = extract_single_yum_line(line)
|
257
|
+
current_row.updated = DateTime.parse(text)
|
258
|
+
when /^Repo-pkgs/
|
259
|
+
current_row.packages = extract_single_yum_line(line).to_i
|
260
|
+
when /^Repo-size/
|
261
|
+
size = Kanrisuru::Util::Bits.normalize_size(extract_single_yum_line(line))
|
262
|
+
current_row.repo_size = size
|
263
|
+
when /^Repo-mirrors/
|
264
|
+
current_row.mirrors = extract_single_yum_line(line)
|
265
|
+
when /^Repo-metalink/
|
266
|
+
current_row.metalink = extract_single_yum_line(line)
|
267
|
+
when /^Repo-baseurl/
|
268
|
+
current_row.baseurl = extract_single_yum_line(line).split[0]
|
269
|
+
when /^Repo-expire/
|
270
|
+
current_row.expire = extract_single_yum_line(line)
|
271
|
+
when /^Repo-filename/
|
272
|
+
current_row.filename = extract_single_yum_line(line)
|
273
|
+
when /^Repo-available-pkgs/
|
274
|
+
current_row.available_packages = extract_single_yum_line(line).to_i
|
275
|
+
when /^Filter/
|
276
|
+
current_row.filters = extract_single_yum_line(line)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
rows << current_row
|
281
|
+
rows
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
def yum_info(opts)
|
286
|
+
command = Kanrisuru::Command.new('yum info')
|
287
|
+
command.append_flag('--quiet')
|
288
|
+
command.append_flag('installed', opts[:installed])
|
289
|
+
|
290
|
+
command << Kanrisuru::Util.string_join_array(opts[:packages], ' ') if opts[:packages]
|
291
|
+
|
292
|
+
execute_shell(command)
|
293
|
+
|
294
|
+
Kanrisuru::Result.new(command) do |cmd|
|
295
|
+
lines = cmd.to_a
|
296
|
+
|
297
|
+
rows = []
|
298
|
+
current_row = nil
|
299
|
+
description = ''
|
300
|
+
|
301
|
+
lines.each do |line|
|
302
|
+
next unless line.include?(': ')
|
303
|
+
|
304
|
+
case line
|
305
|
+
when /^Name/
|
306
|
+
unless current_row.nil?
|
307
|
+
current_row.description = description.strip
|
308
|
+
description = ''
|
309
|
+
rows << current_row
|
310
|
+
end
|
311
|
+
|
312
|
+
current_row = YumPackageDetail.new
|
313
|
+
current_row.package = extract_single_yum_line(line)
|
314
|
+
when /^Arch/, /^Architecture/
|
315
|
+
current_row.architecture = extract_single_yum_line(line)
|
316
|
+
when /^Version/
|
317
|
+
current_row.version = extract_single_yum_line(line)
|
318
|
+
when /^Release/
|
319
|
+
current_row.release = extract_single_yum_line(line)
|
320
|
+
when /^Source/
|
321
|
+
current_row.source = extract_single_yum_line(line)
|
322
|
+
when /^Repository/
|
323
|
+
current_row.repository = extract_single_yum_line(line)
|
324
|
+
when /^Summary/
|
325
|
+
current_row.summary = extract_single_yum_line(line)
|
326
|
+
when /^URL/, /^Url/
|
327
|
+
current_row.url = extract_single_yum_line(line)
|
328
|
+
when /^License/
|
329
|
+
current_row.license = extract_single_yum_line(line)
|
330
|
+
when /^From repo/
|
331
|
+
current_row.yum_id = extract_single_yum_line(line)
|
332
|
+
when /^Size/
|
333
|
+
size = Kanrisuru::Util::Bits.normalize_size(extract_single_yum_line(line))
|
334
|
+
current_row.install_size = size
|
335
|
+
when /^Description/
|
336
|
+
description = extract_single_yum_line(line)
|
337
|
+
else
|
338
|
+
next if line == ''
|
339
|
+
|
340
|
+
description += " #{extract_single_yum_line(line).strip}"
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
if current_row
|
345
|
+
current_row.description = description.strip
|
346
|
+
rows << current_row
|
347
|
+
end
|
348
|
+
|
349
|
+
rows
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
def extract_single_yum_line(line)
|
354
|
+
values = line.split(': ', 2)
|
355
|
+
values.length == 2 ? values[1] : ''
|
356
|
+
end
|
357
|
+
|
358
|
+
def parse_yum_line(line)
|
359
|
+
values = line.split
|
360
|
+
return if values.length != 3
|
361
|
+
return unless /^\w+\.\w+$/i.match(values[0])
|
362
|
+
|
363
|
+
full_name = values[0]
|
364
|
+
version = values[1]
|
365
|
+
|
366
|
+
name, architecture = full_name.split('.')
|
367
|
+
|
368
|
+
YumPackageOverview.new(name, architecture, version)
|
369
|
+
end
|
370
|
+
|
371
|
+
## Bug reported on the output of the yum command
|
372
|
+
## https://bugzilla.redhat.com/show_bug.cgi?id=584525
|
373
|
+
## that autowraps text when used in a script beyond 80 chars wide.
|
374
|
+
## Work-around with formatting by
|
375
|
+
## piping through trimming extra newline chars.
|
376
|
+
def pipe_output_newline(command)
|
377
|
+
command | "tr '\\n' '#'"
|
378
|
+
command | "sed -e 's/# / /g'"
|
379
|
+
command | "tr '#' '\\n'"
|
380
|
+
end
|
381
|
+
|
382
|
+
def yum_disable_repo(command, repo)
|
383
|
+
return unless Kanrisuru::Util.present?(repo)
|
384
|
+
|
385
|
+
command.append_flag("--disablerepo=#{repo}")
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|
data/lib/kanrisuru/remote/os.rb
CHANGED
data/lib/kanrisuru/util/bits.rb
CHANGED
@@ -3,6 +3,25 @@
|
|
3
3
|
module Kanrisuru
|
4
4
|
class Util
|
5
5
|
class Bits
|
6
|
+
def self.normalize_size(string)
|
7
|
+
size, unit = string.split
|
8
|
+
size = size.to_f
|
9
|
+
unit ||= 'b'
|
10
|
+
|
11
|
+
return 0 if size.zero?
|
12
|
+
|
13
|
+
case unit.downcase
|
14
|
+
when 'b'
|
15
|
+
Kanrisuru::Util::Bits.convert_bytes(size, :byte, :kilobyte)
|
16
|
+
when 'kb', 'k', 'kib'
|
17
|
+
size
|
18
|
+
when 'mb', 'm', 'mib'
|
19
|
+
Kanrisuru::Util::Bits.convert_from_mb(size, :kilobyte).to_i
|
20
|
+
when 'gb', 'g', 'gib'
|
21
|
+
Kanrisuru::Util::Bits.convert_from_gb(size, :kilobyte).to_i
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
6
25
|
def self.convert_from_kb(value, metric)
|
7
26
|
convert_bytes(value, :kilobyte, metric)
|
8
27
|
end
|
@@ -145,6 +145,11 @@ module Kanrisuru
|
|
145
145
|
state: 'current',
|
146
146
|
type: 'distribution'
|
147
147
|
},
|
148
|
+
rhel: {
|
149
|
+
name: 'RHEL',
|
150
|
+
type: 'alias',
|
151
|
+
to: 'redhat'
|
152
|
+
},
|
148
153
|
centos: {
|
149
154
|
name: 'CentOS',
|
150
155
|
type: 'alias',
|
@@ -158,27 +163,30 @@ module Kanrisuru
|
|
158
163
|
state: 'current',
|
159
164
|
type: 'distribution'
|
160
165
|
},
|
161
|
-
|
162
|
-
name: '
|
166
|
+
sles: {
|
167
|
+
name: 'SUSE Linux Enterprise Server',
|
163
168
|
os_family: 'linux',
|
164
169
|
upstream: 'linux',
|
165
|
-
model: '
|
170
|
+
model: 'commercial',
|
166
171
|
state: 'current',
|
167
172
|
type: 'distribution'
|
168
173
|
},
|
169
174
|
opensuse_leap: {
|
170
175
|
name: 'openSUSE Leap',
|
171
|
-
|
172
|
-
|
176
|
+
os_family: 'linux',
|
177
|
+
upstream: 'sles',
|
178
|
+
model: 'open_source',
|
179
|
+
state: 'current',
|
180
|
+
type: 'distribution'
|
173
181
|
},
|
174
|
-
|
175
|
-
name: '
|
182
|
+
opensuse: {
|
183
|
+
name: 'openSUSE',
|
176
184
|
os_family: 'linux',
|
177
185
|
upstream: 'linux',
|
178
|
-
model: '
|
186
|
+
model: 'open_source',
|
179
187
|
state: 'current',
|
180
188
|
type: 'distribution'
|
181
|
-
}
|
189
|
+
},
|
182
190
|
}
|
183
191
|
|
184
192
|
def self.family_include_distribution?(family, dist)
|
data/lib/kanrisuru/version.rb
CHANGED
@@ -25,6 +25,16 @@ RSpec.describe Kanrisuru::Core::Apt do
|
|
25
25
|
host.su('root')
|
26
26
|
result = host.apt('install', packages: %w[ffmpeg curl])
|
27
27
|
expect(result).to be_success
|
28
|
+
|
29
|
+
result = host.which('ffmpeg')
|
30
|
+
expect(result).to be_success
|
31
|
+
paths = result.map(&:path)
|
32
|
+
expect(paths).to include(match('ffmpeg'))
|
33
|
+
|
34
|
+
result = host.which('curl')
|
35
|
+
expect(result).to be_success
|
36
|
+
paths = result.map(&:path)
|
37
|
+
expect(paths).to include(match('curl'))
|
28
38
|
end
|
29
39
|
end
|
30
40
|
end
|
@@ -80,6 +90,17 @@ RSpec.describe Kanrisuru::Core::Apt do
|
|
80
90
|
end
|
81
91
|
end
|
82
92
|
|
93
|
+
describe 'apt update' do
|
94
|
+
it 'updates packages' do
|
95
|
+
case os_name
|
96
|
+
when 'debian', 'ubuntu'
|
97
|
+
host.su('root')
|
98
|
+
result = host.apt('update')
|
99
|
+
expect(result).to be_success
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
83
104
|
describe 'apt upgrade' do
|
84
105
|
it 'upgrades packages' do
|
85
106
|
case os_name
|
@@ -0,0 +1,160 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Kanrisuru::Core::Yum do
|
6
|
+
TestHosts.each_os do |os_name|
|
7
|
+
context "with #{os_name}" do
|
8
|
+
let(:host_json) { TestHosts.host(os_name) }
|
9
|
+
let(:host) do
|
10
|
+
Kanrisuru::Remote::Host.new(
|
11
|
+
host: host_json['hostname'],
|
12
|
+
username: host_json['username'],
|
13
|
+
keys: [host_json['ssh_key']]
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
after do
|
18
|
+
host.disconnect
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'upgrades packages' do
|
22
|
+
case os_name
|
23
|
+
when 'centos', 'rhel', 'fedora'
|
24
|
+
host.su('root')
|
25
|
+
result = host.yum('upgrade')
|
26
|
+
expect(result).to be_success
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'updates packages' do
|
31
|
+
case os_name
|
32
|
+
when 'centos', 'rhel', 'fedora'
|
33
|
+
host.su('root')
|
34
|
+
result = host.yum('update')
|
35
|
+
expect(result).to be_success
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'installs local package from RPM' do
|
40
|
+
case os_name
|
41
|
+
when 'fedora'
|
42
|
+
package = 'rpmfusion-free-release-32.noarch.rpm'
|
43
|
+
url = "https://download1.rpmfusion.org/free/fedora/#{package}"
|
44
|
+
|
45
|
+
result = host.wget(url)
|
46
|
+
expect(result).to be_success
|
47
|
+
file = host.file("~/#{package}")
|
48
|
+
expect(file).to be_exists
|
49
|
+
|
50
|
+
host.su('root')
|
51
|
+
result = host.yum('localinstall', repos: file.expand_path)
|
52
|
+
expect(result).to be_success
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'lists installed packages' do
|
57
|
+
case os_name
|
58
|
+
when 'centos', 'rhel', 'fedora'
|
59
|
+
result = host.yum('list', installed: true)
|
60
|
+
expect(result).to be_success
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'lists repos' do
|
65
|
+
case os_name
|
66
|
+
when 'centos', 'rhel', 'fedora'
|
67
|
+
result = host.yum('repolist')
|
68
|
+
expect(result).to be_success
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'lists installed repos' do
|
73
|
+
case os_name
|
74
|
+
when 'centos', 'rhel', 'fedora'
|
75
|
+
result = host.yum('repolist', repos: 'updates')
|
76
|
+
expect(result).to be_success
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'searches a single package' do
|
81
|
+
case os_name
|
82
|
+
when 'centos', 'rhel', 'fedora'
|
83
|
+
result = host.yum('search', packages: 'curl')
|
84
|
+
expect(result).to be_success
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'searches all packages' do
|
89
|
+
case os_name
|
90
|
+
when 'centos', 'rhel', 'fedora'
|
91
|
+
result = host.yum('search', all: true, packages: %w[curl ffmpeg])
|
92
|
+
expect(result).to be_success
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'installs a package' do
|
97
|
+
case os_name
|
98
|
+
when 'centos', 'rhel', 'fedora'
|
99
|
+
host.su('root')
|
100
|
+
result = host.yum('install', packages: %(ffmpeg curl))
|
101
|
+
expect(result).to be_success
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'removes installed packages' do
|
106
|
+
case os_name
|
107
|
+
when 'centos', 'rhel', 'fedora'
|
108
|
+
host.su('root')
|
109
|
+
result = host.yum('remove', packages: ['ffmpeg'])
|
110
|
+
expect(result).to be_success
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'purges installed packages' do
|
115
|
+
case os_name
|
116
|
+
when 'centos', 'rhel', 'fedora'
|
117
|
+
host.su('root')
|
118
|
+
result = host.yum('erase', packages: ['ffmpeg'])
|
119
|
+
expect(result).to be_success
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'gets info for one package' do
|
124
|
+
case os_name
|
125
|
+
when 'centos', 'rhel', 'fedora'
|
126
|
+
host.su('root')
|
127
|
+
result = host.yum('info', packages: 'yum')
|
128
|
+
expect(result).to be_success
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'gets info for installed packages' do
|
133
|
+
case os_name
|
134
|
+
when 'centos', 'rhel', 'fedora'
|
135
|
+
host.su('root')
|
136
|
+
result = host.yum('info', installed: true)
|
137
|
+
expect(result).to be_success
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'cleans packages' do
|
142
|
+
case os_name
|
143
|
+
when 'centos', 'rhel', 'fedora'
|
144
|
+
host.su('root')
|
145
|
+
result = host.yum('clean', all: true)
|
146
|
+
expect(result).to be_success
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'autoremoves packages' do
|
151
|
+
case os_name
|
152
|
+
when 'centos', 'rhel', 'fedora'
|
153
|
+
host.su('root')
|
154
|
+
result = host.yum('autoremove')
|
155
|
+
expect(result).to be_success
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
data/spec/unit/template_spec.rb
CHANGED
data/spec/unit/util_spec.rb
CHANGED
@@ -59,6 +59,7 @@ RSpec.describe Kanrisuru::Util do
|
|
59
59
|
expect(Kanrisuru::Util::OsFamily.upstream_include_distribution?('linux', 'linux_mint')).to eq(true)
|
60
60
|
|
61
61
|
expect(Kanrisuru::Util::OsFamily.upstream_include_distribution?('fedora', 'redhat')).to eq(true)
|
62
|
+
expect(Kanrisuru::Util::OsFamily.upstream_include_distribution?('sles', 'opensuse_leap')).to eq(true)
|
62
63
|
expect(Kanrisuru::Util::OsFamily.upstream_include_distribution?('fedora', 'centos')).to eq(true)
|
63
64
|
|
64
65
|
expect(Kanrisuru::Util::OsFamily.upstream_include_distribution?('unix_like', 'linux_mint')).to eq(false)
|
metadata
CHANGED
@@ -1,114 +1,114 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kanrisuru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
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-
|
11
|
+
date: 2021-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.10'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '3.10'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rubocop
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.12'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '1.12'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rubocop-rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2.2'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: simplecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '0.21'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
68
|
+
version: '0.21'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: net-ping
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
75
|
+
version: '2.0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
82
|
+
version: '2.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: net-scp
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
89
|
+
version: '3.0'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
96
|
+
version: '3.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: net-ssh
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '6.1'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
111
|
-
description:
|
110
|
+
version: '6.1'
|
111
|
+
description: Manage remote servers over ssh with ruby.
|
112
112
|
email: ryan@avamia.com
|
113
113
|
executables: []
|
114
114
|
extensions: []
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- lib/kanrisuru/core/system.rb
|
147
147
|
- lib/kanrisuru/core/transfer.rb
|
148
148
|
- lib/kanrisuru/core/user.rb
|
149
|
+
- lib/kanrisuru/core/yum.rb
|
149
150
|
- lib/kanrisuru/logger.rb
|
150
151
|
- lib/kanrisuru/mode.rb
|
151
152
|
- lib/kanrisuru/os_package.rb
|
@@ -180,6 +181,7 @@ files:
|
|
180
181
|
- spec/functional/core/system_spec.rb
|
181
182
|
- spec/functional/core/transfer_spec.rb
|
182
183
|
- spec/functional/core/user_spec.rb
|
184
|
+
- spec/functional/core/yum_spec.rb
|
183
185
|
- spec/functional/os_package_spec.rb
|
184
186
|
- spec/functional/remote/cluster_spec.rb
|
185
187
|
- spec/functional/remote/cpu_spec.rb
|
@@ -216,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
218
|
requirements:
|
217
219
|
- - ">="
|
218
220
|
- !ruby/object:Gem::Version
|
219
|
-
version:
|
221
|
+
version: '0'
|
220
222
|
requirements: []
|
221
223
|
rubygems_version: 3.1.2
|
222
224
|
signing_key:
|