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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProposalSettings

Constructor


35
36
37
38
39
40
41
42
# File 'src/lib/y2network/proposal_settings.rb', line 35

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

  @selected_backend = nil
end

Instance Attribute Details

#selected_backendBoolean


32
33
34
# File 'src/lib/y2network/proposal_settings.rb', line 32

def selected_backend
  @selected_backend
end

Class Method Details

.create_instanceObject

Enforce a new clean instance


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

def create_instance
  @instance = new
end

.instanceObject

Singleton instance


112
113
114
# File 'src/lib/y2network/proposal_settings.rb', line 112

def instance
  @instance ||= create_instance
end

Instance Method Details

#current_backendObject


44
45
46
# File 'src/lib/y2network/proposal_settings.rb', line 44

def current_backend
  selected_backend || default_backend
end

#default_backendObject


48
49
50
51
52
# File 'src/lib/y2network/proposal_settings.rb', line 48

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

#enable_network_manager!Object

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


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

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


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

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

  selected_backend
end

#network_manager_available?Boolean

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


88
89
90
91
92
93
94
95
96
# File 'src/lib/y2network/proposal_settings.rb', line 88

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


101
102
103
104
105
106
107
108
# File 'src/lib/y2network/proposal_settings.rb', line 101

def network_service
  case current_backend
  when :network_manager
    network_manager_installed? ? :network_manager : :wicked
  else
    :wicked
  end
end

#refresh_packagesObject


74
75
76
77
78
79
80
81
82
# File 'src/lib/y2network/proposal_settings.rb', line 74

def refresh_packages
  if current_backend == :network_manager
    Yast::PackagesProposal.AddResolvables("network", :package, ["NetworkManager"])
    Yast::PackagesProposal.RemoveResolvables("network", :package, ["wicked"])
  else
    Yast::PackagesProposal.AddResolvables("network", :package, ["wicked"])
    Yast::PackagesProposal.RemoveResolvables("network", :package, ["NetworkManager"])
  end
end