linux_admin 2.0.2 → 4.0.0
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 -6
- data/lib/linux_admin/common.rb +1 -1
- data/lib/linux_admin/network_interface/network_interface_rh.rb +8 -0
- data/lib/linux_admin/network_interface.rb +50 -34
- data/lib/linux_admin/registration_system.rb +2 -1
- data/lib/linux_admin/service/systemd_service.rb +2 -0
- data/lib/linux_admin/ssh_agent.rb +1 -1
- data/lib/linux_admin/version.rb +1 -1
- metadata +85 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a68c70db030c6c422243f781a3500324a224ae653c7e04e6ebac3f5ad902d08
|
4
|
+
data.tar.gz: 2d1d363cd64e3c2ebf64616a0376752f2e04aa7b74c143856d89c1aa2bcd0a7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24c97db1e87afbbb873c963eb0e5c45f54dd1de468b46e301ec44563bcc459ecc2a97c9219a4c221ec8703258328c0c2f476b6e27f91da4c6bb811945ea3cfe7
|
7
|
+
data.tar.gz: 9b1a31fbf403c5b0873dced35a8308870a382c907ae8ef3919a285151c878bebf9297d71179435c09bc4c4a182fffee053e3e1ee8b76b2a50f2e8e8bd2e3d1ee
|
data/README.md
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
# LinuxAdmin
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/linux_admin.svg)](http://badge.fury.io/rb/linux_admin)
|
4
|
-
[![
|
5
|
-
[![Code Climate](
|
6
|
-
[![Coverage
|
7
|
-
[![Dependency Status](https://gemnasium.com/ManageIQ/linux_admin.svg)](https://gemnasium.com/ManageIQ/linux_admin)
|
8
|
-
[![Security](https://hakiri.io/github/ManageIQ/linux_admin/master.svg)](https://hakiri.io/github/ManageIQ/linux_admin/master)
|
9
|
-
|
4
|
+
[![CI](https://github.com/ManageIQ/linux_admin/actions/workflows/ci.yaml/badge.svg)](https://github.com/ManageIQ/linux_admin/actions/workflows/ci.yaml)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/ManageIQ/linux_admin.svg)](https://codeclimate.com/github/ManageIQ/linux_admin)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/ManageIQ/linux_admin/badges/coverage.svg)](https://codeclimate.com/github/ManageIQ/linux_admin/coverage)
|
10
7
|
|
11
8
|
LinuxAdmin is a module to simplify management of linux systems.
|
12
9
|
It should be a single place to manage various system level configurations,
|
data/lib/linux_admin/common.rb
CHANGED
@@ -4,7 +4,7 @@ module LinuxAdmin
|
|
4
4
|
module Common
|
5
5
|
include Logging
|
6
6
|
|
7
|
-
BIN_DIRS =
|
7
|
+
BIN_DIRS = ENV["PATH"].split(File::PATH_SEPARATOR).freeze
|
8
8
|
|
9
9
|
def self.cmd(name)
|
10
10
|
BIN_DIRS.collect { |dir| "#{dir}/#{name}" }.detect { |cmd| File.exist?(cmd) }
|
@@ -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
|
|
@@ -20,13 +21,28 @@ module LinuxAdmin
|
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
24
|
+
def self.list
|
25
|
+
ip_link.pluck("ifname").map { |iface| new(iface) }
|
26
|
+
rescue AwesomeSpawn::CommandResultError => e
|
27
|
+
raise NetworkInterfaceError.new(e.message, e.result)
|
28
|
+
end
|
29
|
+
|
30
|
+
private_class_method def self.ip_link
|
31
|
+
require "json"
|
32
|
+
|
33
|
+
result = Common.run!(Common.cmd("ip"), :params => ["--json", "link"])
|
34
|
+
JSON.parse(result.output)
|
35
|
+
rescue AwesomeSpawn::CommandResultError, JSON::ParserError => e
|
36
|
+
raise NetworkInterfaceError.new(e.message, e.result)
|
37
|
+
end
|
38
|
+
|
23
39
|
# Creates an instance of the correct NetworkInterface subclass for the local distro
|
24
40
|
def self.new(*args)
|
25
41
|
self == LinuxAdmin::NetworkInterface ? dist_class.new(*args) : super
|
26
42
|
end
|
27
43
|
|
28
44
|
# @return [String] the interface for networking operations
|
29
|
-
attr_reader :interface
|
45
|
+
attr_reader :interface, :link_type
|
30
46
|
|
31
47
|
# @param interface [String] Name of the network interface to manage
|
32
48
|
def initialize(interface)
|
@@ -45,18 +61,25 @@ module LinuxAdmin
|
|
45
61
|
return false
|
46
62
|
end
|
47
63
|
|
48
|
-
|
49
|
-
|
50
|
-
|
64
|
+
@link_type = ip_output["link_type"]
|
65
|
+
addr_info = ip_output["addr_info"]
|
66
|
+
|
67
|
+
parse_ip4(addr_info)
|
68
|
+
parse_ip6(addr_info, "global")
|
69
|
+
parse_ip6(addr_info, "link")
|
51
70
|
|
52
|
-
@network_conf[:mac] =
|
71
|
+
@network_conf[:mac] = ip_output["address"]
|
53
72
|
|
54
73
|
[4, 6].each do |version|
|
55
|
-
@network_conf["gateway#{version}".to_sym] =
|
74
|
+
@network_conf["gateway#{version}".to_sym] = ip_route(version, "default")&.dig("gateway")
|
56
75
|
end
|
57
76
|
true
|
58
77
|
end
|
59
78
|
|
79
|
+
def loopback?
|
80
|
+
@link_type == "loopback"
|
81
|
+
end
|
82
|
+
|
60
83
|
# Retrieve the IPv4 address assigned to the interface
|
61
84
|
#
|
62
85
|
# @return [String] IPv4 address for the managed interface
|
@@ -153,23 +176,15 @@ module LinuxAdmin
|
|
153
176
|
|
154
177
|
private
|
155
178
|
|
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
179
|
# Runs the command `ip addr show <interface>`
|
168
180
|
#
|
169
181
|
# @return [String] The command output
|
170
182
|
# @raise [NetworkInterfaceError] if the command fails
|
171
183
|
def ip_show
|
172
|
-
Common.run!(Common.cmd("ip"), :params => ["addr", "show", @interface]).output
|
184
|
+
output = Common.run!(Common.cmd("ip"), :params => ["--json", "addr", "show", @interface]).output
|
185
|
+
return {} if output.blank?
|
186
|
+
|
187
|
+
JSON.parse(output).first
|
173
188
|
rescue AwesomeSpawn::CommandResultError => e
|
174
189
|
raise NetworkInterfaceError.new(e.message, e.result)
|
175
190
|
end
|
@@ -179,8 +194,11 @@ module LinuxAdmin
|
|
179
194
|
# @param version [Fixnum] Version of IP protocol (4 or 6)
|
180
195
|
# @return [String] The command output
|
181
196
|
# @raise [NetworkInterfaceError] if the command fails
|
182
|
-
def ip_route(version)
|
183
|
-
Common.run!(Common.cmd("ip"), :params => ["-#{version}",
|
197
|
+
def ip_route(version, route = "default")
|
198
|
+
output = Common.run!(Common.cmd("ip"), :params => ["--json", "-#{version}", "route", "show", route]).output
|
199
|
+
return {} if output.blank?
|
200
|
+
|
201
|
+
JSON.parse(output).first
|
184
202
|
rescue AwesomeSpawn::CommandResultError => e
|
185
203
|
raise NetworkInterfaceError.new(e.message, e.result)
|
186
204
|
end
|
@@ -188,26 +206,24 @@ module LinuxAdmin
|
|
188
206
|
# Parses the IPv4 information from the output of `ip addr show <device>`
|
189
207
|
#
|
190
208
|
# @param ip_output [String] The command output
|
191
|
-
def parse_ip4(
|
192
|
-
|
193
|
-
return
|
209
|
+
def parse_ip4(addr_info)
|
210
|
+
inet = addr_info&.detect { |addr| addr["family"] == "inet" }
|
211
|
+
return if inet.nil?
|
194
212
|
|
195
|
-
|
196
|
-
@network_conf[:
|
197
|
-
@network_conf[:prefix] = parts[1].to_i
|
213
|
+
@network_conf[:address] = inet["local"]
|
214
|
+
@network_conf[:prefix] = inet["prefixlen"]
|
198
215
|
end
|
199
216
|
|
200
217
|
# Parses the IPv6 information from the output of `ip addr show <device>`
|
201
218
|
#
|
202
219
|
# @param ip_output [String] The command output
|
203
220
|
# @param scope [Symbol] The IPv6 scope (either `:global` or `:local`)
|
204
|
-
def parse_ip6(
|
205
|
-
|
206
|
-
return
|
221
|
+
def parse_ip6(addr_info, scope)
|
222
|
+
inet6 = addr_info&.detect { |addr| addr["family"] == "inet6" && addr["scope"] == scope }
|
223
|
+
return if inet6.nil?
|
207
224
|
|
208
|
-
|
209
|
-
@network_conf["
|
210
|
-
@network_conf["prefix6_#{scope}".to_sym] = parts[1].to_i
|
225
|
+
@network_conf["address6_#{scope}".to_sym] = inet6["local"]
|
226
|
+
@network_conf["prefix6_#{scope}".to_sym] = inet6["prefixlen"]
|
211
227
|
end
|
212
228
|
end
|
213
229
|
end
|
@@ -47,7 +47,8 @@ module LinuxAdmin
|
|
47
47
|
private_class_method :white_list_methods
|
48
48
|
|
49
49
|
def install_server_certificate(server, cert_path)
|
50
|
-
|
50
|
+
require 'uri'
|
51
|
+
host = server.start_with?("http") ? ::URI.parse(server).host : server
|
51
52
|
|
52
53
|
LinuxAdmin::Rpm.upgrade("http://#{host}/#{cert_path}")
|
53
54
|
end
|
@@ -32,7 +32,7 @@ module LinuxAdmin
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def stop
|
35
|
-
system({'SSH_AGENT_PID' => @pid}, '(ssh-agent -k)
|
35
|
+
system({'SSH_AGENT_PID' => @pid}, '(ssh-agent -k) >/dev/null 2>&1') if process_exists?(@pid)
|
36
36
|
File.delete(@socket) if File.exist?(@socket)
|
37
37
|
@socket = nil
|
38
38
|
@pid = nil
|
data/lib/linux_admin/version.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.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Dunne
|
@@ -24,11 +24,28 @@ authors:
|
|
24
24
|
- Daniel Berger
|
25
25
|
- Satoe Imaishi
|
26
26
|
- d-m-u
|
27
|
-
|
27
|
+
- whitesource-bolt-for-github[bot]
|
28
|
+
- Adam Grare
|
29
|
+
- renovate[bot]
|
30
|
+
autorequire:
|
28
31
|
bindir: bin
|
29
32
|
cert_chain: []
|
30
|
-
date:
|
33
|
+
date: 2024-08-13 00:00:00.000000000 Z
|
31
34
|
dependencies:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: manageiq-style
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
type: :development
|
43
|
+
prerelease: false
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
32
49
|
- !ruby/object:Gem::Dependency
|
33
50
|
name: rake
|
34
51
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,7 +75,7 @@ dependencies:
|
|
58
75
|
- !ruby/object:Gem::Version
|
59
76
|
version: '3.0'
|
60
77
|
- !ruby/object:Gem::Dependency
|
61
|
-
name:
|
78
|
+
name: rubocop
|
62
79
|
requirement: !ruby/object:Gem::Requirement
|
63
80
|
requirements:
|
64
81
|
- - ">="
|
@@ -72,33 +89,59 @@ dependencies:
|
|
72
89
|
- !ruby/object:Gem::Version
|
73
90
|
version: '0'
|
74
91
|
- !ruby/object:Gem::Dependency
|
75
|
-
name:
|
92
|
+
name: awesome_spawn
|
93
|
+
requirement: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '1.6'
|
98
|
+
type: :runtime
|
99
|
+
prerelease: false
|
100
|
+
version_requirements: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '1.6'
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
name: bcrypt_pbkdf
|
76
107
|
requirement: !ruby/object:Gem::Requirement
|
77
108
|
requirements:
|
78
109
|
- - ">="
|
79
110
|
- !ruby/object:Gem::Version
|
80
|
-
version: '0'
|
81
|
-
|
111
|
+
version: '1.0'
|
112
|
+
- - "<"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '2.0'
|
115
|
+
type: :runtime
|
82
116
|
prerelease: false
|
83
117
|
version_requirements: !ruby/object:Gem::Requirement
|
84
118
|
requirements:
|
85
119
|
- - ">="
|
86
120
|
- !ruby/object:Gem::Version
|
87
|
-
version: '0'
|
121
|
+
version: '1.0'
|
122
|
+
- - "<"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.0'
|
88
125
|
- !ruby/object:Gem::Dependency
|
89
|
-
name:
|
126
|
+
name: ed25519
|
90
127
|
requirement: !ruby/object:Gem::Requirement
|
91
128
|
requirements:
|
92
|
-
- - "
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.2'
|
132
|
+
- - "<"
|
93
133
|
- !ruby/object:Gem::Version
|
94
|
-
version: '
|
134
|
+
version: '2.0'
|
95
135
|
type: :runtime
|
96
136
|
prerelease: false
|
97
137
|
version_requirements: !ruby/object:Gem::Requirement
|
98
138
|
requirements:
|
99
|
-
- - "
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '1.2'
|
142
|
+
- - "<"
|
100
143
|
- !ruby/object:Gem::Version
|
101
|
-
version: '
|
144
|
+
version: '2.0'
|
102
145
|
- !ruby/object:Gem::Dependency
|
103
146
|
name: inifile
|
104
147
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,6 +170,20 @@ dependencies:
|
|
127
170
|
- - "~>"
|
128
171
|
- !ruby/object:Gem::Version
|
129
172
|
version: '4.0'
|
173
|
+
- !ruby/object:Gem::Dependency
|
174
|
+
name: net-ssh
|
175
|
+
requirement: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - "~>"
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: 7.2.3
|
180
|
+
type: :runtime
|
181
|
+
prerelease: false
|
182
|
+
version_requirements: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - "~>"
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: 7.2.3
|
130
187
|
- !ruby/object:Gem::Dependency
|
131
188
|
name: nokogiri
|
132
189
|
requirement: !ruby/object:Gem::Requirement
|
@@ -180,19 +237,19 @@ dependencies:
|
|
180
237
|
- !ruby/object:Gem::Version
|
181
238
|
version: '0'
|
182
239
|
- !ruby/object:Gem::Dependency
|
183
|
-
name:
|
240
|
+
name: simplecov
|
184
241
|
requirement: !ruby/object:Gem::Requirement
|
185
242
|
requirements:
|
186
|
-
- - "
|
243
|
+
- - ">="
|
187
244
|
- !ruby/object:Gem::Version
|
188
|
-
version:
|
189
|
-
type: :
|
245
|
+
version: 0.21.2
|
246
|
+
type: :development
|
190
247
|
prerelease: false
|
191
248
|
version_requirements: !ruby/object:Gem::Requirement
|
192
249
|
requirements:
|
193
|
-
- - "
|
250
|
+
- - ">="
|
194
251
|
- !ruby/object:Gem::Version
|
195
|
-
version:
|
252
|
+
version: 0.21.2
|
196
253
|
description: |2
|
197
254
|
|
198
255
|
LinuxAdmin is a module to simplify management of linux systems.
|
@@ -202,7 +259,7 @@ email:
|
|
202
259
|
- brandondunne@hotmail.com
|
203
260
|
- fryguy9@gmail.com
|
204
261
|
- mmorsi@redhat.com
|
205
|
-
- jrafanie@
|
262
|
+
- jrafanie@gmail.com
|
206
263
|
- keenan@thebrocks.net
|
207
264
|
- twiest@redhat.com
|
208
265
|
- ncarboni@redhat.com
|
@@ -218,7 +275,10 @@ email:
|
|
218
275
|
- nicklamuro@gmail.com
|
219
276
|
- djberg96@gmail.com
|
220
277
|
- simaishi@redhat.com
|
221
|
-
-
|
278
|
+
- 16326669+d-m-u@users.noreply.github.com
|
279
|
+
- 42819689+whitesource-bolt-for-github[bot]@users.noreply.github.com
|
280
|
+
- adam@grare.com
|
281
|
+
- 29139614+renovate[bot]@users.noreply.github.com
|
222
282
|
executables: []
|
223
283
|
extensions: []
|
224
284
|
extra_rdoc_files: []
|
@@ -268,7 +328,7 @@ homepage: http://github.com/ManageIQ/linux_admin
|
|
268
328
|
licenses:
|
269
329
|
- MIT
|
270
330
|
metadata: {}
|
271
|
-
post_install_message:
|
331
|
+
post_install_message:
|
272
332
|
rdoc_options: []
|
273
333
|
require_paths:
|
274
334
|
- lib
|
@@ -276,15 +336,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
276
336
|
requirements:
|
277
337
|
- - ">="
|
278
338
|
- !ruby/object:Gem::Version
|
279
|
-
version: 2.
|
339
|
+
version: '2.6'
|
280
340
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
281
341
|
requirements:
|
282
342
|
- - ">="
|
283
343
|
- !ruby/object:Gem::Version
|
284
344
|
version: '0'
|
285
345
|
requirements: []
|
286
|
-
rubygems_version: 3.
|
287
|
-
signing_key:
|
346
|
+
rubygems_version: 3.3.27
|
347
|
+
signing_key:
|
288
348
|
specification_version: 4
|
289
349
|
summary: LinuxAdmin is a module to simplify management of linux systems.
|
290
350
|
test_files: []
|