Class: Y2Network::ProposalSettings

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

Overview

Class that stores the proposal settings for network during installation.

Constant Summary collapse

DEFAULTS =
[:ipv4_forward, :ipv6_forward].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProposalSettings

Constructor



43
44
45
46
47
48
49
50
51
52
53
54
# File 'src/lib/y2network/proposal_settings.rb', line 43

def initialize
  Yast.import "Arch"
  Yast.import "ProductFeatures"

  Yast.import "Package"
  Yast.import "PackagesProposal"
  Yast.import "Lan"

  @selected_backend = autoinst_backend
  @virt_bridge_proposal = autoinst_disabled_proposal? ? false : true
  @defaults_applied = false
end

Instance Attribute Details

#defaults_appliedObject

Returns the value of attribute defaults_applied.



38
39
40
# File 'src/lib/y2network/proposal_settings.rb', line 38

def defaults_applied
  @defaults_applied
end

#ipv4_forwardObject

Returns the value of attribute ipv4_forward.



36
37
38
# File 'src/lib/y2network/proposal_settings.rb', line 36

def ipv4_forward
  @ipv4_forward
end

#ipv6_forwardObject

Returns the value of attribute ipv6_forward.



37
38
39
# File 'src/lib/y2network/proposal_settings.rb', line 37

def ipv6_forward
  @ipv6_forward
end

#selected_backendBoolean

Returns network service to be used after the installation.

Returns:

  • (Boolean)

    network service to be used after the installation



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

def selected_backend
  @selected_backend
end

#virt_bridge_proposalObject

Returns the value of attribute virt_bridge_proposal.



35
36
37
# File 'src/lib/y2network/proposal_settings.rb', line 35

def virt_bridge_proposal
  @virt_bridge_proposal
end

Class Method Details

.create_instanceObject

Enforce a new clean instance



191
192
193
# File 'src/lib/y2network/proposal_settings.rb', line 191

def create_instance
  @instance = new
end

.instanceObject

Singleton instance



186
187
188
# File 'src/lib/y2network/proposal_settings.rb', line 186

def instance
  @instance ||= create_instance
end

Instance Method Details

#apply_defaultsObject

Modifies the current network configuration according to the proposal. It does not touch the network configuration if the proposal settings were already applied



66
67
68
69
70
71
72
73
74
# File 'src/lib/y2network/proposal_settings.rb', line 66

def apply_defaults
  return if defaults_applied
  return @defaults_applied = true if DEFAULTS.all? { |o| public_send(o).nil? }

  Yast::Lan.read_config(report: false) unless yast_config
  yast_config.routing.forward_ipv4 = ipv4_forward unless ipv4_forward.nil?
  yast_config.routing.forward_ipv6 = ipv6_forward unless ipv6_forward.nil?
  @defaults_applied = true
end

#current_backendObject



76
77
78
# File 'src/lib/y2network/proposal_settings.rb', line 76

def current_backend
  selected_backend || default_backend
end

#default_backendObject



80
81
82
83
84
# File 'src/lib/y2network/proposal_settings.rb', line 80

def default_backend
  default = use_network_manager? ? :network_manager : :wicked
  log.info "The default backend is: #{default}"
  default
end

#disable_network!Object



115
116
117
118
# File 'src/lib/y2network/proposal_settings.rb', line 115

def disable_network!
  log.info "Disabling all network services"
  self.selected_backend = :none
end

#enable_network_manager!Object

Adds the NetworkManager package to the Yast::PackagesProposal and sets NetworkManager as the backend to be used



97
98
99
100
101
102
103
# File 'src/lib/y2network/proposal_settings.rb', line 97

def enable_network_manager!
  log.info "Enabling NetworkManager"
  self.selected_backend = :network_manager
  refresh_packages

  selected_backend
end

#enable_wicked!Object

Add the wicked package to the Yast::PackagesProposal and sets wicked as the backend to be used



107
108
109
110
111
112
113
# File 'src/lib/y2network/proposal_settings.rb', line 107

def enable_wicked!
  log.info "Enabling Wicked"
  self.selected_backend = :wicked
  refresh_packages

  selected_backend
end

#modify_defaults(settings = network_section) ⇒ Object

Modifies the proposal according to the given settings

Parameters:

  • settings (Hash) (defaults to: network_section)

    network default settings to be loaded



59
60
61
62
# File 'src/lib/y2network/proposal_settings.rb', line 59

def modify_defaults(settings = network_section)
  load_features(settings)
  @defaults_applied = false
end

#network_manager_available?Boolean

Convenience method to obtain whether the NetworkManager package is available or not.

Returns:

  • (Boolean)

    false if no package available, true otherwise



138
139
140
141
142
143
144
145
146
# File 'src/lib/y2network/proposal_settings.rb', line 138

def network_manager_available?
  p = Y2Packager::Package.find("NetworkManager").first
  if p.nil?
    log.info("The NetworkManager package is not available")
    return false
  end
  log.info("The NetworkManager package status: #{p.status}")
  true
end

#network_serviceObject

Propose the network service to be use at the end of the installation depending on the backend selected during the proposal and the packages installed



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'src/lib/y2network/proposal_settings.rb', line 162

def network_service
  case current_backend
  when :network_manager
    return :network_manager if network_manager_installed?

    log.info("NetworkManager is the selected service but it is not installed")
    log.info("- using wicked")

    return :wicked
  when :wicked
    return :wicked if wicked_installed?

    return :none unless network_manager_installed?

    log.info("Wicked is the selected service but it is not installed - using Network Manager")

    return :network_manager
  end

  current_backend
end

#propose_bridge!(option) ⇒ Object



90
91
92
93
# File 'src/lib/y2network/proposal_settings.rb', line 90

def propose_bridge!(option)
  log.info("Bridge proposal set to: #{option.inspect}")
  @virt_bridge_proposal = option
end

#propose_bridge?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'src/lib/y2network/proposal_settings.rb', line 86

def propose_bridge?
  virtual_proposal_required? && virt_bridge_proposal
end

#refresh_packagesObject



120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'src/lib/y2network/proposal_settings.rb', line 120

def refresh_packages
  case current_backend
  when :network_manager
    Yast::PackagesProposal.AddResolvables("network", :package, ["NetworkManager"])
    Yast::PackagesProposal.RemoveResolvables("network", :package, ["wicked"])
  when :wicked
    Yast::PackagesProposal.AddResolvables("network", :package, ["wicked"])
    Yast::PackagesProposal.RemoveResolvables("network", :package, ["NetworkManager"])
  when :none
    Yast::PackagesProposal.RemoveResolvables("network", :package, ["NetworkManager"])
    Yast::PackagesProposal.RemoveResolvables("network", :package, ["wicked"])
  end
end

#virtual_proposal_required?Boolean

Decides if a proposal for virtualization host machine is required.

Returns:

  • (Boolean)


149
150
151
152
153
154
155
156
157
# File 'src/lib/y2network/proposal_settings.rb', line 149

def virtual_proposal_required?
  return false if Yast::Arch.s390

  return true if package_selected?("xen") && Yast::Arch.is_xen0
  return true if package_selected?("kvm")
  return true if package_selected?("qemu")

  false
end