Class: Y2Network::InterfaceConfigBuilders::Bridge

Inherits:
Y2Network::InterfaceConfigBuilder show all
Extended by:
Forwardable
Includes:
Yast::Logger
Defined in:
src/lib/y2network/interface_config_builders/bridge.rb

Constant Summary

Constants inherited from Y2Network::InterfaceConfigBuilder

Y2Network::InterfaceConfigBuilder::NEW_DEVICES_COUNT

Instance Attribute Summary

Attributes inherited from Y2Network::InterfaceConfigBuilder

#connection_config, #firewall_zone, #interface, #name, #newly_added, #renaming_mechanism, #type

Instance Method Summary collapse

Methods inherited from Y2Network::InterfaceConfigBuilder

#alias_for, #aliases, #aliases=, #boot_protocol, #boot_protocol=, #configure_as_port, #driver, #driver=, #drivers, for, #hostname, #hostname=, #hwinfo, #hwinfo_from, #ifplugd_priority, #ifplugd_priority=, #ip_address, #ip_address=, #mtu, #mtu=, #name_exists?, #name_valid_characters, #newly_added?, #proposed_names, #remote_ip, #remote_ip=, #rename_interface, #renamed_interface?, #startmode=, #subnet_prefix, #subnet_prefix=, #valid_name?

Constructor Details

#initialize(config: nil) ⇒ Bridge

Returns a new instance of Bridge.



31
32
33
# File 'src/lib/y2network/interface_config_builders/bridge.rb', line 31

def initialize(config: nil)
  super(type: InterfaceType::BRIDGE, config: config)
end

Instance Method Details

#bridgeable_interfacesArray<Interface>

Returns list of interfaces usable in the bridge.

Returns:

  • (Array<Interface>)

    list of interfaces usable in the bridge



50
51
52
# File 'src/lib/y2network/interface_config_builders/bridge.rb', line 50

def bridgeable_interfaces
  interfaces.select { |i| bridgeable?(i) }
end

#configure_from(connection) ⇒ Object



71
72
73
74
75
76
# File 'src/lib/y2network/interface_config_builders/bridge.rb', line 71

def configure_from(connection)
  [:bootproto, :ip, :ip_aliases, :startmode, :description,
   :firewall_zone, :hostnames].all? do |method|
    @connection_config.public_send("#{method}=", connection.public_send(method))
  end
end

#require_adaptation?(devices) ⇒ Boolean

Returns whether any configuration of the given devices needs to be adapted in order to be added as a bridge port

Parameters:

  • devices (Array<String>)

    devices to check

Returns:

  • (Boolean)

    true if there is a device config that needs to be adaptated; false otherwise



41
42
43
44
45
46
47
# File 'src/lib/y2network/interface_config_builders/bridge.rb', line 41

def require_adaptation?(devices)
  devices.any? do |device|
    next false unless yast_config.configured_interface?(device)

    yast_config.connections.by_name(device).bootproto.name != "none"
  end
end

#saveObject

additionally it adapts ports if needed



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'src/lib/y2network/interface_config_builders/bridge.rb', line 55

def save
  ports.each do |port|
    interface = yast_config.interfaces.by_name(port)

    connection = yast_config.connections.by_name(port)
    next if connection && connection.startmode.name == "none"

    builder = InterfaceConfigBuilder.for(interface.type, config: connection)
    builder.name = interface.name
    builder.configure_as_port
    builder.save
  end

  super
end