kanrisuru 0.16.0 → 0.16.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/lib/kanrisuru/command.rb +2 -3
- data/lib/kanrisuru/core/zypper/commands/add_repo.rb +1 -8
- data/lib/kanrisuru/core/zypper/commands/add_service.rb +4 -2
- data/lib/kanrisuru/core/zypper/commands/info.rb +1 -2
- data/lib/kanrisuru/core/zypper/commands/install.rb +2 -3
- data/lib/kanrisuru/core/zypper/commands/modify_repo.rb +1 -7
- data/lib/kanrisuru/core/zypper/commands/modify_service.rb +3 -1
- data/lib/kanrisuru/core/zypper/commands/remove.rb +1 -2
- data/lib/kanrisuru/core/zypper/commands/remove_repo.rb +3 -3
- data/lib/kanrisuru/core/zypper/commands/remove_service.rb +6 -1
- data/lib/kanrisuru/core/zypper/commands/search.rb +1 -3
- data/lib/kanrisuru/core/zypper/commands/source_install.rb +2 -0
- data/lib/kanrisuru/core/zypper/commands.rb +10 -1
- data/lib/kanrisuru/mode/permission.rb +103 -0
- data/lib/kanrisuru/mode.rb +2 -98
- data/lib/kanrisuru/os_package.rb +2 -0
- data/lib/kanrisuru/remote/fstab/entry.rb +154 -0
- data/lib/kanrisuru/remote/fstab/options.rb +143 -0
- data/lib/kanrisuru/remote/fstab.rb +3 -283
- data/lib/kanrisuru/remote/host.rb +1 -3
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/core/{ip/ip_address_label_spec.rb → ip_address_label_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_address_spec.rb → ip_address_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_link_spec.rb → ip_link_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_maddress_spec.rb → ip_maddress_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_neighbour_spec.rb → ip_neighbour_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_route_spec.rb → ip_route_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_rule_spec.rb → ip_rule_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_spec.rb → ip_spec.rb} +0 -0
- data/spec/functional/core/zypper_spec.rb +708 -0
- data/spec/helper/stub_network.rb +1 -1
- metadata +14 -10
@@ -0,0 +1,143 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kanrisuru
|
4
|
+
module Remote
|
5
|
+
class Fstab
|
6
|
+
class Options
|
7
|
+
def initialize(type, opts)
|
8
|
+
@type = type
|
9
|
+
@valid = false
|
10
|
+
|
11
|
+
if opts.instance_of?(String)
|
12
|
+
@opts = parse_opts(opts)
|
13
|
+
elsif opts.instance_of?(Hash)
|
14
|
+
@opts = opts.transform_keys(&:to_s)
|
15
|
+
else
|
16
|
+
raise ArgumentError, 'Invalid option type'
|
17
|
+
end
|
18
|
+
|
19
|
+
validate_opts!
|
20
|
+
end
|
21
|
+
|
22
|
+
def inspect
|
23
|
+
format('<Kanrisuru::Remote::Fstab::Options:0x%<object_id>s @opts=%<opts>s @type=%<type>s>',
|
24
|
+
object_id: object_id, opts: @opts, type: @type)
|
25
|
+
end
|
26
|
+
|
27
|
+
def [](option)
|
28
|
+
@opts[option]
|
29
|
+
end
|
30
|
+
|
31
|
+
def []=(option, value)
|
32
|
+
option = option.to_s
|
33
|
+
|
34
|
+
unless Kanrisuru::Remote::Fstab::Options.option_exists?(option, @type)
|
35
|
+
raise ArgumentError,
|
36
|
+
"Invalid option: #{option} for #{@type} file system."
|
37
|
+
end
|
38
|
+
|
39
|
+
unless Kanrisuru::Remote::Fstab::Options.valid_option?(option, value, @type)
|
40
|
+
raise ArgumentError,
|
41
|
+
"Invalid option value: #{value} for #{option} on #{@type} file system."
|
42
|
+
end
|
43
|
+
|
44
|
+
@opts[option] = value
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_s
|
48
|
+
string = ''
|
49
|
+
opts_length = @opts.length
|
50
|
+
|
51
|
+
@opts.each_with_index do |(key, value), index|
|
52
|
+
append_comma = true
|
53
|
+
|
54
|
+
if value == true
|
55
|
+
string += key.to_s
|
56
|
+
elsif value.instance_of?(String) || value.instance_of?(Integer) || value.instance_of?(Float)
|
57
|
+
string += "#{key}=#{value}"
|
58
|
+
else
|
59
|
+
append_comma = false
|
60
|
+
end
|
61
|
+
|
62
|
+
string += ',' if append_comma && index < opts_length - 1
|
63
|
+
end
|
64
|
+
|
65
|
+
string
|
66
|
+
end
|
67
|
+
|
68
|
+
def to_h
|
69
|
+
@opts
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.option_exists?(value, type = nil)
|
73
|
+
value = value.to_sym
|
74
|
+
type = type ? type.to_sym : nil
|
75
|
+
|
76
|
+
common = Kanrisuru::Util::FsMountOpts[:common]
|
77
|
+
fs_opts = Kanrisuru::Util::FsMountOpts[type]
|
78
|
+
|
79
|
+
common.key?(value) ||
|
80
|
+
fs_opts&.key?(value)
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.valid_option?(value, field, type = nil)
|
84
|
+
value = value.to_sym
|
85
|
+
type = type ? type.to_sym : nil
|
86
|
+
|
87
|
+
common = Kanrisuru::Util::FsMountOpts[:common]
|
88
|
+
fs_opts = Kanrisuru::Util::FsMountOpts[type]
|
89
|
+
|
90
|
+
if common.key?(value)
|
91
|
+
case common[value]
|
92
|
+
when 'boolean'
|
93
|
+
[true, false].include?(field)
|
94
|
+
when 'value'
|
95
|
+
field.instance_of?(String) || field.instance_of?(Float) || field.instance_of?(Integer)
|
96
|
+
else
|
97
|
+
false
|
98
|
+
end
|
99
|
+
elsif fs_opts&.key?(value)
|
100
|
+
case fs_opts[value]
|
101
|
+
when 'boolean'
|
102
|
+
[true, false].include?(field)
|
103
|
+
when 'value'
|
104
|
+
field.instance_of?(String) || field.instance_of?(Float) || field.instance_of?(Integer)
|
105
|
+
else
|
106
|
+
false
|
107
|
+
end
|
108
|
+
else
|
109
|
+
raise ArgumentError, 'Invalid option'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
def validate_opts!
|
116
|
+
@opts.each do |key, value|
|
117
|
+
unless Kanrisuru::Remote::Fstab::Options.valid_option?(key, value, @type)
|
118
|
+
raise ArgumentError, "Invalid option: #{key} for #{@type}"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
@valid = true
|
123
|
+
end
|
124
|
+
|
125
|
+
def parse_opts(string)
|
126
|
+
opts = {}
|
127
|
+
|
128
|
+
options = string.split(',')
|
129
|
+
options.each do |option|
|
130
|
+
if option.include?('=')
|
131
|
+
opt, value = option.split('=')
|
132
|
+
opts[opt] = value
|
133
|
+
else
|
134
|
+
opts[option] = true
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
opts
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'fstab/entry'
|
4
|
+
require_relative 'fstab/options'
|
5
|
+
|
3
6
|
module Kanrisuru
|
4
7
|
module Remote
|
5
8
|
class Fstab
|
@@ -133,289 +136,6 @@ module Kanrisuru
|
|
133
136
|
}
|
134
137
|
end
|
135
138
|
end
|
136
|
-
|
137
|
-
class Entry
|
138
|
-
attr_reader :device, :uuid, :invalid, :label, :type, :opts, :freq, :passno
|
139
|
-
attr_accessor :mount_point
|
140
|
-
|
141
|
-
def initialize(opts = {})
|
142
|
-
@host = opts[:host]
|
143
|
-
@line = opts[:line]
|
144
|
-
|
145
|
-
@default = nil
|
146
|
-
|
147
|
-
@device = opts[:device] || nil
|
148
|
-
@opts = opts[:opts] || nil
|
149
|
-
@label = opts[:label] || nil
|
150
|
-
@uuid = opts[:uuid] || nil
|
151
|
-
@mount_point = opts[:mount_point] || nil
|
152
|
-
@type = opts[:type] || nil
|
153
|
-
@freq = opts[:freq] || nil
|
154
|
-
@passno = opts[:passno] || nil
|
155
|
-
|
156
|
-
@changed = false
|
157
|
-
|
158
|
-
@ucount = 0
|
159
|
-
@special = false
|
160
|
-
@invalid = false
|
161
|
-
|
162
|
-
if Kanrisuru::Util.present?(@line) && @line.instance_of?(String)
|
163
|
-
parse_line!
|
164
|
-
elsif (Kanrisuru::Util.present?(@opts) && @opts.instance_of?(String)) || @opts.instance_of?(Hash)
|
165
|
-
@opts = Kanrisuru::Remote::Fstab::Options.new(@type, @opts)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def inspect
|
170
|
-
str = '#<Kanrisuru::Remote::Fstab::Entry:0x%<object_id>s ' \
|
171
|
-
'@line=%<line>s @device=%<device>s @label=%<label>s' \
|
172
|
-
'@uuid=%<uuid>s @freq=%<freq>s @pasno=%<passno>s' \
|
173
|
-
'@opts=%<opts>s}>'
|
174
|
-
|
175
|
-
format(
|
176
|
-
str,
|
177
|
-
object_id: object_id,
|
178
|
-
line: @line,
|
179
|
-
device: @device,
|
180
|
-
label: @label,
|
181
|
-
uuid: @uuid,
|
182
|
-
freq: @freq,
|
183
|
-
passno: @passno,
|
184
|
-
opts: @opts.inspect
|
185
|
-
)
|
186
|
-
end
|
187
|
-
|
188
|
-
def valid?
|
189
|
-
!@invalid
|
190
|
-
end
|
191
|
-
|
192
|
-
def to_s(override = nil)
|
193
|
-
mode = override || @default
|
194
|
-
|
195
|
-
case mode
|
196
|
-
when 'uuid'
|
197
|
-
"UUID=#{@uuid} #{@mount_point} #{@type} #{@opts} #{@freq} #{@passno}"
|
198
|
-
when 'label'
|
199
|
-
"LABEL=#{@label} #{@mount_point} #{@type} #{@opts} #{@freq} #{@passno}"
|
200
|
-
else
|
201
|
-
"#{@device} #{@mount_point} #{@type} #{@opts} #{@freq} #{@passno}"
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
private
|
206
|
-
|
207
|
-
def parse_line!
|
208
|
-
fsline, mp, @type, opts, freq, passno = @line.split
|
209
|
-
|
210
|
-
@mount_point = mp
|
211
|
-
@freq = freq || '0'
|
212
|
-
@passno = passno || '0'
|
213
|
-
|
214
|
-
@opts = Fstab::Options.new(@type, opts)
|
215
|
-
|
216
|
-
case @line
|
217
|
-
when /^\s*LABEL=/
|
218
|
-
@default = 'label'
|
219
|
-
parse_label(fsline)
|
220
|
-
when /^\s*UUID=/
|
221
|
-
@default = 'uuid'
|
222
|
-
parse_uuid(fsline)
|
223
|
-
when %r{^\s*/dev}
|
224
|
-
@default = 'dev'
|
225
|
-
parse_dev(fsline)
|
226
|
-
else
|
227
|
-
# TODO: somewhat risky to assume that everything else
|
228
|
-
# can be considered a special device, but validating this
|
229
|
-
# is really tricky.
|
230
|
-
@special = true
|
231
|
-
@device = fsline
|
232
|
-
end
|
233
|
-
|
234
|
-
# Fstab entries not matching real devices have device unknown
|
235
|
-
@invalid = (@line.split.count != 6) # invalid entry if < 6 columns
|
236
|
-
|
237
|
-
if (@uuid.nil? && @label.nil? && !@special) ||
|
238
|
-
@device =~ /^unknown_/ ||
|
239
|
-
(!@host.inode?(@device) && !@special)
|
240
|
-
@invalid = true
|
241
|
-
@ucount += 1
|
242
|
-
end
|
243
|
-
|
244
|
-
@invalid = true unless @freq =~ /0|1|2/ && @passno =~ /0|1|2/
|
245
|
-
end
|
246
|
-
|
247
|
-
def parse_label(fsline)
|
248
|
-
@label = fsline.split('=').last.strip.chomp
|
249
|
-
path = @host.realpath("/dev/disk/by-label/#{@label}").path
|
250
|
-
|
251
|
-
@device = begin
|
252
|
-
"/dev/#{path.split('/').last}"
|
253
|
-
rescue StandardError
|
254
|
-
"unknown_#{@ucount}"
|
255
|
-
end
|
256
|
-
|
257
|
-
result = @host.blkid(device: @device)
|
258
|
-
@uuid = result.success? ? result[0].uuid : nil
|
259
|
-
end
|
260
|
-
|
261
|
-
def parse_uuid(fsline)
|
262
|
-
@uuid = fsline.split('=').last.strip.chomp
|
263
|
-
path = @host.realpath("/dev/disk/by-uuid/#{uuid}").path
|
264
|
-
|
265
|
-
@device = begin
|
266
|
-
"/dev/#{path.split('/').last}"
|
267
|
-
rescue StandardError
|
268
|
-
"unknown_#{@ucount}"
|
269
|
-
end
|
270
|
-
|
271
|
-
result = @host.blkid(device: @device)
|
272
|
-
@label = result.success? ? result[0].label : nil
|
273
|
-
end
|
274
|
-
|
275
|
-
def parse_dev(fsline)
|
276
|
-
@device = fsline
|
277
|
-
result = @host.blkid(device: @device)
|
278
|
-
|
279
|
-
@label = result.success? ? result[0].label : nil
|
280
|
-
@uuid = result.success? ? result[0].uuid : nil
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
class Options
|
285
|
-
def initialize(type, opts)
|
286
|
-
@type = type
|
287
|
-
@valid = false
|
288
|
-
|
289
|
-
if opts.instance_of?(String)
|
290
|
-
@opts = parse_opts(opts)
|
291
|
-
elsif opts.instance_of?(Hash)
|
292
|
-
@opts = opts.transform_keys(&:to_s)
|
293
|
-
else
|
294
|
-
raise ArgumentError, 'Invalid option type'
|
295
|
-
end
|
296
|
-
|
297
|
-
validate_opts!
|
298
|
-
end
|
299
|
-
|
300
|
-
def inspect
|
301
|
-
format('<Kanrisuru::Remote::Fstab::Options:0x%<object_id>s @opts=%<opts>s @type=%<type>s>',
|
302
|
-
object_id: object_id, opts: @opts, type: @type)
|
303
|
-
end
|
304
|
-
|
305
|
-
def [](option)
|
306
|
-
@opts[option]
|
307
|
-
end
|
308
|
-
|
309
|
-
def []=(option, value)
|
310
|
-
option = option.to_s
|
311
|
-
|
312
|
-
unless Kanrisuru::Remote::Fstab::Options.option_exists?(option, @type)
|
313
|
-
raise ArgumentError,
|
314
|
-
"Invalid option: #{option} for #{@type} file system."
|
315
|
-
end
|
316
|
-
|
317
|
-
unless Kanrisuru::Remote::Fstab::Options.valid_option?(option, value, @type)
|
318
|
-
raise ArgumentError,
|
319
|
-
"Invalid option value: #{value} for #{option} on #{@type} file system."
|
320
|
-
end
|
321
|
-
|
322
|
-
@opts[option] = value
|
323
|
-
end
|
324
|
-
|
325
|
-
def to_s
|
326
|
-
string = ''
|
327
|
-
opts_length = @opts.length
|
328
|
-
|
329
|
-
@opts.each_with_index do |(key, value), index|
|
330
|
-
append_comma = true
|
331
|
-
|
332
|
-
if value == true
|
333
|
-
string += key.to_s
|
334
|
-
elsif value.instance_of?(String) || value.instance_of?(Integer) || value.instance_of?(Float)
|
335
|
-
string += "#{key}=#{value}"
|
336
|
-
else
|
337
|
-
append_comma = false
|
338
|
-
end
|
339
|
-
|
340
|
-
string += ',' if append_comma && index < opts_length - 1
|
341
|
-
end
|
342
|
-
|
343
|
-
string
|
344
|
-
end
|
345
|
-
|
346
|
-
def to_h
|
347
|
-
@opts
|
348
|
-
end
|
349
|
-
|
350
|
-
def self.option_exists?(value, type = nil)
|
351
|
-
value = value.to_sym
|
352
|
-
type = type ? type.to_sym : nil
|
353
|
-
|
354
|
-
common = Kanrisuru::Util::FsMountOpts[:common]
|
355
|
-
fs_opts = Kanrisuru::Util::FsMountOpts[type]
|
356
|
-
|
357
|
-
common.key?(value) ||
|
358
|
-
fs_opts&.key?(value)
|
359
|
-
end
|
360
|
-
|
361
|
-
def self.valid_option?(value, field, type = nil)
|
362
|
-
value = value.to_sym
|
363
|
-
type = type ? type.to_sym : nil
|
364
|
-
|
365
|
-
common = Kanrisuru::Util::FsMountOpts[:common]
|
366
|
-
fs_opts = Kanrisuru::Util::FsMountOpts[type]
|
367
|
-
|
368
|
-
if common.key?(value)
|
369
|
-
case common[value]
|
370
|
-
when 'boolean'
|
371
|
-
[true, false].include?(field)
|
372
|
-
when 'value'
|
373
|
-
field.instance_of?(String) || field.instance_of?(Float) || field.instance_of?(Integer)
|
374
|
-
else
|
375
|
-
false
|
376
|
-
end
|
377
|
-
elsif fs_opts&.key?(value)
|
378
|
-
case fs_opts[value]
|
379
|
-
when 'boolean'
|
380
|
-
[true, false].include?(field)
|
381
|
-
when 'value'
|
382
|
-
field.instance_of?(String) || field.instance_of?(Float) || field.instance_of?(Integer)
|
383
|
-
else
|
384
|
-
false
|
385
|
-
end
|
386
|
-
else
|
387
|
-
raise ArgumentError, 'Invalid option'
|
388
|
-
end
|
389
|
-
end
|
390
|
-
|
391
|
-
private
|
392
|
-
|
393
|
-
def validate_opts!
|
394
|
-
@opts.each do |key, value|
|
395
|
-
unless Kanrisuru::Remote::Fstab::Options.valid_option?(key, value, @type)
|
396
|
-
raise ArgumentError, "Invalid option: #{key} for #{@type}"
|
397
|
-
end
|
398
|
-
end
|
399
|
-
|
400
|
-
@valid = true
|
401
|
-
end
|
402
|
-
|
403
|
-
def parse_opts(string)
|
404
|
-
opts = {}
|
405
|
-
|
406
|
-
options = string.split(',')
|
407
|
-
options.each do |option|
|
408
|
-
if option.include?('=')
|
409
|
-
opt, value = option.split('=')
|
410
|
-
opts[opt] = value
|
411
|
-
else
|
412
|
-
opts[option] = true
|
413
|
-
end
|
414
|
-
end
|
415
|
-
|
416
|
-
opts
|
417
|
-
end
|
418
|
-
end
|
419
139
|
end
|
420
140
|
end
|
421
141
|
end
|
@@ -135,6 +135,7 @@ module Kanrisuru
|
|
135
135
|
end
|
136
136
|
|
137
137
|
ch.on_data do |_, data|
|
138
|
+
Kanrisuru.logger.debug { data.strip }
|
138
139
|
command.handle_data(data)
|
139
140
|
end
|
140
141
|
|
@@ -145,9 +146,6 @@ module Kanrisuru
|
|
145
146
|
end
|
146
147
|
|
147
148
|
channel.wait
|
148
|
-
|
149
|
-
Kanrisuru.logger.debug { command.to_a }
|
150
|
-
|
151
149
|
command
|
152
150
|
rescue Net::SSH::ConnectionTimeout, Net::SSH::Timeout => e
|
153
151
|
if retry_attempts > 1
|
data/lib/kanrisuru/version.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|