class CFA::Grub2::Default

Represents grub configuration in /etc/default/grub Main features:

Constants

PATH
VALID_TERMINAL_OPTIONS

Public Class Methods

new(file_handler: nil) click to toggle source
Calls superclass method
# File lib/cfa/grub2/default.rb, line 31
def initialize(file_handler: nil)
  super(AugeasParser.new("sysconfig.lns"), PATH,
    file_handler: file_handler)
end

Public Instance Methods

cryptodisk() click to toggle source
# File lib/cfa/grub2/default.rb, line 102
def cryptodisk
  @cryptodisk ||= BooleanValue.new("GRUB_ENABLE_CRYPTODISK", self,
                                   true_value: "y", false_value: "n")
end
kernel_params() click to toggle source
# File lib/cfa/grub2/default.rb, line 67
def kernel_params
  @kernel_params ||= KernelParams.new(
    value_for("GRUB_CMDLINE_LINUX_DEFAULT"), "GRUB_CMDLINE_LINUX_DEFAULT"
  )
end
load() click to toggle source
Calls superclass method
# File lib/cfa/grub2/default.rb, line 48
def load
  super

  kernels = [kernel_params, xen_hypervisor_params, xen_kernel_params,
             recovery_params]
  kernels.each do |kernel|
    param_line = value_for(kernel.key)
    kernel.replace(param_line) if param_line
  end
end
os_prober() click to toggle source
# File lib/cfa/grub2/default.rb, line 59
def os_prober
  @os_prober ||= BooleanValue.new(
    "GRUB_DISABLE_OS_PROBER", self,
    # grub key is disable, so use reverse logic
    true_value: "false", false_value: "true"
  )
end
recovery_entry() click to toggle source
# File lib/cfa/grub2/default.rb, line 94
def recovery_entry
  @recovery_entry ||= BooleanValue.new(
    "GRUB_DISABLE_RECOVERY", self,
    # grub key is disable, so use reverse logic
    true_value: "false", false_value: "true"
  )
end
recovery_params() click to toggle source
# File lib/cfa/grub2/default.rb, line 87
def recovery_params
  @recovery_params ||= KernelParams.new(
    value_for("GRUB_CMDLINE_LINUX_RECOVERY"),
    "GRUB_CMDLINE_LINUX_RECOVERY"
  )
end
save() click to toggle source
Calls superclass method
# File lib/cfa/grub2/default.rb, line 36
def save
  # serialize kernel params object before save
  kernels = [@kernel_params, @xen_hypervisor_params, @xen_kernel_params,
             @recovery_params]
  kernels.each do |params|
    # FIXME: this empty prevent writing explicit empty kernel params.
    generic_set(params.key, params.serialize) if params && !params.empty?
  end

  super
end
serial_console() click to toggle source
# File lib/cfa/grub2/default.rb, line 155
def serial_console
  value_for("GRUB_SERIAL_COMMAND")
end
serial_console=(value) click to toggle source

Sets GRUB_SERIAL_COMMAND option

Updates GRUB_SERIAL_COMMAND with given value, also enables serial console in GRUB_TERMINAL

@param value [String] value for GRUB_SERIAL_COMMAND

# File lib/cfa/grub2/default.rb, line 150
def serial_console=(value)
  self.terminal = (terminal || []) | [:serial]
  generic_set("GRUB_SERIAL_COMMAND", value)
end
terminal() click to toggle source

Reads value of GRUB_TERMINAL from /etc/default/grub

GRUB_TERMINAL option allows multiple values as space separated string

@return [Array<Symbol>, nil] an array of symbols where each symbol

represents supported terminal definition
nil if value is undefined or empty
# File lib/cfa/grub2/default.rb, line 115
def terminal
  values = value_for("GRUB_TERMINAL")

  return nil if values.nil? || values.empty?

  values.split.map do |value|
    msg = "unknown GRUB_TERMINAL option #{value.inspect}"
    raise msg if !VALID_TERMINAL_OPTIONS.include?(value.to_sym)

    value.to_sym
  end
end
terminal=(values) click to toggle source

Sets GRUB_TERMINAL option

Raises an ArgumentError exception in case of invalid value

@param values [Array<Symbol>, nil] list of accepted terminal values

(@see VALID_TERMINAL_OPTIONS)
# File lib/cfa/grub2/default.rb, line 134
def terminal=(values)
  values = [] if values.nil?

  msg = "A value is invalid: #{values.inspect}"
  invalid = values.any? { |v| !VALID_TERMINAL_OPTIONS.include?(v) }
  raise ArgumentError, msg if invalid

  generic_set("GRUB_TERMINAL", values.join(" "))
end
xen_hypervisor_params() click to toggle source
# File lib/cfa/grub2/default.rb, line 73
def xen_hypervisor_params
  @xen_hypervisor_params ||= KernelParams.new(
    value_for("GRUB_CMDLINE_XEN_DEFAULT"),
    "GRUB_CMDLINE_XEN_DEFAULT"
  )
end
xen_kernel_params() click to toggle source
# File lib/cfa/grub2/default.rb, line 80
def xen_kernel_params
  @xen_kernel_params ||= KernelParams.new(
    value_for("GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT"),
    "GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT"
  )
end

Private Instance Methods

value_for(key) click to toggle source
# File lib/cfa/grub2/default.rb, line 161
def value_for(key)
  data[key].respond_to?(:value) ? data[key].value : data[key]
end