Class: Y2Network::VirtualizationConfig

Inherits:
Object
  • Object
show all
Includes:
Yast::Logger
Defined in:
src/lib/y2network/virtualization_config.rb

Overview

This class is responsible for creating a bridge configuration for virtualization from the interfaces that are connected and bridgeable.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ VirtualizationConfig

Constructor

Parameters:



34
35
36
# File 'src/lib/y2network/virtualization_config.rb', line 34

def initialize(config)
  @config = config
end

Instance Attribute Details

#configY2Network::Config (readonly)

Returns:



29
30
31
# File 'src/lib/y2network/virtualization_config.rb', line 29

def config
  @config
end

Instance Method Details

#bridgeable_candidatesArray<Y2Network::Interface]

Obtains the interfaces that are candidates for being bridgeable

Returns:



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

def bridgeable_candidates
  builder = Y2Network::InterfaceConfigBuilder.for("br")
  builder.name = config.interfaces.free_name("br")

  config.interfaces.select { |i| connected_and_bridgeable?(builder, i) }
end

#createBoolean

Iterates over the bridgeable candidates creating a bridge for each of them. The connection is copied to the bridge when exist and the interface is added as a bridge port

Returns:

  • (Boolean)

    true when a new bridge was created



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'src/lib/y2network/virtualization_config.rb', line 53

def create
  return false if bridgeable_candidates.empty?

  bridgeable_candidates.each do |interface|
    bridge_builder = bridge_builder_for(interface)

    connection = config.connections.by_name(interface.name)
    # The configuration of the connection being included is copied to the
    # bridge when exist
    bridge_builder.configure_from(connection) if connection

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

    # It adds the connection and the virtual interface
    bridge_builder.save

    # Move routes from the port member to the bridge (bsc#903889)
    move_routes(builder.name, bridge_builder.name)
  end

  true
end