Class: Yast::SystemdTargetClass

Inherits:
Module
  • Object
show all
Includes:
Logger
Defined in:
library/systemd/src/modules/systemd_target.rb

Defined Under Namespace

Classes: Target

Constant Summary collapse

UNIT_SUFFIX =
".target".freeze
DEFAULT_TARGET =
"default.target".freeze
PROPMAP =
{ allow_isolate: "AllowIsolate" }.freeze

Instance Method Summary collapse

Instance Method Details

#all(propmap = {}) ⇒ Object

Parameters:



70
71
72
73
74
75
# File 'library/systemd/src/modules/systemd_target.rb', line 70

def all(propmap = {})
  targets = Systemctl.target_units.map do |target_unit_name|
    find(target_unit_name, propmap)
  end
  targets.compact
end

#find(target_name, propmap = {}) ⇒ Object

Parameters:



52
53
54
55
56
57
58
59
60
61
62
# File 'library/systemd/src/modules/systemd_target.rb', line 52

def find(target_name, propmap = {})
  target_name += UNIT_SUFFIX unless target_name.end_with?(UNIT_SUFFIX)
  target = Target.new(target_name, PROPMAP.merge(propmap))

  if target.properties.not_found?
    log.error "Target #{target_name} not found: #{target.properties.inspect}"
    return nil
  end

  target
end

#find!(target_name, propmap = {}) ⇒ Object

Parameters:



65
66
67
# File 'library/systemd/src/modules/systemd_target.rb', line 65

def find!(target_name, propmap = {})
  find(target_name, propmap) || raise(SystemdTargetNotFound, target_name)
end

#get_defaultObject

Raises:



77
78
79
80
81
82
# File 'library/systemd/src/modules/systemd_target.rb', line 77

def get_default
  result = Systemctl.execute("get-default")
  raise(SystemctlError, result) unless result.exit.zero?

  find(result.stdout.strip)
end

#set_default(target) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'library/systemd/src/modules/systemd_target.rb', line 84

def set_default(target)
  target_unit = target.is_a?(Target) ? target : find(target)

  unless target_unit
    log.error "Cannot find target #{target.inspect}"
    return false
  end

  target_unit.set_default
end