Skip to content

Commit

Permalink
Merge 2a181d1 into 91c1265
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Jul 31, 2019
2 parents 91c1265 + 2a181d1 commit 4a30e80
Show file tree
Hide file tree
Showing 43 changed files with 1,194 additions and 125 deletions.
15 changes: 12 additions & 3 deletions src/lib/y2network/connection_config/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ class Base
attr_accessor :interface
# @return [BootProtocol] Bootproto
attr_accessor :bootproto
# @return [Array<IPConfig>]
attr_accessor :ip_configs
# @return [IPConfig] Primary IP configuration
attr_accessor :ip
# @return [Array<IPConfig>] Additional IP configurations (also known as 'aliases')
attr_accessor :ip_aliases
# @return [Integer, nil]
attr_accessor :mtu
# @return [Startmode, nil]
Expand All @@ -53,7 +55,7 @@ class Base

# Constructor
def initialize
@ip_configs = []
@ip_aliases = []
@bootproto = BootProtocol::STATIC
@startmode = Startmode.create("manual")
end
Expand All @@ -75,6 +77,13 @@ def type
def virtual?
false
end

# Returns all IP configurations
#
# @return [Array<IPConfig>]
def all_ips
([ip] + ip_aliases).compact
end
end
end
end
2 changes: 1 addition & 1 deletion src/lib/y2network/connection_config/bonding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module ConnectionConfig
#
# @see https://www.kernel.org/doc/Documentation/networking/bonding.txt
class Bonding < Base
# @return [Array<Interface>]
# @return [Array<String>]
attr_accessor :slaves
# @return [String] bond driver options
attr_accessor :options
Expand Down
46 changes: 46 additions & 0 deletions src/lib/y2network/connection_config/bridge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (c) [2019] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "y2network/connection_config/base"

module Y2Network
module ConnectionConfig
# Configuration for bridge connections
#
# @see https://www.kernel.org/doc/Documentation/networking/bridge.txt
class Bridge < Base
# @return [Array<String>]
attr_accessor :ports
# @return [Boolean] whether spanning tree protocol is enabled or not
attr_accessor :stp
# @return [Integer]
attr_accessor :forward_delay

def initialize
@ports = []
@stp = false
@forward_delay = 0
end

def virtual?
true
end
end
end
end
41 changes: 41 additions & 0 deletions src/lib/y2network/connection_config/tap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) [2019] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "y2network/connection_config/base"

module Y2Network
module ConnectionConfig
# Configuration for TAP connections
class Tap < Base
# @return [String] tunnel owner (name or UID)
attr_accessor :owner
# @return [String] tunnel group (name or GID)
attr_accessor :group

def initialize
@owner = ""
@group = ""
end

def virtual?
true
end
end
end
end
41 changes: 41 additions & 0 deletions src/lib/y2network/connection_config/tun.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) [2019] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "y2network/connection_config/base"

module Y2Network
module ConnectionConfig
# Configuration for TUN connections
class Tun < Base
# @return [String] tunnel owner (name or UID)
attr_accessor :owner
# @return [String] tunnel group (name or GID)
attr_accessor :group

def initialize
@owner = ""
@group = ""
end

def virtual?
true
end
end
end
end
31 changes: 10 additions & 21 deletions src/lib/y2network/interface_config_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def aliases
}
end

new_aliases = @connection_config.ip_configs.select { |c| c.id != "" }.map do |data|
new_aliases = @connection_config.ip_aliases.map do |data|
{
label: data.label,
ip: data.address.address,
Expand All @@ -269,17 +269,15 @@ def aliases
def aliases=(value)
@aliases = value

# connection config
# keep only default as aliases does not handle default ip config
@connection_config.ip_configs.delete_if { |c| c.id != "" }
@connection_config.ip_aliases.clear
value.each_with_index do |h, i|
ip_addr = IPAddress.from_string(h[:ip])
if h[:prefixlen] && !h[:prefixlen].empty?
ip_addr.prefix = h[:prefixlen].delete("/").to_i
elsif h[:mask] && !h[:mask].empty?
ip.netmask = h[:mask]
end
@connection_config.ip_configs << ConnectionConfig::IPConfig.new(
@connection_config.ip_aliases << ConnectionConfig::IPConfig.new(
ip_addr,
label: h[:label],
id: "_#{i}" # TODO: remember original prefixes
Expand Down Expand Up @@ -308,8 +306,7 @@ def ethtool_options=(value)
def ip_address
old = @config["IPADDR"]

# FIXME: workaround to remove when primary ip config is separated from the rest
default = (@connection_config.ip_configs || []).find { |c| c.id == "" }
default = @connection_config.ip
new_ = if default
default.address.address
else
Expand All @@ -321,11 +318,8 @@ def ip_address
# @param [String] value
def ip_address=(value)
@config["IPADDR"] = value

# connection_config
if value.nil? || value.empty?
# in such case remove default config
@connection_config.ip_configs.delete_if { |c| c.id == "" }
@connection_config.ip = nil
else
ip_config_default.address.address = value
end
Expand All @@ -338,9 +332,8 @@ def subnet_prefix
else
@config["NETMASK"] || ""
end
default = (@connection_config.ip_configs || []).find { |c| c.id == "" }
new_ = if default
"/" + default.address.prefix.to_s
new_ = if @connection_config.ip
"/" + @connection_config.ip.address.prefix.to_s
else
""
end
Expand Down Expand Up @@ -384,7 +377,7 @@ def hostname=(value)
# @return [String]
def remote_ip
old = @config["REMOTEIP"]
default = @connection_config.ip_configs.find { |c| c.id == "" }
default = @connection_config.ip
new_ = if default
default.remote_address.to_s
else
Expand Down Expand Up @@ -576,12 +569,8 @@ def save_aliases
end

def ip_config_default
default = @connection_config.ip_configs.find { |c| c.id == "" }
if !default
default = ConnectionConfig::IPConfig.new(IPAddress.new("0.0.0.0")) # fake ip as it will be replaced soon
@connection_config.ip_configs << default
end
default
return @connection_config.ip if @connection_config.ip
@connection_config.ip = ConnectionConfig::IPConfig.new(IPAddress.new("0.0.0.0"))
end

# method that allows easy change of backend for providing data
Expand Down
9 changes: 4 additions & 5 deletions src/lib/y2network/sysconfig/connection_config_readers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def connection_config
conn.bootproto = BootProtocol.from_name(file.bootproto || "static")
conn.description = file.name
conn.interface = file.interface
conn.ip_configs = ip_configs
conn.ip = all_ips.find { |i| i.id.empty? }
conn.ip_aliases = all_ips.reject { |i| i.id.empty? }
conn.name = file.interface
conn.startmode = Startmode.create(file.startmode || "manual")
conn.startmode.priority = file.ifplugd_priority if conn.startmode.name == "ifplugd"
Expand Down Expand Up @@ -81,8 +82,8 @@ def update_connection_config(_conn)
#
# @return [Array<Y2Network::ConnectionConfig::IPAdress>] IP addresses configuration
# @see Y2Network::ConnectionConfig::IPConfig
def ip_configs
configs = file.ipaddrs.map do |id, ip|
def all_ips
@all_ips ||= file.ipaddrs.map do |id, ip|
next unless ip.is_a?(Y2Network::IPAddress)
ip_address = build_ip(ip, file.prefixlens[id], file.netmasks[id])
Y2Network::ConnectionConfig::IPConfig.new(
Expand All @@ -93,8 +94,6 @@ def ip_configs
broadcast: file.broadcasts[id]
)
end
# The one without suffix comes first.
configs.compact.sort_by { |c| c.id.nil? ? -1 : 0 }
end

# Builds an IP address
Expand Down
45 changes: 45 additions & 0 deletions src/lib/y2network/sysconfig/connection_config_readers/bonding.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (c) [2019] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "y2network/sysconfig/connection_config_readers/base"

module Y2Network
module Sysconfig
module ConnectionConfigReaders
# This class is able to build a ConnectionConfig::Bonding object given a
# SysconfigInterfaceFile object.
class Bonding < Base
private

# @see Y2Network::Sysconfig::ConnectionConfigReaders::Base#update_connection_config
def update_connection_config(conn)
conn.slaves = slaves
conn.options = file.bonding_module_opts
end

# Convenience method to obtain the bonding slaves defined in the file
#
# @return [Array<String>] bonding slaves defined in the file
def slaves
(file.bonding_slaves || {}).values
end
end
end
end
end
39 changes: 39 additions & 0 deletions src/lib/y2network/sysconfig/connection_config_readers/bridge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (c) [2019] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "y2network/sysconfig/connection_config_readers/base"

module Y2Network
module Sysconfig
module ConnectionConfigReaders
# This class is able to build a ConnectionConfig::Bridge object given a
# SysconfigInterfaceFile object.
class Bridge < Base
private

# @see Y2Network::Sysconfig::ConnectionConfigReaders::Base#update_connection_config
def update_connection_config(conn)
conn.ports = file.bridge_ports.split(" ")
conn.stp = file.bridge_stp
conn.forward_delay = file.bridge_forwarddelay
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module ConnectionConfigReaders
class Infiniband < Base
private

# @param conn [Y2Network::ConnectionConfig::Infiniband]
# @see Y2Network::Sysconfig::ConnectionConfigReaders::Base#update_connection_config
def update_connection_config(conn)
conn.ipoib_mode = IpoibMode.from_name(file.ipoib_mode.to_s)
Expand Down
Loading

0 comments on commit 4a30e80

Please sign in to comment.