Class: Y2Network::ConnectionConfig::Base
- Inherits:
-
Object
- Object
- Y2Network::ConnectionConfig::Base
- 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 description (e.g., “Ethernet Card 0”).
-
#ethtool_options ⇒ String
Configuration for ethtools when initializing.
-
#firewall_zone ⇒ String
Assigned firewall zone to interface.
-
#hostname ⇒ String
Interface's hostname.
-
#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
-
#==(other) ⇒ Boolean
(also: #eql?)
Compares ConnectionConfigs.
-
#all_ips ⇒ Array<IPConfig>
Returns all IP configurations.
-
#find_master(configs) ⇒ ConnectionConfig::Bonding, ...
find master from given collection of configs nil in which this device in enslaved.
-
#initialize ⇒ Base
constructor
Constructor.
-
#propose ⇒ Object
Propose reasonable defaults for given config.
- #propose_startmode ⇒ Object
-
#type ⇒ InterfaceType
Returns the connection type.
-
#virtual? ⇒ Boolean
Whether a connection needs a virtual device associated or not.
Constructor Details
#initialize ⇒ Base
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
#bootproto ⇒ BootProtocol
Returns Bootproto.
51 52 53 |
# File 'src/lib/y2network/connection_config/base.rb', line 51 def bootproto @bootproto end |
#description ⇒ String
Returns Connection's description (e.g., “Ethernet Card 0”).
61 62 63 |
# File 'src/lib/y2network/connection_config/base.rb', line 61 def description @description end |
#ethtool_options ⇒ String
Returns configuration for ethtools when initializing.
65 66 67 |
# File 'src/lib/y2network/connection_config/base.rb', line 65 def @ethtool_options end |
#firewall_zone ⇒ String
Returns assigned firewall zone to interface.
67 68 69 |
# File 'src/lib/y2network/connection_config/base.rb', line 67 def firewall_zone @firewall_zone end |
#hostname ⇒ String
Returns interface's hostname.
69 70 71 |
# File 'src/lib/y2network/connection_config/base.rb', line 69 def hostname @hostname end |
#id ⇒ String (readonly)
Returns Connection identifier.
72 73 74 |
# File 'src/lib/y2network/connection_config/base.rb', line 72 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.
48 49 50 |
# File 'src/lib/y2network/connection_config/base.rb', line 48 def interface @interface end |
#ip ⇒ IPConfig
Returns Primary IP configuration.
53 54 55 |
# File 'src/lib/y2network/connection_config/base.rb', line 53 def ip @ip end |
#ip_aliases ⇒ Array<IPConfig>
Returns Additional IP configurations (also known as 'aliases').
55 56 57 |
# File 'src/lib/y2network/connection_config/base.rb', line 55 def ip_aliases @ip_aliases end |
#lladdress ⇒ String
Returns Link layer address.
63 64 65 |
# File 'src/lib/y2network/connection_config/base.rb', line 63 def lladdress @lladdress end |
#mtu ⇒ Integer?
57 58 59 |
# File 'src/lib/y2network/connection_config/base.rb', line 57 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.
43 44 45 |
# File 'src/lib/y2network/connection_config/base.rb', line 43 def name @name end |
#startmode ⇒ Startmode
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_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 |
#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 |
#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.
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_startmode ⇒ Object
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 |
#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 |