Class: Y2Network::ConnectionConfig::Base
- Inherits:
-
Object
- Object
- Y2Network::ConnectionConfig::Base
- 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.
0
Instance Attribute Summary collapse
-
#bootproto ⇒ BootProtocol
Bootproto.
-
#description ⇒ String?
Connection's custom description (e.g., "Ethernet Card 0").
-
#dhclient_set_hostname ⇒ Boolean?
Set to true if dhcp from this interface sets machine hostname, false if not and nil if not specified.
-
#ethtool_options ⇒ String
Configuration for ethtools when initializing.
-
#firewall_zone ⇒ String
Assigned firewall zone to interface.
-
#hostnames ⇒ Array<String>
Interface's hostnames.
-
#id ⇒ String
readonly
Connection identifier.
-
#interface ⇒ String?
FIXME: Maybe in the future it could be a matcher.
-
#ip ⇒ IPConfig?
Primary IP configuration.
-
#ip_aliases ⇒ Array<IPConfig>
Additional IP configurations (also known as 'aliases').
-
#lladdress ⇒ String
Link layer address.
- #mtu ⇒ Integer?
-
#name ⇒ String
A connection could belongs to a specific interface or not.
- #startmode ⇒ Startmode
Instance Method Summary collapse
-
#all_ips ⇒ Array<IPConfig>
Returns all IP configurations.
-
#dhcp? ⇒ Boolean
Return whether the connection is configured using the dhcp protocol or not.
-
#find_parent(configs) ⇒ ConnectionConfig::Bonding, ...
find parent from given collection of configs nil in which this device in included.
-
#hostname ⇒ String?
Return the first hostname associated with the primary IP address.
-
#hostname=(hname) ⇒ Object
Convenience method in order to modify the canonical hostname mapped to the primary IP address.
-
#initialize ⇒ Base
constructor
Constructor.
-
#propose ⇒ Object
Propose reasonable defaults for given config.
- #propose_startmode ⇒ Object
-
#static? ⇒ Boolean
Return whether the connection is configured using a fixed IPADDR.
-
#type ⇒ InterfaceType
Returns the connection type.
-
#virtual? ⇒ Boolean
Whether a connection needs a virtual device associated or not.
Constructor Details
#initialize ⇒ Base
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
#bootproto ⇒ BootProtocol
Returns Bootproto.
59 60 61 |
# File 'src/lib/y2network/connection_config/base.rb', line 59 def bootproto @bootproto end |
#description ⇒ String?
Returns 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_hostname ⇒ Boolean?
Returns 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_options ⇒ String
Returns configuration for ethtools when initializing.
73 74 75 |
# File 'src/lib/y2network/connection_config/base.rb', line 73 def @ethtool_options end |
#firewall_zone ⇒ String
Returns assigned firewall zone to interface.
75 76 77 |
# File 'src/lib/y2network/connection_config/base.rb', line 75 def firewall_zone @firewall_zone end |
#hostnames ⇒ Array<String>
Returns interface's hostnames.
77 78 79 |
# File 'src/lib/y2network/connection_config/base.rb', line 77 def hostnames @hostnames end |
#id ⇒ String (readonly)
Returns Connection identifier.
83 84 85 |
# File 'src/lib/y2network/connection_config/base.rb', line 83 def id @id end |
#interface ⇒ String?
FIXME: Maybe in the future it could be a matcher. By now we will use the interface's name.
56 57 58 |
# File 'src/lib/y2network/connection_config/base.rb', line 56 def interface @interface end |
#ip ⇒ IPConfig?
Returns Primary IP configuration.
61 62 63 |
# File 'src/lib/y2network/connection_config/base.rb', line 61 def ip @ip end |
#ip_aliases ⇒ Array<IPConfig>
Returns 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 |
#lladdress ⇒ String
Returns Link layer address.
71 72 73 |
# File 'src/lib/y2network/connection_config/base.rb', line 71 def lladdress @lladdress end |
#mtu ⇒ Integer?
65 66 67 |
# File 'src/lib/y2network/connection_config/base.rb', line 65 def mtu @mtu end |
#name ⇒ String
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.
51 52 53 |
# File 'src/lib/y2network/connection_config/base.rb', line 51 def name @name end |
#startmode ⇒ Startmode
67 68 69 |
# File 'src/lib/y2network/connection_config/base.rb', line 67 def startmode @startmode end |
Instance Method Details
#all_ips ⇒ Array<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 |
#dhcp? ⇒ Boolean
Return whether the connection is configured using the dhcp protocol or not
187 188 189 |
# File 'src/lib/y2network/connection_config/base.rb', line 187 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
173 174 175 176 177 178 179 180 181 182 |
# File 'src/lib/y2network/connection_config/base.rb', line 173 def find_parent(configs) configs.find do |config| # TODO: what about VLAN? if config.type.bonding? config.ports.include?(name) elsif config.type.bridge? config.ports.include?(name) end end end |
#hostname ⇒ String?
Return the first hostname associated with the primary IP address.
203 204 205 |
# File 'src/lib/y2network/connection_config/base.rb', line 203 def hostname hostnames&.first end |
#hostname=(hname) ⇒ Object
Convenience method in order to modify the canonical hostname mapped to the primary IP address.
211 212 213 214 215 216 |
# File 'src/lib/y2network/connection_config/base.rb', line 211 def hostname=(hname) short_name = hname&.split(".")&.first @hostnames = [hname, short_name].uniq.compact log.info("Assigned hostnames #{@hostnames.inspect} to connection #{name}") end |
#propose ⇒ Object
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_startmode ⇒ Object
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
195 196 197 |
# File 'src/lib/y2network/connection_config/base.rb', line 195 def static? bootproto ? bootproto.static? : true end |
#type ⇒ InterfaceType
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 |