Class: Y2Network::ConnectionConfig::Base

Inherits:
Object
  • Object
show all
Includes:
Yast2::Equatable, Yast::Logger
Defined in:
src/lib/y2network/connection_config/base.rb

Overview

This class is reponsible of a connection configuration

It holds a configuration (IP addresses, MTU, WIFI settings, etc.) that can be applied to an interface. By comparison, it is the equivalent of the "Connection" concept in NetworkManager. When it comes to sysconfig, a "ConnectionConfig" is defined using a "ifcfg-*" file.

Additionally, each connection config gets an internal ID which makes easier to track changes between two different Y2Network::Config objects. When they are copied, the same IDs are kept, so it is easy to find out which connections have been added, removed or simply changed.

Direct Known Subclasses

Bonding, Bridge, Ctc, Dummy, Ethernet, Hsi, Infiniband, Lcs, Qeth, Tap, Tun, Usb, Vlan, Wireless

Constant Summary collapse

PROPOSED_PPPOE_MTU =

suggested value for PPPoE

1492
@@last_id =

Returns Connection identifier counter.

Returns:

  • (Integer)

    Connection identifier counter

0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Constructor



89
90
91
92
93
94
95
96
97
98
99
# File 'src/lib/y2network/connection_config/base.rb', line 89

def initialize
  @id = @@last_id += 1
  @ip_aliases = []
  # TODO: maybe do test query if physical interface is attached to proposal?
  @bootproto = BootProtocol::STATIC
  @ip = IPConfig.new(IPAddress.from_string("0.0.0.0/32"))
  @startmode = Startmode.create("manual")
  @ethtool_options = ""
  @firewall_zone = ""
  @hostnames = []
end

Instance Attribute Details

#bootprotoBootProtocol

Returns Bootproto.

Returns:



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

def bootproto
  @bootproto
end

#descriptionString?

Returns Connection's custom description (e.g., "Ethernet Card 0").

Returns:

  • (String, nil)

    Connection's custom description (e.g., "Ethernet Card 0")



69
70
71
# File 'src/lib/y2network/connection_config/base.rb', line 69

def description
  @description
end

#dhclient_set_hostnameBoolean?

Returns set to true if dhcp from this interface sets machine hostname, false if not and nil if not specified.

Returns:

  • (Boolean, nil)

    set to true if dhcp from this interface sets machine hostname, false if not and nil if not specified



80
81
82
# File 'src/lib/y2network/connection_config/base.rb', line 80

def dhclient_set_hostname
  @dhclient_set_hostname
end

#ethtool_optionsString

Returns configuration for ethtools when initializing.

Returns:

  • (String)

    configuration for ethtools when initializing



73
74
75
# File 'src/lib/y2network/connection_config/base.rb', line 73

def ethtool_options
  @ethtool_options
end

#firewall_zoneString

Returns assigned firewall zone to interface.

Returns:

  • (String)

    assigned firewall zone to interface



75
76
77
# File 'src/lib/y2network/connection_config/base.rb', line 75

def firewall_zone
  @firewall_zone
end

#hostnamesArray<String>

Returns interface's hostnames.

Returns:

  • (Array<String>)

    interface's hostnames



77
78
79
# File 'src/lib/y2network/connection_config/base.rb', line 77

def hostnames
  @hostnames
end

#idString (readonly)

Returns Connection identifier.

Returns:

  • (String)

    Connection identifier



83
84
85
# File 'src/lib/y2network/connection_config/base.rb', line 83

def id
  @id
end

#interfaceString?

FIXME: Maybe in the future it could be a matcher. By now we will use the interface's name.

Returns:

  • (String, nil)

    Interface to apply the configuration to



56
57
58
# File 'src/lib/y2network/connection_config/base.rb', line 56

def interface
  @interface
end

#ipIPConfig?

Returns Primary IP configuration.

Returns:

  • (IPConfig, nil)

    Primary IP configuration



61
62
63
# File 'src/lib/y2network/connection_config/base.rb', line 61

def ip
  @ip
end

#ip_aliasesArray<IPConfig>

Returns Additional IP configurations (also known as 'aliases').

Returns:

  • (Array<IPConfig>)

    Additional IP configurations (also known as 'aliases')



63
64
65
# File 'src/lib/y2network/connection_config/base.rb', line 63

def ip_aliases
  @ip_aliases
end

#lladdressString

Returns Link layer address.

Returns:

  • (String)

    Link layer address



71
72
73
# File 'src/lib/y2network/connection_config/base.rb', line 71

def lladdress
  @lladdress
end

#mtuInteger?

Returns:

  • (Integer, nil)


65
66
67
# File 'src/lib/y2network/connection_config/base.rb', line 65

def mtu
  @mtu
end

#nameString

A connection could belongs to a specific interface or not. In case of no specific interface then it could be activated by the first available device.

Returns:

  • (String)

    Connection name



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

def name
  @name
end

#startmodeStartmode

Returns:



67
68
69
# File 'src/lib/y2network/connection_config/base.rb', line 67

def startmode
  @startmode
end

Instance Method Details

#all_ipsArray<IPConfig>

Returns all IP configurations

Returns:



165
166
167
# File 'src/lib/y2network/connection_config/base.rb', line 165

def all_ips
  ([ip] + ip_aliases).compact
end

#dhcp?Boolean

Return whether the connection is configured using the dhcp protocol or not

Returns:

  • (Boolean)

    true when using dhcp; false otherwise



183
184
185
# File 'src/lib/y2network/connection_config/base.rb', line 183

def dhcp?
  bootproto ? bootproto.dhcp? : false
end

#find_parent(configs) ⇒ ConnectionConfig::Bonding, ...

find parent from given collection of configs nil in which this device in included

Parameters:

Returns:



173
174
175
176
177
178
# File 'src/lib/y2network/connection_config/base.rb', line 173

def find_parent(configs)
  configs.find do |config|
    # TODO: what about VLAN?
    config.ports.include?(name) if config.type.bonding? || config.type.bridge?
  end
end

#hostnameString?

Return the first hostname associated with the primary IP address.

Returns:

  • (String, nil)

    returns the hostname associated with the primary IP address or nil



199
200
201
# File 'src/lib/y2network/connection_config/base.rb', line 199

def hostname
  hostnames&.first
end

#hostname=(hname) ⇒ Object

Convenience method in order to modify the canonical hostname mapped to the primary IP address.

Parameters:

  • hname (String, nil)

    hostnamme mapped to the primary IP address



207
208
209
210
211
212
# File 'src/lib/y2network/connection_config/base.rb', line 207

def hostname=(hname)
  short_name = hname&.split(".")&.first

  @hostnames = [hname, short_name].uniq.compact
  log.info("Assigned hostnames #{@hostnames.inspect} to connection #{name}")
end

#proposeObject

Note:

difference between constructor and propose is that initialize should set simple defaults and propose have more tricky config that depends on env, product, etc.

Propose reasonable defaults for given config. Useful for newly created devices.



109
110
111
112
# File 'src/lib/y2network/connection_config/base.rb', line 109

def propose
  propose_startmode
  self.mtu = PROPOSED_PPPOE_MTU if Yast::Arch.s390 && type.lcs?
end

#propose_startmodeObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'src/lib/y2network/connection_config/base.rb', line 114

def propose_startmode
  Yast.import "ProductFeatures"

  if root_filesystem_in_network?
    log.info "startmode nfsroot"
    @startmode = Startmode.create("nfsroot")
    return
  end

  product_startmode = Yast::ProductFeatures.GetStringFeature(
    "network",
    "startmode"
  )

  startmode = case product_startmode
  when "ifplugd"
    if replace_ifplugd?
      hotplug_interface? ? "hotplug" : "auto"
    else
      product_startmode
    end
  when "auto"
    "auto"
  else
    hotplug_interface? ? "hotplug" : "auto"
  end

  @startmode = Startmode.create(startmode)
end

#static?Boolean

Return whether the connection is configured using a fixed IPADDR

Returns:

  • (Boolean)

    true when static protocol is used or not defined bootpro; false otherwise



191
192
193
# File 'src/lib/y2network/connection_config/base.rb', line 191

def static?
  bootproto ? bootproto.static? : true
end

#typeInterfaceType

Returns the connection type

Any subclass could define this method is the default logic does not match.

Returns:



150
151
152
153
# File 'src/lib/y2network/connection_config/base.rb', line 150

def type
  const_name = self.class.name.split("::").last.upcase
  InterfaceType.const_get(const_name)
end

#virtual?Boolean

Whether a connection needs a virtual device associated or not.

Returns:

  • (Boolean)


158
159
160
# File 'src/lib/y2network/connection_config/base.rb', line 158

def virtual?
  false
end