Class: Y2Network::ConnectionConfig::Base

Inherits:
Object
  • Object
show all
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 =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Constructor


78
79
80
81
82
83
84
85
86
87
# File 'src/lib/y2network/connection_config/base.rb', line 78

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

Instance Attribute Details

#bootprotoBootProtocol


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

def bootproto
  @bootproto
end

#descriptionString


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

def description
  @description
end

#ethtool_optionsString


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

def ethtool_options
  @ethtool_options
end

#firewall_zoneString


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

def firewall_zone
  @firewall_zone
end

#hostnameString


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

def hostname
  @hostname
end

#idString (readonly)


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

def id
  @id
end

#interfaceString?

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


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

def interface
  @interface
end

#ipIPConfig


53
54
55
# File 'src/lib/y2network/connection_config/base.rb', line 53

def ip
  @ip
end

#ip_aliasesArray<IPConfig>


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

def ip_aliases
  @ip_aliases
end

#lladdressString


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

def lladdress
  @lladdress
end

#mtuInteger?


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

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.


43
44
45
# File 'src/lib/y2network/connection_config/base.rb', line 43

def name
  @name
end

#startmodeStartmode


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

def startmode
  @startmode
end

Instance Method Details

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

Compares ConnectionConfigs


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

def ==(other)
  return false if self.class != other.class
  [:name, :interface, :bootproto, :ip, :ip_aliases, :mtu, :startmode,
   :description, :lladdress, :ethtool_options, :firewall_zone, :hostname].all? do |method|
    public_send(method) == other.public_send(method)
  end
end

#all_ipsArray<IPConfig>

Returns all IP configurations


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

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

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

find master from given collection of configs nil in which this device in enslaved


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

def find_master(configs)
  configs.find do |config|
    # TODO: what about VLAN?
    if config.type.bonding?
      config.slaves.include?(name)
    elsif config.type.bridge?
      config.ports.include?(name)
    end
  end
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.


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

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

#propose_startmodeObject


113
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 113

def propose_startmode
  Yast.import "ProductFeatures"
  # see bsc#176804
  devicegraph = Y2Storage::StorageManager.instance.staging
  if devicegraph.filesystem_in_network?("/")
    @startmode = Startmode.create("nfsroot")
    log.info "startmode 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

#typeInterfaceType

Returns the connection type

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


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.


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

def virtual?
  false
end