Class: DInstaller::Storage::Proposal

Inherits:
Object
  • Object
show all
Defined in:
lib/dinstaller/storage/proposal.rb

Overview

Backend class to calculate a storage proposal

Defined Under Namespace

Classes: NoProposalError

Instance Method Summary collapse

Constructor Details

#initialize(logger, config) ⇒ Proposal

Constructor

Parameters:

  • logger (Logger)
  • config (Config)


37
38
39
40
41
# File 'lib/dinstaller/storage/proposal.rb', line 37

def initialize(logger, config)
  @logger = logger
  @config = config
  @listeners = []
end

Instance Method Details

#actionsStorage::Actions

Storage actions manager

Returns:



124
125
126
127
# File 'lib/dinstaller/storage/proposal.rb', line 124

def actions
  # FIXME: this class could receive the storage manager instance
  @actions ||= Actions.new(logger)
end

#add_on_change_listener(&block) ⇒ Object



43
44
45
# File 'lib/dinstaller/storage/proposal.rb', line 43

def add_on_change_listener(&block)
  @listeners << block
end

#available_devicesArray<Y2Storage::Device>

Available devices for installation

Returns:

  • (Array<Y2Storage::Device>)


54
55
56
# File 'lib/dinstaller/storage/proposal.rb', line 54

def available_devices
  disk_analyzer.candidate_disks
end

#calculate(settings = {}) ⇒ Boolean

Calculates a new proposal

Parameters:

  • settings (Hash) (defaults to: {})

    settings to calculate the proposal (e.g., { “use_lvm” => true, “candidate_devices” => [“/dev/sda”]}). Note that keys should match with a public setter.

Returns:

  • (Boolean)

    whether the proposal was correctly calculated



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/dinstaller/storage/proposal.rb', line 105

def calculate(settings = {})
  proposal_settings = generate_proposal_settings(settings)

  @proposal = Y2Storage::GuidedProposal.initial(
    settings:      proposal_settings,
    devicegraph:   probed_devicegraph,
    disk_analyzer: disk_analyzer
  )
  save
  changed!

  !proposal.failed?
end

#candidate_devicesArray<String>

Name of devices where to perform the installation

Returns:

  • (Array<String>)

Raises:



81
82
83
84
85
# File 'lib/dinstaller/storage/proposal.rb', line 81

def candidate_devices
  raise NoProposalError unless proposal

  proposal.settings.candidate_devices
end

#changed!Object



47
48
49
# File 'lib/dinstaller/storage/proposal.rb', line 47

def changed!
  @listeners.each(&:call)
end

#device_label(device) ⇒ String

Label that should be used to represent the given disk in the UI

NOTE: this is likely a temporary solution. The label should not be calculated in the backend in the future. See the note about available_devices at DBus::Storage::Proposal.

The label has the form: “NAME, SIZE, [USB], INSTALLED_SYSTEMS”.

Examples:

"/dev/sda, 250.00 GiB, Windows, OpenSUSE"
"/dev/sdb, 8.00 GiB, USB"

Parameters:

  • device (Y2Storage::Device)

Returns:

  • (String)


72
73
74
# File 'lib/dinstaller/storage/proposal.rb', line 72

def device_label(device)
  disk_helper.label(device)
end

#lvm?Boolean

Whether the proposal should create LVM devices

Returns:

  • (Boolean)

Raises:



92
93
94
95
96
# File 'lib/dinstaller/storage/proposal.rb', line 92

def lvm?
  raise NoProposalError unless proposal

  proposal.settings.use_lvm
end