Class: Y2Network::ConfigWriter

Inherits:
Object
  • Object
show all
Includes:
Yast::I18n, Yast::Logger
Defined in:
src/lib/y2network/config_writer.rb

Overview

This class is responsible for writing the configuration to the system

It implements a #write method which receives a configuration object and apply the changes to the system. Moreover, it is possible to write partial configurations (the so-called 'sections'). For example, you might want to just write the DNS configuration but keep the rest as it is.

It is expect that a configuration writer exists for each supported backend by inheriting from this class. It implements support for the common bits: drivers, intefaces (udev rules), DNS and hostname settings. Of course, you are not forced to use this class as a base.

Constant Summary collapse

SECTIONS =

Returns The different sections handled by the writer.

Returns:

  • (Array<Symbol>)

    The different sections handled by the writer

[:routing, :drivers, :interfaces, :connections, :dns, :hostname].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for(source) ⇒ Y2Network::ConfigWriters::ConfigWriter

Returns a configuration writer for a given source

Parameters:

  • source (Symbol)

    Source name (e.g., :wicked)

Returns:

  • (Y2Network::ConfigWriters::ConfigWriter)

See Also:

  • Y2Network::ConfigWriters::ConfigWriter


53
54
55
56
57
58
# File 'src/lib/y2network/config_writer.rb', line 53

def for(source)
  require "y2network/#{source}/config_writer"
  modname = source.to_s.split("_").map(&:capitalize).join
  klass = Y2Network.const_get("#{modname}::ConfigWriter")
  klass.new
end

Instance Method Details

#write(config, old_config = nil, only: nil) ⇒ IssuesResult

Writes the configuration into YaST network related modules

Parameters:

  • config (Y2Network::Config)

    Configuration to write

  • old_config (Y2Network::Config) (defaults to: nil)

    Old configuration

  • only (Array<symbol>, nil) (defaults to: nil)

    explicit sections to be written, by default if no parameter is given then all changes will be written

Returns:



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'src/lib/y2network/config_writer.rb', line 72

def write(config, old_config = nil, only: nil)
  sections = only || SECTIONS

  # TODO: Improve the loging using better format
  log.info "Writing configuration: #{config.inspect}\n"
  log.info "Old configuration: #{old_config.inspect}\n"

  log.info("Writing sections: #{sections.inspect}") if only

  issues_list = Y2Issues::List.new

  SECTIONS.each do |s|
    send(:"write_#{s}", config, old_config, issues_list) if sections.include?(s)
  end

  Yast::Host.Write(gui: false)

  IssuesResult.new(config, issues_list)
end