Class: Y2Network::Interface

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

Overview

Network interface.

It represents network interfaces, no matter whether they are physical or virtual ones. This class (including its subclasses) are basically responsible for holding the hardware configuration (see Hwinfo), including naming and driver information.

Logical configuration, like TCP/IP or WIFI settings, are handled through ConnectionConfig::Base classes. Actually, relationships with other interfaces (like bonding slaves) are kept in those configuration objects too.

Direct Known Subclasses

PhysicalInterface, VirtualInterface

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type: InterfaceType::ETHERNET) ⇒ Interface

Constructor

Parameters:

  • name (String)

    Interface name (e.g., "eth0")

  • type (InterfaceType) (defaults to: InterfaceType::ETHERNET)

    Interface type


70
71
72
73
74
75
76
# File 'src/lib/y2network/interface.rb', line 70

def initialize(name, type: InterfaceType::ETHERNET)
  @name = name
  @description = ""
  @type = type  # TODO: move renaming logic to physical interfaces only

  @renaming_mechanism = :none
end

Instance Attribute Details

#descriptionString

Returns Interface description.

Returns:

  • (String)

    Interface description


42
43
44
# File 'src/lib/y2network/interface.rb', line 42

def description
  @description
end

#hardwareHwInfo (readonly)

Returns:

  • (HwInfo)

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

def hardware
  @hardware
end

#nameString

Returns Device name ('eth0', 'wlan0', etc.).

Returns:

  • (String)

    Device name ('eth0', 'wlan0', etc.)


40
41
42
# File 'src/lib/y2network/interface.rb', line 40

def name
  @name
end

#old_nameString? (readonly)

Returns:

  • (String, nil)

50
51
52
# File 'src/lib/y2network/interface.rb', line 50

def old_name
  @old_name
end

#renaming_mechanismSymbol

Returns Mechanism to rename the interface (:none -no rename-, :bus_id or :mac).

Returns:

  • (Symbol)

    Mechanism to rename the interface (:none -no rename-, :bus_id or :mac)


48
49
50
# File 'src/lib/y2network/interface.rb', line 48

def renaming_mechanism
  @renaming_mechanism
end

#typeInterfaceType

Returns Interface type.

Returns:


44
45
46
# File 'src/lib/y2network/interface.rb', line 44

def type
  @type
end

Class Method Details

.from_connection(conn) ⇒ Object

Builds an interface based on a connection

Parameters:

  • conn (ConnectionConfig)

    Connection configuration related to the network interface


56
57
58
59
60
61
62
63
# File 'src/lib/y2network/interface.rb', line 56

def from_connection(conn)
  # require here to avoid circular dependency
  require "y2network/physical_interface"
  require "y2network/virtual_interface"

  interface_class = conn.virtual? ? VirtualInterface : PhysicalInterface
  interface_class.new(conn.interface || conn.name, type: conn.type)
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Determines whether two interfaces are equal

Parameters:

  • other (Interface)

    Interface to compare with

Returns:

  • (Boolean)

82
83
84
85
# File 'src/lib/y2network/interface.rb', line 82

def ==(other)
  return false unless other.is_a?(Interface)
  name == other.name
end

#configHash<String, String>

Complete configuration of the interface

Returns:

  • (Hash<String, String>)

    option, value hash map


94
95
96
# File 'src/lib/y2network/interface.rb', line 94

def config
  system_config(name)
end

#driversArray<Driver>

Returns the list of kernel modules

Returns:

See Also:


102
103
104
# File 'src/lib/y2network/interface.rb', line 102

def drivers
  hardware.drivers
end

#rename(new_name, mechanism) ⇒ Object

Renames the interface

Parameters:

  • new_name (String)

    New interface's name

  • mechanism (Symbol)

    Property to base the rename on (:mac or :bus_id)


110
111
112
113
114
115
# File 'src/lib/y2network/interface.rb', line 110

def rename(new_name, mechanism)
  log.info "Rename interface '#{name}' to '#{new_name}' using the '#{mechanism}'"
  @old_name = name if name != new_name # same name, just set different mechanism
  @name = new_name
  @renaming_mechanism = mechanism
end