machinery-tool 1.22.1 → 1.22.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/.git_revision +1 -1
  3. data/NEWS +10 -0
  4. data/bin/machinery +1 -1
  5. data/lib/analyze_changed_config_files_diffs_task.rb +6 -6
  6. data/lib/autoyast.rb +2 -2
  7. data/lib/build_task.rb +10 -7
  8. data/lib/cli.rb +1005 -801
  9. data/lib/compare_task.rb +11 -7
  10. data/lib/comparison.rb +2 -2
  11. data/lib/config_base.rb +1 -1
  12. data/lib/config_task.rb +1 -1
  13. data/lib/containerize_task.rb +3 -3
  14. data/lib/containerized_app.rb +1 -1
  15. data/lib/copy_task.rb +1 -1
  16. data/lib/current_user.rb +1 -1
  17. data/lib/deploy_task.rb +6 -4
  18. data/lib/diff_widget.rb +67 -63
  19. data/lib/docker_system.rb +12 -8
  20. data/lib/dpkg_database.rb +1 -1
  21. data/lib/element_filter.rb +7 -4
  22. data/lib/exceptions.rb +23 -5
  23. data/lib/export_task.rb +1 -1
  24. data/lib/exporter.rb +1 -1
  25. data/lib/file_diff.rb +1 -1
  26. data/lib/file_scope.rb +1 -1
  27. data/lib/file_validator.rb +7 -4
  28. data/lib/filter.rb +97 -93
  29. data/lib/filter_option_parser.rb +2 -2
  30. data/lib/hint.rb +64 -59
  31. data/lib/html.rb +1 -1
  32. data/lib/inspect_task.rb +12 -12
  33. data/lib/inspector.rb +3 -3
  34. data/lib/json_validation_error_cleaner.rb +1 -1
  35. data/lib/json_validator.rb +4 -4
  36. data/lib/kiwi_config.rb +8 -4
  37. data/lib/list_task.rb +10 -9
  38. data/lib/local_system.rb +11 -5
  39. data/lib/logged_cheetah.rb +1 -1
  40. data/lib/man_task.rb +10 -6
  41. data/lib/managed_files_database.rb +1 -1
  42. data/lib/manifest.rb +5 -5
  43. data/lib/migration.rb +16 -10
  44. data/lib/mountpoints.rb +1 -1
  45. data/lib/move_task.rb +1 -1
  46. data/lib/remote_system.rb +7 -7
  47. data/lib/remove_task.rb +1 -1
  48. data/lib/renderer.rb +177 -172
  49. data/lib/rpm.rb +4 -4
  50. data/lib/rpm_database.rb +1 -1
  51. data/lib/scope.rb +2 -2
  52. data/lib/scope_file_access_archive.rb +1 -1
  53. data/lib/scope_file_access_flat.rb +1 -1
  54. data/lib/scope_file_store.rb +1 -1
  55. data/lib/serve_html_task.rb +6 -2
  56. data/lib/server.rb +19 -12
  57. data/lib/show_task.rb +10 -6
  58. data/lib/static_html.rb +1 -1
  59. data/lib/system.rb +10 -10
  60. data/lib/system_description.rb +14 -13
  61. data/lib/system_description_memory_store.rb +1 -1
  62. data/lib/system_description_store.rb +9 -9
  63. data/lib/tarball.rb +8 -2
  64. data/lib/upgrade_format_task.rb +11 -6
  65. data/lib/validate_task.rb +2 -2
  66. data/lib/version.rb +1 -1
  67. data/lib/workload_mapper.rb +2 -2
  68. data/lib/workload_mapper_dsl.rb +1 -1
  69. data/lib/zypper.rb +40 -17
  70. data/machinery-helper/machinery_helper.go +35 -16
  71. data/machinery-helper/version.go +1 -1
  72. data/man/generated/machinery.1.gz +0 -0
  73. data/manual/site/sitemap.xml +24 -24
  74. data/plugins/changed_config_files/changed_config_files_inspector.rb +59 -56
  75. data/plugins/changed_config_files/changed_config_files_model.rb +23 -21
  76. data/plugins/changed_config_files/changed_config_files_renderer.rb +56 -52
  77. data/plugins/changed_managed_files/changed_managed_files_inspector.rb +52 -50
  78. data/plugins/changed_managed_files/changed_managed_files_model.rb +23 -21
  79. data/plugins/changed_managed_files/changed_managed_files_renderer.rb +43 -39
  80. data/plugins/environment/environment_inspector.rb +25 -23
  81. data/plugins/environment/environment_model.rb +5 -3
  82. data/plugins/groups/groups_inspector.rb +30 -28
  83. data/plugins/groups/groups_model.rb +18 -17
  84. data/plugins/groups/groups_renderer.rb +29 -25
  85. data/plugins/os/os_inspector.rb +120 -118
  86. data/plugins/os/os_model.rb +139 -134
  87. data/plugins/os/os_renderer.rb +13 -9
  88. data/plugins/packages/packages_inspector.rb +99 -86
  89. data/plugins/packages/packages_model.rb +35 -34
  90. data/plugins/packages/packages_renderer.rb +47 -39
  91. data/plugins/patterns/patterns_inspector.rb +70 -68
  92. data/plugins/patterns/patterns_model.rb +19 -18
  93. data/plugins/patterns/patterns_renderer.rb +36 -32
  94. data/plugins/repositories/repositories_inspector.rb +162 -156
  95. data/plugins/repositories/repositories_model.rb +50 -49
  96. data/plugins/repositories/repositories_renderer.rb +48 -44
  97. data/plugins/repositories/schema/system-description-repositories.schema-v10.json +0 -1
  98. data/plugins/services/services_inspector.rb +187 -176
  99. data/plugins/services/services_model.rb +37 -36
  100. data/plugins/services/services_renderer.rb +28 -24
  101. data/plugins/unmanaged_files/unmanaged_files_inspector.rb +102 -99
  102. data/plugins/unmanaged_files/unmanaged_files_model.rb +64 -56
  103. data/plugins/unmanaged_files/unmanaged_files_renderer.rb +44 -40
  104. data/plugins/users/users_inspector.rb +67 -65
  105. data/plugins/users/users_model.rb +37 -36
  106. data/plugins/users/users_renderer.rb +31 -27
  107. data/schema/migrations/migrate1to2.rb +1 -1
  108. data/schema/migrations/migrate2to3.rb +1 -1
  109. data/schema/migrations/migrate3to4.rb +1 -1
  110. data/schema/migrations/migrate4to5.rb +1 -1
  111. data/schema/migrations/migrate5to6.rb +1 -1
  112. data/schema/migrations/migrate6to7.rb +1 -1
  113. data/schema/migrations/migrate7to8.rb +1 -1
  114. data/schema/migrations/migrate8to9.rb +1 -1
  115. data/schema/migrations/migrate9to10.rb +1 -1
  116. metadata +2 -2
@@ -15,63 +15,67 @@
15
15
  # To contact SUSE about this file by physical or electronic mail,
16
16
  # you may find current contact information at www.suse.com
17
17
 
18
- class RepositoriesRenderer < Renderer
19
- def content(description)
20
- return unless description.repositories
18
+ module Machinery
19
+ class Ui
20
+ class RepositoriesRenderer < Machinery::Ui::Renderer
21
+ def content(description)
22
+ return unless description.repositories
21
23
 
22
- if description.repositories.empty?
23
- puts "There are no repositories."
24
- end
24
+ if description.repositories.empty?
25
+ puts "There are no repositories."
26
+ end
25
27
 
26
- na_note("repository type") if description.repositories.any? { |a| a[:type] == "" }
28
+ na_note("repository type") if description.repositories.any? { |a| a[:type] == "" }
27
29
 
28
- list do
29
- description.repositories.each do |p|
30
- item_name = if p.name
31
- p.name
32
- else
33
- "URI: #{p.url}"
34
- end
35
- item item_name do
36
- if p.url.is_a?(Array)
37
- list "URI", sublist: true do
38
- p.url.each do |url|
39
- item url
30
+ list do
31
+ description.repositories.each do |p|
32
+ item_name = if p.name
33
+ p.name
34
+ else
35
+ "URI: #{p.url}"
36
+ end
37
+ item item_name do
38
+ if p.url.is_a?(::Array)
39
+ list "URI", sublist: true do
40
+ p.url.each do |url|
41
+ item url
42
+ end
43
+ end
44
+ elsif p.name
45
+ puts "URI: #{p.url}"
40
46
  end
47
+ puts "Mirrorlist: #{!p.mirrorlist.empty? ? p.mirrorlist : "N/A"}" if p.mirrorlist
48
+ puts "Alias: #{p.alias}" if p.alias
49
+ puts "Distribution: #{p.distribution}" if p.distribution
50
+ puts "Components: #{p.components.join(", ")}" if p.components
51
+ puts "Enabled: #{p.enabled ? "Yes" : "No"}" unless p.enabled.nil?
52
+ puts "Refresh: #{p.autorefresh ? "Yes" : "No"}" unless p.autorefresh.nil?
53
+ puts "Priority: #{p.priority}" unless p.priority.nil?
54
+ puts "Type: #{p.type || "N/A"}"
41
55
  end
42
- elsif p.name
43
- puts "URI: #{p.url}"
44
56
  end
45
- puts "Mirrorlist: #{!p.mirrorlist.empty? ? p.mirrorlist : "N/A"}" if p.mirrorlist
46
- puts "Alias: #{p.alias}" if p.alias
47
- puts "Distribution: #{p.distribution}" if p.distribution
48
- puts "Components: #{p.components.join(", ")}" if p.components
49
- puts "Enabled: #{p.enabled ? "Yes" : "No"}" unless p.enabled.nil?
50
- puts "Refresh: #{p.autorefresh ? "Yes" : "No"}" unless p.autorefresh.nil?
51
- puts "Priority: #{p.priority}" unless p.priority.nil?
52
- puts "Type: #{p.type || "N/A"}"
53
57
  end
54
58
  end
55
- end
56
- end
57
59
 
58
- def display_name
59
- "Repositories"
60
- end
60
+ def display_name
61
+ "Repositories"
62
+ end
63
+
64
+ def compare_content_changed(changed_elements)
65
+ list do
66
+ changed_elements.each do |one, two|
67
+ changes = []
68
+ relevant_attributes = one.attributes.keys
61
69
 
62
- def compare_content_changed(changed_elements)
63
- list do
64
- changed_elements.each do |one, two|
65
- changes = []
66
- relevant_attributes = one.attributes.keys
70
+ relevant_attributes.each do |attribute|
71
+ if one[attribute] != two[attribute]
72
+ changes << "#{attribute}: #{one[attribute]} <> #{two[attribute]}"
73
+ end
74
+ end
67
75
 
68
- relevant_attributes.each do |attribute|
69
- if one[attribute] != two[attribute]
70
- changes << "#{attribute}: #{one[attribute]} <> #{two[attribute]}"
76
+ item "#{one.alias} (#{changes.join(", ")})"
71
77
  end
72
78
  end
73
-
74
- item "#{one.alias} (#{changes.join(", ")})"
75
79
  end
76
80
  end
77
81
  end
@@ -146,7 +146,6 @@
146
146
  },
147
147
  "url": {
148
148
  "type": "string",
149
- "format": "uri",
150
149
  "minLength": 1
151
150
  },
152
151
  "components": {
@@ -15,218 +15,229 @@
15
15
  # To contact SUSE about this file by physical or electronic mail,
16
16
  # you may find current contact information at www.suse.com
17
17
 
18
- class ServicesInspector < Inspector
19
- has_priority 70
18
+ module Machinery
19
+ class ServicesInspector < Machinery::Inspector
20
+ has_priority 70
20
21
 
21
- def initialize(system, description)
22
- @system = system
23
- @description = description
24
- end
22
+ def initialize(system, description)
23
+ @system = system
24
+ @description = description
25
+ end
25
26
 
26
- def inspect(_filter, _options = {})
27
- services, init_system =
28
- case
29
- when @description.environment.system_type == "docker"
30
- then [[], "none"]
31
- when @system.has_command?("systemctl")
32
- then [inspect_systemd_services, "systemd"]
33
- when @system.has_command?("initctl") && @system.has_command?("chkconfig")
34
- then [parse_redhat_chkconfig.map { |s| s["legacy_sysv"] = true; s }, "upstart"]
35
- when @system.has_command?("initctl") && !@system.has_command?("chkconfig")
36
- then [inspect_ubuntu_services, "upstart"]
37
- else
38
- [inspect_sysvinit_services, "sysvinit"]
39
- end
27
+ def inspect(_filter, _options = {})
28
+ services, init_system =
29
+ if @description.environment.system_type == "docker"
30
+ [[], "none"]
31
+ elsif @system.has_command?("systemctl")
32
+ [inspect_systemd_services, "systemd"]
33
+ elsif @system.has_command?("initctl") && @system.has_command?("chkconfig")
34
+ [parse_redhat_chkconfig.map { |s| s["legacy_sysv"] = true; s }, "upstart"]
35
+ elsif @system.has_command?("initctl") && !@system.has_command?("chkconfig")
36
+ [inspect_ubuntu_services, "upstart"]
37
+ else
38
+ [inspect_sysvinit_services, "sysvinit"]
39
+ end
40
+
41
+ @description.services = ServicesScope.new(
42
+ services,
43
+ init_system: init_system
44
+ )
45
+ end
40
46
 
41
- @description.services = ServicesScope.new(
42
- services,
43
- init_system: init_system
44
- )
45
- end
47
+ def summary
48
+ "Found #{Machinery.pluralize(@description.services.length, "%d service")}."
49
+ end
46
50
 
47
- def summary
48
- "Found #{Machinery.pluralize(@description.services.length, "%d service")}."
49
- end
51
+ private
50
52
 
51
- private
53
+ def inspect_systemd_services
54
+ services = list_unit_files.map do |line|
55
+ name, state = line.split(/\s+/)
52
56
 
53
- def inspect_systemd_services
54
- services = list_unit_files.map do |line|
55
- name, state = line.split(/\s+/)
57
+ Service.new(name: name, state: state)
58
+ end
56
59
 
57
- Service.new(name: name, state: state)
58
- end
60
+ list_unit_files(true).map { |line| line.split(/\s+/) }.each do |name, state|
61
+ prefix, suffix = name.split("@")
59
62
 
60
- list_unit_files(true).map { |line| line.split(/\s+/) }.each do |name, state|
61
- prefix, suffix = name.split("@")
63
+ instances = list_units.select { |i| i =~ /#{prefix}@.+#{suffix}/ }.each do |instance|
64
+ services << Service.new(name: instance, state: unit_is_enabled?(instance))
65
+ end
62
66
 
63
- instances = list_units.select { |i| i =~ /#{prefix}@.+#{suffix}/ }.each do |instance|
64
- services << Service.new(name: instance, state: unit_is_enabled?(instance))
67
+ services << Service.new(name: name, state: state) if instances.empty?
65
68
  end
66
69
 
67
- services << Service.new(name: name, state: state) if instances.empty?
70
+ services.sort_by(&:name)
68
71
  end
69
72
 
70
- services.sort_by(&:name)
71
- end
73
+ def list_unit_files(templates = false)
74
+ @unit_files ||= @system.run_command(
75
+ "systemctl",
76
+ "list-unit-files",
77
+ "--type=service,socket",
78
+ stdout: :capture
79
+ )
80
+
81
+ # The first line contains a table header. The last two lines contain a
82
+ # separator and a summary (e.g. "197 unit files listed").
83
+ # Files will be grouped by depending on
84
+ # wether they are templates or not.
85
+ @unit_files.lines[1..-3].group_by { |l| l.include?("@") }[templates]
86
+ end
72
87
 
73
- def list_unit_files(templates = false)
74
- @unit_files ||= @system.run_command(
75
- "systemctl",
76
- "list-unit-files",
77
- "--type=service,socket",
78
- :stdout => :capture
79
- )
80
-
81
- # The first line contains a table header. The last two lines contain a
82
- # separator and a summary (e.g. "197 unit files listed"). Files will be grouped by depending on
83
- # weather they are templates or not.
84
- @unit_files.lines[1..-3].group_by { |l| l.include?("@") }[templates]
85
- end
88
+ def list_units
89
+ output = @system.run_command(
90
+ "systemctl",
91
+ "list-units",
92
+ "--all",
93
+ stdout: :capture
94
+ )
86
95
 
87
- def list_units
88
- output = @system.run_command(
89
- "systemctl",
90
- "list-units",
91
- "--all",
92
- stdout: :capture
93
- )
96
+ output.lines[1..-8].map { |line| line.split.first }
97
+ end
94
98
 
95
- output.lines[1..-8].map { |line| line.split.first }
96
- end
99
+ def unit_is_enabled?(unit)
100
+ output = @system.run_command("systemctl", "is-enabled", unit, stdout: :capture)
101
+ return output.split("\n").first
102
+ rescue Cheetah::ExecutionFailed
103
+ return "disabled"
104
+ end
97
105
 
98
- def unit_is_enabled?(unit)
99
- output = @system.run_command("systemctl", "is-enabled", unit, stdout: :capture)
100
- return output.split("\n").first
101
- rescue Cheetah::ExecutionFailed
102
- return "disabled"
103
- end
106
+ def inspect_sysvinit_services
107
+ # Red Hat's chkconfig behaves differently than SUSE's: It takes different
108
+ # command line arguments and has a different output format. We determine
109
+ # if it's Red Hat by calling 'chkconfig --version'. On SUSE it exits with
110
+ # an error, on Red Hat it doesn't.
111
+ #
112
+ begin
113
+ @system.run_command("/sbin/chkconfig", "--version")
114
+ services = parse_redhat_chkconfig
115
+ rescue
116
+ services = parse_suse_chkconfig
117
+ end
104
118
 
105
- def inspect_sysvinit_services
106
- # Red Hat's chkconfig behaves differently than SUSE's: It takes different
107
- # command line arguments and has a different output format. We determine
108
- # if it's Red Hat by calling 'chkconfig --version'. On SUSE it exits with
109
- # an error, on Red Hat it doesn't.
110
- #
111
- begin
112
- @system.run_command("/sbin/chkconfig", "--version")
113
- services = parse_redhat_chkconfig
114
- rescue
115
- services = parse_suse_chkconfig
119
+ services.sort_by(&:name)
116
120
  end
117
121
 
118
- services.sort_by(&:name)
119
- end
122
+ def inspect_ubuntu_services
123
+ # Ubuntu is managing its services using upstart but also has some
124
+ # services still not handled by that. Therefor we need to scan upstart
125
+ # and sysV to determine all services and their bootup state
126
+ services = parse_ubuntu_upstart
127
+ parse_ubuntu_sysv.each do |service|
128
+ services << service unless services.find { |s| s.name == service.name }
129
+ end
120
130
 
121
- def inspect_ubuntu_services
122
- # Ubuntu is managing its services using upstart but also has some
123
- # services still not handled by that. Therefor we need to scan upstart
124
- # and sysV to determine all services and their bootup state
125
- services = parse_ubuntu_upstart
126
- parse_ubuntu_sysv.each do |service|
127
- services << service unless services.find { |s| s.name == service.name }
131
+ services.sort_by(&:name)
128
132
  end
129
133
 
130
- services.sort_by(&:name)
131
- end
134
+ def parse_ubuntu_upstart
135
+ initctl_output = @system.run_command(
136
+ "/sbin/initctl",
137
+ "show-config",
138
+ "-e",
139
+ stdout: :capture
140
+ )
132
141
 
133
- def parse_ubuntu_upstart
134
- initctl_output = @system.run_command("/sbin/initctl", "show-config", "-e", stdout: :capture)
142
+ servicelist = initctl_output.lines.map(&:chomp).slice_before do |l|
143
+ !l.start_with?(" ")
144
+ end
145
+ enabled, disabled = servicelist.partition do |s|
146
+ s.find { |e| e.start_with?(" start on runlevel", " start on startup") }
147
+ end
135
148
 
136
- servicelist = initctl_output.lines.map(&:chomp).slice_before { |l| !l.start_with?(" ") }
137
- enabled, disabled = servicelist.partition do |s|
138
- s.find { |e| e.start_with?(" start on runlevel", " start on startup") }
149
+ services = enabled.map(&:first).each.map do |name|
150
+ Service.new(name: name, state: "enabled", legacy_sysv: false)
151
+ end
152
+ services + disabled.map(&:first).each.map do |name|
153
+ Service.new(name: name, state: "disabled", legacy_sysv: false)
154
+ end
139
155
  end
140
156
 
141
- services = enabled.map(&:first).each.map do |name|
142
- Service.new(name: name, state: "enabled", legacy_sysv: false)
143
- end
144
- services + disabled.map(&:first).each.map do |name|
145
- Service.new(name: name, state: "disabled", legacy_sysv: false)
146
- end
147
- end
157
+ def parse_ubuntu_sysv
158
+ # Get all sysV services
159
+ out, err = @system.run_command(
160
+ "/usr/sbin/service",
161
+ "--status-all",
162
+ stdout: :capture,
163
+ stderr: :capture
164
+ )
165
+ services_output = out + err
166
+
167
+ sysv_all = services_output.each_line.map { |line|
168
+ line.chomp.sub(/^.*\]../, "")
169
+ }
170
+
171
+ # Get all enabled sysV services - default in ubuntu1404 is runlevel 2
172
+ # and runlevels 3,4 and 5 are considered to be identical to 2.
173
+ runlevels = ["2", "S"]
174
+ find_output = runlevels.each.map do |runlevel|
175
+ @system.run_command(
176
+ "/usr/bin/find",
177
+ "/etc/rc#{runlevel}.d",
178
+ "-name",
179
+ "S\*",
180
+ stdout: :capture
181
+ ).split
182
+ end
148
183
 
149
- def parse_ubuntu_sysv
150
- # Get all sysV services
151
- out, err = @system.run_command(
152
- "/usr/sbin/service",
153
- "--status-all",
154
- stdout: :capture, stderr: :capture)
155
- services_output = out + err
156
-
157
- sysv_all = services_output.each_line.map { |line|
158
- line.chomp.sub(/^.*\]../, "")
159
- }
160
-
161
- # Get all enabled sysV services - default in ubuntu1404 is runlevel 2
162
- # and runlevels 3,4 and 5 are considered to be identical to 2.
163
- runlevels = ["2", "S"]
164
- find_output = runlevels.each.map do |runlevel|
165
- @system.run_command(
166
- "/usr/bin/find",
167
- "/etc/rc#{runlevel}.d",
168
- "-name",
169
- "S\*",
170
- stdout: :capture).split
171
- end
184
+ sysv_enabled = find_output.flatten.map { |line|
185
+ line.chomp.sub(/^\/etc\/rc.\.d\/.../, "")
186
+ }.uniq
187
+ sysv_disabled = sysv_all - sysv_enabled
172
188
 
173
- sysv_enabled = find_output.flatten.map { |line|
174
- line.chomp.sub(/^\/etc\/rc.\.d\/.../, "")
175
- }.uniq
176
- sysv_disabled = sysv_all - sysv_enabled
189
+ services = sysv_enabled.map.each do |name|
190
+ Service.new(name: name, state: "enabled", legacy_sysv: true)
191
+ end
177
192
 
178
- services = sysv_enabled.map.each do |name|
179
- Service.new(name: name, state: "enabled", legacy_sysv: true)
193
+ services + sysv_disabled.map.each do |name|
194
+ Service.new(name: name, state: "disabled", legacy_sysv: true)
195
+ end
180
196
  end
181
197
 
182
- services + sysv_disabled.map.each do |name|
183
- Service.new(name: name, state: "disabled", legacy_sysv: true)
198
+ def parse_suse_chkconfig
199
+ # check if chkconfig is available otherwise use /sbin/chkconfig
200
+ # this fixes issue on sles11sp3 where chkconfig isn't in /usr/bin
201
+ chkconfig = @system.check_requirement(["chkconfig", "/sbin/chkconfig"], "--help")
202
+ output = @system.run_command(
203
+ chkconfig,
204
+ "--allservices",
205
+ stdout: :capture
206
+ )
207
+
208
+ output.lines.map do |line|
209
+ name, state = line.split(/\s+/)
210
+ Service.new(name: name, state: state)
211
+ end
184
212
  end
185
- end
186
213
 
187
- def parse_suse_chkconfig
188
- # check if chkconfig is available otherwise use /sbin/chkconfig
189
- # this fixes issue on sles11sp3 where chkconfig isn't in /usr/bin
190
- chkconfig = @system.check_requirement(["chkconfig", "/sbin/chkconfig"], "--help")
191
- output = @system.run_command(
192
- chkconfig,
193
- "--allservices",
194
- :stdout => :capture
195
- )
196
-
197
- output.lines.map do |line|
198
- name, state = line.split(/\s+/)
199
- Service.new(name: name, state: state)
200
- end
201
- end
214
+ def parse_redhat_chkconfig
215
+ @system.check_requirement("/sbin/runlevel")
216
+ _, runlevel = @system.run_command(
217
+ "/sbin/runlevel",
218
+ stdout: :capture
219
+ ).split(" ")
220
+
221
+ output = @system.run_command(
222
+ "/sbin/chkconfig", "--list",
223
+ stdout: :capture
224
+ )
225
+
226
+ # Run chkconfig output through regular expressions to parse
227
+ # seperatly for systemv and xinetd services.
228
+ services = output.lines.select do |line|
229
+ line =~ /^\S+(\s+\d:(on|off))+.*$/
230
+ end.map do |line|
231
+ name, *state = line.split(/\s+/)
232
+ Service.new(name: name, state: state[runlevel.to_i].split(":")[1])
233
+ end
202
234
 
203
- def parse_redhat_chkconfig
204
- @system.check_requirement("/sbin/runlevel")
205
- _, runlevel = @system.run_command(
206
- "/sbin/runlevel",
207
- stdout: :capture
208
- ).split(" ")
209
-
210
- output = @system.run_command(
211
- "/sbin/chkconfig", "--list",
212
- stdout: :capture
213
- )
214
-
215
- # Run chkconfig output through regular expressions to parse
216
- # seperatly for systemv and xinetd services.
217
- services = output.lines.select do |line|
218
- line =~ /^\S+(\s+\d:(on|off))+.*$/
219
- end.map do |line|
220
- state = []
221
- name, state[0], state[1], state[2], state[3], state[4], state[5], state[6] = line.split(/\s+/)
222
- Service.new(name: name, state: state[runlevel.to_i].split(":")[1])
223
- end
235
+ services += output.lines.select { |line| line =~ /^\s+\S+:\s+(on|off).*$/ }.map do |line|
236
+ name, state = line.split(/:/)
237
+ Service.new(name: name.strip, state: state.strip)
238
+ end
224
239
 
225
- services += output.lines.select { |line| line =~ /^\s+\S+:\s+(on|off).*$/ }.map do |line|
226
- name, state = line.split(/:/)
227
- Service.new(name: name.strip, state: state.strip)
240
+ services
228
241
  end
229
-
230
- services
231
242
  end
232
243
  end