linux_admin 3.0.0 → 4.1.0
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/README.md +0 -2
- data/lib/linux_admin/distro.rb +5 -1
- data/lib/linux_admin/homebrew.rb +21 -0
- data/lib/linux_admin/network_interface/network_interface_darwin.rb +19 -0
- data/lib/linux_admin/network_interface/network_interface_rh.rb +8 -0
- data/lib/linux_admin/network_interface.rb +54 -35
- data/lib/linux_admin/version.rb +1 -1
- data/lib/linux_admin.rb +1 -0
- metadata +20 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: de3cd5883d8dee83ce8db19f61bb2b6b47cf8a057a00f37488ce809110d8d158
|
|
4
|
+
data.tar.gz: f6bc420d4a091ce5cb42150e8ec7d2b6fe149c38b3a9c0bf6981ee76ff582302
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 21a1d96a14181e0bd6d0c74d654f3588dab524d5a2ab0a0adda21e88b134e013be8e78927e5e912be729071459c6ac1cb72add42ae328e499e2ab92a8223078d
|
|
7
|
+
data.tar.gz: 78fb390e5faf124d4dd27e001464854cbcafcf0346bb9eaebd5a98591257bae9ac8b00a0d34dec0ebcb05979553bb973f672f0d4061095090d7e75960ffec977
|
data/README.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
[](http://badge.fury.io/rb/linux_admin)
|
|
4
4
|
[](https://github.com/ManageIQ/linux_admin/actions/workflows/ci.yaml)
|
|
5
|
-
[](https://codeclimate.com/github/ManageIQ/linux_admin)
|
|
6
|
-
[](https://codeclimate.com/github/ManageIQ/linux_admin/coverage)
|
|
7
5
|
|
|
8
6
|
LinuxAdmin is a module to simplify management of linux systems.
|
|
9
7
|
It should be a single place to manage various system level configurations,
|
data/lib/linux_admin/distro.rb
CHANGED
|
@@ -18,8 +18,12 @@ module LinuxAdmin
|
|
|
18
18
|
@ubuntu ||= Distro.new(:ubuntu, nil, ['ubuntu'], LinuxAdmin::Deb)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
def self.darwin
|
|
22
|
+
@darwin ||= Distro.new(:darwin, "/System/Library/CoreServices/SystemVersion.plist", ['darwin'], LinuxAdmin::Homebrew)
|
|
23
|
+
end
|
|
24
|
+
|
|
21
25
|
def self.all
|
|
22
|
-
@distros ||= [rhel, fedora, ubuntu, generic]
|
|
26
|
+
@distros ||= [rhel, fedora, ubuntu, darwin, generic]
|
|
23
27
|
end
|
|
24
28
|
|
|
25
29
|
def self.local
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module LinuxAdmin
|
|
2
|
+
class Homebrew < Package
|
|
3
|
+
extend Logging
|
|
4
|
+
|
|
5
|
+
def self.homebrew_cmd
|
|
6
|
+
Common.cmd("brew")
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.list_installed
|
|
10
|
+
info(nil)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.info(pkg)
|
|
14
|
+
out = Common.run!(homebrew_cmd, :params => ["list", :versions, pkg]).output
|
|
15
|
+
out.split("\n").each_with_object({}) do |line, pkg_hash|
|
|
16
|
+
name, ver = line.split[0..1] # only take the latest version
|
|
17
|
+
pkg_hash[name] = ver
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module LinuxAdmin
|
|
2
|
+
class NetworkInterfaceDarwin < NetworkInterface
|
|
3
|
+
# Runs the command `ip -[4/6] route` and returns the output
|
|
4
|
+
#
|
|
5
|
+
# @param version [Fixnum] Version of IP protocol (4 or 6)
|
|
6
|
+
# @return [String] The command output
|
|
7
|
+
# @raise [NetworkInterfaceError] if the command fails
|
|
8
|
+
#
|
|
9
|
+
# macs use ip route get while others use ip route show
|
|
10
|
+
def ip_route(version, route = "default")
|
|
11
|
+
output = Common.run!(Common.cmd("ip"), :params => ["--json", "-#{version}", "route", "get", route]).output
|
|
12
|
+
return {} if output.blank?
|
|
13
|
+
|
|
14
|
+
JSON.parse(output).first
|
|
15
|
+
rescue AwesomeSpawn::CommandResultError => e
|
|
16
|
+
raise NetworkInterfaceError.new(e.message, e.result)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -12,7 +12,15 @@ module LinuxAdmin
|
|
|
12
12
|
def initialize(interface)
|
|
13
13
|
@interface_file = self.class.path_to_interface_config_file(interface)
|
|
14
14
|
super
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Gathers current network information for this interface
|
|
18
|
+
#
|
|
19
|
+
# @return [Boolean] true if network information was gathered successfully
|
|
20
|
+
def reload
|
|
21
|
+
super
|
|
15
22
|
parse_conf
|
|
23
|
+
true
|
|
16
24
|
end
|
|
17
25
|
|
|
18
26
|
# Parses the interface configuration file into the @interface_config hash
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
require 'ipaddr'
|
|
2
|
-
|
|
3
1
|
module LinuxAdmin
|
|
4
2
|
class NetworkInterface
|
|
3
|
+
require "ipaddr"
|
|
4
|
+
require "json"
|
|
5
|
+
|
|
5
6
|
# Cached class instance variable for what distro we are running on
|
|
6
7
|
@dist_class = nil
|
|
7
8
|
|
|
@@ -12,21 +13,39 @@ module LinuxAdmin
|
|
|
12
13
|
def self.dist_class(clear_cache = false)
|
|
13
14
|
@dist_class = nil if clear_cache
|
|
14
15
|
@dist_class ||= begin
|
|
15
|
-
|
|
16
|
+
case Distros.local
|
|
17
|
+
when Distros.rhel, Distros.fedora
|
|
16
18
|
NetworkInterfaceRH
|
|
19
|
+
when Distros.darwin
|
|
20
|
+
NetworkInterfaceDarwin
|
|
17
21
|
else
|
|
18
22
|
NetworkInterfaceGeneric
|
|
19
23
|
end
|
|
20
24
|
end
|
|
21
25
|
end
|
|
22
26
|
|
|
27
|
+
def self.list
|
|
28
|
+
ip_link.pluck("ifname").map { |iface| new(iface) }
|
|
29
|
+
rescue AwesomeSpawn::CommandResultError => e
|
|
30
|
+
raise NetworkInterfaceError.new(e.message, e.result)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private_class_method def self.ip_link
|
|
34
|
+
require "json"
|
|
35
|
+
|
|
36
|
+
result = Common.run!(Common.cmd("ip"), :params => ["--json", "link"])
|
|
37
|
+
JSON.parse(result.output)
|
|
38
|
+
rescue AwesomeSpawn::CommandResultError, JSON::ParserError => e
|
|
39
|
+
raise NetworkInterfaceError.new(e.message, e.result)
|
|
40
|
+
end
|
|
41
|
+
|
|
23
42
|
# Creates an instance of the correct NetworkInterface subclass for the local distro
|
|
24
43
|
def self.new(*args)
|
|
25
44
|
self == LinuxAdmin::NetworkInterface ? dist_class.new(*args) : super
|
|
26
45
|
end
|
|
27
46
|
|
|
28
47
|
# @return [String] the interface for networking operations
|
|
29
|
-
attr_reader :interface
|
|
48
|
+
attr_reader :interface, :link_type
|
|
30
49
|
|
|
31
50
|
# @param interface [String] Name of the network interface to manage
|
|
32
51
|
def initialize(interface)
|
|
@@ -45,18 +64,25 @@ module LinuxAdmin
|
|
|
45
64
|
return false
|
|
46
65
|
end
|
|
47
66
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
67
|
+
@link_type = ip_output["link_type"]
|
|
68
|
+
addr_info = ip_output["addr_info"]
|
|
69
|
+
|
|
70
|
+
parse_ip4(addr_info)
|
|
71
|
+
parse_ip6(addr_info, "global")
|
|
72
|
+
parse_ip6(addr_info, "link")
|
|
51
73
|
|
|
52
|
-
@network_conf[:mac] =
|
|
74
|
+
@network_conf[:mac] = ip_output["address"]
|
|
53
75
|
|
|
54
76
|
[4, 6].each do |version|
|
|
55
|
-
@network_conf["gateway#{version}".to_sym] =
|
|
77
|
+
@network_conf["gateway#{version}".to_sym] = ip_route(version, "default")&.dig("gateway")
|
|
56
78
|
end
|
|
57
79
|
true
|
|
58
80
|
end
|
|
59
81
|
|
|
82
|
+
def loopback?
|
|
83
|
+
@link_type == "loopback"
|
|
84
|
+
end
|
|
85
|
+
|
|
60
86
|
# Retrieve the IPv4 address assigned to the interface
|
|
61
87
|
#
|
|
62
88
|
# @return [String] IPv4 address for the managed interface
|
|
@@ -153,23 +179,15 @@ module LinuxAdmin
|
|
|
153
179
|
|
|
154
180
|
private
|
|
155
181
|
|
|
156
|
-
# Parses the output of `ip addr show`
|
|
157
|
-
#
|
|
158
|
-
# @param output [String] The command output
|
|
159
|
-
# @param regex [Regexp] Regular expression to match the desired output line
|
|
160
|
-
# @param col [Fixnum] The whitespace delimited column to be returned
|
|
161
|
-
# @return [String] The parsed data
|
|
162
|
-
def parse_ip_output(output, regex, col)
|
|
163
|
-
the_line = output.split("\n").detect { |l| l =~ regex }
|
|
164
|
-
the_line.nil? ? nil : the_line.strip.split(' ')[col]
|
|
165
|
-
end
|
|
166
|
-
|
|
167
182
|
# Runs the command `ip addr show <interface>`
|
|
168
183
|
#
|
|
169
184
|
# @return [String] The command output
|
|
170
185
|
# @raise [NetworkInterfaceError] if the command fails
|
|
171
186
|
def ip_show
|
|
172
|
-
Common.run!(Common.cmd("ip"), :params => ["addr", "show", @interface]).output
|
|
187
|
+
output = Common.run!(Common.cmd("ip"), :params => ["--json", "addr", "show", @interface]).output
|
|
188
|
+
return {} if output.blank?
|
|
189
|
+
|
|
190
|
+
JSON.parse(output).first
|
|
173
191
|
rescue AwesomeSpawn::CommandResultError => e
|
|
174
192
|
raise NetworkInterfaceError.new(e.message, e.result)
|
|
175
193
|
end
|
|
@@ -179,8 +197,11 @@ module LinuxAdmin
|
|
|
179
197
|
# @param version [Fixnum] Version of IP protocol (4 or 6)
|
|
180
198
|
# @return [String] The command output
|
|
181
199
|
# @raise [NetworkInterfaceError] if the command fails
|
|
182
|
-
def ip_route(version)
|
|
183
|
-
Common.run!(Common.cmd("ip"), :params => ["-#{version}",
|
|
200
|
+
def ip_route(version, route = "default")
|
|
201
|
+
output = Common.run!(Common.cmd("ip"), :params => ["--json", "-#{version}", "route", "show", route]).output
|
|
202
|
+
return {} if output.blank?
|
|
203
|
+
|
|
204
|
+
JSON.parse(output).first
|
|
184
205
|
rescue AwesomeSpawn::CommandResultError => e
|
|
185
206
|
raise NetworkInterfaceError.new(e.message, e.result)
|
|
186
207
|
end
|
|
@@ -188,26 +209,24 @@ module LinuxAdmin
|
|
|
188
209
|
# Parses the IPv4 information from the output of `ip addr show <device>`
|
|
189
210
|
#
|
|
190
211
|
# @param ip_output [String] The command output
|
|
191
|
-
def parse_ip4(
|
|
192
|
-
|
|
193
|
-
return
|
|
212
|
+
def parse_ip4(addr_info)
|
|
213
|
+
inet = addr_info&.detect { |addr| addr["family"] == "inet" }
|
|
214
|
+
return if inet.nil?
|
|
194
215
|
|
|
195
|
-
|
|
196
|
-
@network_conf[:
|
|
197
|
-
@network_conf[:prefix] = parts[1].to_i
|
|
216
|
+
@network_conf[:address] = inet["local"]
|
|
217
|
+
@network_conf[:prefix] = inet["prefixlen"]
|
|
198
218
|
end
|
|
199
219
|
|
|
200
220
|
# Parses the IPv6 information from the output of `ip addr show <device>`
|
|
201
221
|
#
|
|
202
222
|
# @param ip_output [String] The command output
|
|
203
223
|
# @param scope [Symbol] The IPv6 scope (either `:global` or `:local`)
|
|
204
|
-
def parse_ip6(
|
|
205
|
-
|
|
206
|
-
return
|
|
224
|
+
def parse_ip6(addr_info, scope)
|
|
225
|
+
inet6 = addr_info&.detect { |addr| addr["family"] == "inet6" && addr["scope"] == scope }
|
|
226
|
+
return if inet6.nil?
|
|
207
227
|
|
|
208
|
-
|
|
209
|
-
@network_conf["
|
|
210
|
-
@network_conf["prefix6_#{scope}".to_sym] = parts[1].to_i
|
|
228
|
+
@network_conf["address6_#{scope}".to_sym] = inet6["local"]
|
|
229
|
+
@network_conf["prefix6_#{scope}".to_sym] = inet6["prefixlen"]
|
|
211
230
|
end
|
|
212
231
|
end
|
|
213
232
|
end
|
data/lib/linux_admin/version.rb
CHANGED
data/lib/linux_admin.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: linux_admin
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 4.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brandon Dunne
|
|
@@ -27,10 +27,9 @@ authors:
|
|
|
27
27
|
- whitesource-bolt-for-github[bot]
|
|
28
28
|
- Adam Grare
|
|
29
29
|
- renovate[bot]
|
|
30
|
-
autorequire:
|
|
31
30
|
bindir: bin
|
|
32
31
|
cert_chain: []
|
|
33
|
-
date:
|
|
32
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
34
33
|
dependencies:
|
|
35
34
|
- !ruby/object:Gem::Dependency
|
|
36
35
|
name: manageiq-style
|
|
@@ -162,19 +161,28 @@ dependencies:
|
|
|
162
161
|
requirements:
|
|
163
162
|
- - "~>"
|
|
164
163
|
- !ruby/object:Gem::Version
|
|
165
|
-
version: '4.
|
|
164
|
+
version: '4.5'
|
|
165
|
+
- - ">="
|
|
166
|
+
- !ruby/object:Gem::Version
|
|
167
|
+
version: 4.5.1
|
|
166
168
|
type: :runtime
|
|
167
169
|
prerelease: false
|
|
168
170
|
version_requirements: !ruby/object:Gem::Requirement
|
|
169
171
|
requirements:
|
|
170
172
|
- - "~>"
|
|
171
173
|
- !ruby/object:Gem::Version
|
|
172
|
-
version: '4.
|
|
174
|
+
version: '4.5'
|
|
175
|
+
- - ">="
|
|
176
|
+
- !ruby/object:Gem::Version
|
|
177
|
+
version: 4.5.1
|
|
173
178
|
- !ruby/object:Gem::Dependency
|
|
174
179
|
name: net-ssh
|
|
175
180
|
requirement: !ruby/object:Gem::Requirement
|
|
176
181
|
requirements:
|
|
177
182
|
- - "~>"
|
|
183
|
+
- !ruby/object:Gem::Version
|
|
184
|
+
version: '7.2'
|
|
185
|
+
- - ">="
|
|
178
186
|
- !ruby/object:Gem::Version
|
|
179
187
|
version: 7.2.3
|
|
180
188
|
type: :runtime
|
|
@@ -182,6 +190,9 @@ dependencies:
|
|
|
182
190
|
version_requirements: !ruby/object:Gem::Requirement
|
|
183
191
|
requirements:
|
|
184
192
|
- - "~>"
|
|
193
|
+
- !ruby/object:Gem::Version
|
|
194
|
+
version: '7.2'
|
|
195
|
+
- - ">="
|
|
185
196
|
- !ruby/object:Gem::Version
|
|
186
197
|
version: 7.2.3
|
|
187
198
|
- !ruby/object:Gem::Dependency
|
|
@@ -296,12 +307,14 @@ files:
|
|
|
296
307
|
- lib/linux_admin/exceptions.rb
|
|
297
308
|
- lib/linux_admin/fstab.rb
|
|
298
309
|
- lib/linux_admin/hardware.rb
|
|
310
|
+
- lib/linux_admin/homebrew.rb
|
|
299
311
|
- lib/linux_admin/hosts.rb
|
|
300
312
|
- lib/linux_admin/ip_address.rb
|
|
301
313
|
- lib/linux_admin/logging.rb
|
|
302
314
|
- lib/linux_admin/logical_volume.rb
|
|
303
315
|
- lib/linux_admin/mountable.rb
|
|
304
316
|
- lib/linux_admin/network_interface.rb
|
|
317
|
+
- lib/linux_admin/network_interface/network_interface_darwin.rb
|
|
305
318
|
- lib/linux_admin/network_interface/network_interface_generic.rb
|
|
306
319
|
- lib/linux_admin/network_interface/network_interface_rh.rb
|
|
307
320
|
- lib/linux_admin/null_logger.rb
|
|
@@ -328,7 +341,6 @@ homepage: http://github.com/ManageIQ/linux_admin
|
|
|
328
341
|
licenses:
|
|
329
342
|
- MIT
|
|
330
343
|
metadata: {}
|
|
331
|
-
post_install_message:
|
|
332
344
|
rdoc_options: []
|
|
333
345
|
require_paths:
|
|
334
346
|
- lib
|
|
@@ -336,15 +348,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
336
348
|
requirements:
|
|
337
349
|
- - ">="
|
|
338
350
|
- !ruby/object:Gem::Version
|
|
339
|
-
version: '
|
|
351
|
+
version: '3.0'
|
|
340
352
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
341
353
|
requirements:
|
|
342
354
|
- - ">="
|
|
343
355
|
- !ruby/object:Gem::Version
|
|
344
356
|
version: '0'
|
|
345
357
|
requirements: []
|
|
346
|
-
rubygems_version: 3.
|
|
347
|
-
signing_key:
|
|
358
|
+
rubygems_version: 3.6.9
|
|
348
359
|
specification_version: 4
|
|
349
360
|
summary: LinuxAdmin is a module to simplify management of linux systems.
|
|
350
361
|
test_files: []
|