Class: Y2Network::Driver

Inherits:
Object
  • Object
show all
Includes:
CanBeCopied, Yast2::Equatable
Defined in:
src/lib/y2network/driver.rb

Overview

This class represents a driver for an interface

It is composed of a kernel module name and a string representing the module options

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CanBeCopied

#copy

Constructor Details

#initialize(name, params = "") ⇒ Driver

Constructor

Parameters:

  • name (String)

    Driver name

  • params (String) (defaults to: "")

    Driver parameters (e.g., "csum=1 debug=16")



67
68
69
70
# File 'src/lib/y2network/driver.rb', line 67

def initialize(name, params = "")
  @name = name
  @params = params
end

Instance Attribute Details

#nameString

Returns Kernel module name.

Returns:

  • (String)

    Kernel module name



57
58
59
# File 'src/lib/y2network/driver.rb', line 57

def name
  @name
end

#paramsString

Returns Kernel module parameters.

Returns:

  • (String)

    Kernel module parameters



59
60
61
# File 'src/lib/y2network/driver.rb', line 59

def params
  @params
end

Class Method Details

.commitObject

Commits drivers options to disk



51
52
53
# File 'src/lib/y2network/driver.rb', line 51

def commit
  Yast::SCR.Write(Yast::Path.new(".modules"), nil)
end

.from_system(name) ⇒ Object

Returns a driver using the information from the system

Parameters:

  • name (String)

    Driver's name



36
37
38
39
40
# File 'src/lib/y2network/driver.rb', line 36

def from_system(name)
  params = Yast::SCR.Read(Yast::Path.new(".modules.options.#{name}"))
  params_string = params.map { |k, v| "#{k}=#{v}" }.join(" ")
  new(name, params_string)
end

.write_options(drivers) ⇒ Object

Writes driver options to the underlying system

Parameters:



45
46
47
48
# File 'src/lib/y2network/driver.rb', line 45

def write_options(drivers)
  drivers.each(&:write_options)
  commit
end

Instance Method Details

#write_optionsObject

Adds driver parameters to be written to the underlying system

Parameters are not written to disk until Y2Network::Driver.commit is called. The reason is that writing them is an expensive operation, so it is better to write parameters for all drivers at the same time.

You might prefer to use write_options instead.

See Also:



81
82
83
84
85
86
87
88
# File 'src/lib/y2network/driver.rb', line 81

def write_options
  parts = params.split(/ +/)
  params_hash = parts.each_with_object({}) do |param, hash|
    key, value = param.split("=")
    hash[key] = value.to_s
  end
  Yast::SCR.Write(Yast::Path.new(".modules.options.#{name}"), params_hash)
end