fix: add module doc comment to satisfy reek IrresponsibleModule
ci/woodpecker/pr/ruby-validate Pipeline was successful
ci/woodpecker/pr/bolt-validate Pipeline was successful
ci/woodpecker/pr/yamllint Pipeline was successful
ci/woodpecker/pr/epp-validate Pipeline was successful
ci/woodpecker/pr/puppet-lint Pipeline was successful
ci/woodpecker/pr/erb-validate Pipeline was successful
ci/woodpecker/pr/puppet-validate Pipeline was successful
ci/woodpecker/pr/ruby-check Pipeline was successful
ci/woodpecker/pr/ruby-validate Pipeline was successful
ci/woodpecker/pr/bolt-validate Pipeline was successful
ci/woodpecker/pr/yamllint Pipeline was successful
ci/woodpecker/pr/epp-validate Pipeline was successful
ci/woodpecker/pr/puppet-lint Pipeline was successful
ci/woodpecker/pr/erb-validate Pipeline was successful
ci/woodpecker/pr/puppet-validate Pipeline was successful
ci/woodpecker/pr/ruby-check Pipeline was successful
This commit is contained in:
@@ -4,39 +4,46 @@ require 'facter'
|
|||||||
|
|
||||||
# Detects active ceph service instances via systemctl and exposes facts
|
# Detects active ceph service instances via systemctl and exposes facts
|
||||||
# for use in ceph service management profiles.
|
# for use in ceph service management profiles.
|
||||||
module Unkin::Ceph::Utils
|
# rubocop:disable Style/ClassAndModuleChildren
|
||||||
TYPES = %w[mon mgr mds osd].freeze
|
module Unkin
|
||||||
|
module Ceph
|
||||||
|
# Detects active ceph service instances via systemctl and exposes Facter facts.
|
||||||
|
module Utils
|
||||||
|
TYPES = %w[mon mgr mds osd].freeze
|
||||||
|
|
||||||
def self.services
|
def self.services
|
||||||
output = Facter::Core::Execution.execute(
|
output = Facter::Core::Execution.execute(
|
||||||
'systemctl list-units "ceph*" --no-legend --plain --all 2>/dev/null',
|
'systemctl list-units "ceph*" --no-legend --plain --all 2>/dev/null',
|
||||||
on_fail: ''
|
on_fail: ''
|
||||||
)
|
)
|
||||||
parse_units(output)
|
parse_units(output)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.parse_units(output)
|
def self.parse_units(output)
|
||||||
result = TYPES.each_with_object({}) { |type, hash| hash[type] = [] }
|
result = TYPES.each_with_object({}) { |type, hash| hash[type] = [] }
|
||||||
output.each_line do |line|
|
output.each_line do |line|
|
||||||
unit = line.split.first
|
unit = line.split.first
|
||||||
next unless unit
|
next unless unit
|
||||||
|
|
||||||
match_unit(result, unit)
|
match_unit(result, unit)
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.match_unit(result, unit)
|
||||||
|
TYPES.each do |type|
|
||||||
|
match = unit.match(/\Aceph-#{type}@(.+)\.service\z/)
|
||||||
|
result[type] << "ceph-#{type}@#{match[1]}" if match
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
TYPES.each do |type|
|
||||||
|
define_singleton_method(:"#{type}?") { !services[type].empty? }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
result
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.match_unit(result, unit)
|
|
||||||
TYPES.each do |type|
|
|
||||||
match = unit.match(/\Aceph-#{type}@(.+)\.service\z/)
|
|
||||||
result[type] << "ceph-#{type}@#{match[1]}" if match
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
TYPES.each do |type|
|
|
||||||
define_singleton_method(:"#{type}?") { !services[type].empty? }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Style/ClassAndModuleChildren
|
||||||
|
|
||||||
Facter.add('ceph_services') do
|
Facter.add('ceph_services') do
|
||||||
setcode { Unkin::Ceph::Utils.services }
|
setcode { Unkin::Ceph::Utils.services }
|
||||||
|
|||||||
Reference in New Issue
Block a user