d-installer 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +29 -0
- data/Gemfile.lock +75 -0
- data/bin/d-installer +74 -0
- data/etc/d-installer.yaml +284 -0
- data/lib/dinstaller/can_ask_question.rb +48 -0
- data/lib/dinstaller/cmdline_args.rb +80 -0
- data/lib/dinstaller/cockpit_manager.rb +176 -0
- data/lib/dinstaller/config.rb +128 -0
- data/lib/dinstaller/config_reader.rb +164 -0
- data/lib/dinstaller/dbus/base_object.rb +58 -0
- data/lib/dinstaller/dbus/clients/base.rb +71 -0
- data/lib/dinstaller/dbus/clients/language.rb +86 -0
- data/lib/dinstaller/dbus/clients/manager.rb +76 -0
- data/lib/dinstaller/dbus/clients/software.rb +185 -0
- data/lib/dinstaller/dbus/clients/users.rb +112 -0
- data/lib/dinstaller/dbus/clients/with_progress.rb +56 -0
- data/lib/dinstaller/dbus/clients/with_service_status.rb +75 -0
- data/lib/dinstaller/dbus/clients.rb +34 -0
- data/lib/dinstaller/dbus/interfaces/progress.rb +113 -0
- data/lib/dinstaller/dbus/interfaces/service_status.rb +89 -0
- data/lib/dinstaller/dbus/language.rb +93 -0
- data/lib/dinstaller/dbus/language_service.rb +92 -0
- data/lib/dinstaller/dbus/manager.rb +147 -0
- data/lib/dinstaller/dbus/manager_service.rb +132 -0
- data/lib/dinstaller/dbus/question.rb +176 -0
- data/lib/dinstaller/dbus/questions.rb +124 -0
- data/lib/dinstaller/dbus/service_runner.rb +97 -0
- data/lib/dinstaller/dbus/service_status.rb +87 -0
- data/lib/dinstaller/dbus/software/manager.rb +131 -0
- data/lib/dinstaller/dbus/software/proposal.rb +82 -0
- data/lib/dinstaller/dbus/software.rb +31 -0
- data/lib/dinstaller/dbus/software_service.rb +86 -0
- data/lib/dinstaller/dbus/storage/proposal.rb +170 -0
- data/lib/dinstaller/dbus/storage.rb +30 -0
- data/lib/dinstaller/dbus/users.rb +132 -0
- data/lib/dinstaller/dbus/users_service.rb +92 -0
- data/lib/dinstaller/dbus/with_service_status.rb +48 -0
- data/lib/dinstaller/dbus/y2dir/manager/modules/Package.rb +51 -0
- data/lib/dinstaller/dbus/y2dir/manager/modules/PackagesProposal.rb +62 -0
- data/lib/dinstaller/dbus/y2dir/modules/Autologin.rb +214 -0
- data/lib/dinstaller/dbus/y2dir/software/modules/SpaceCalculation.rb +44 -0
- data/lib/dinstaller/dbus.rb +11 -0
- data/lib/dinstaller/errors.rb +28 -0
- data/lib/dinstaller/installation_phase.rb +106 -0
- data/lib/dinstaller/language.rb +73 -0
- data/lib/dinstaller/luks_activation_question.rb +92 -0
- data/lib/dinstaller/manager.rb +261 -0
- data/lib/dinstaller/network.rb +53 -0
- data/lib/dinstaller/package_callbacks.rb +69 -0
- data/lib/dinstaller/progress.rb +149 -0
- data/lib/dinstaller/question.rb +103 -0
- data/lib/dinstaller/questions_manager.rb +145 -0
- data/lib/dinstaller/security.rb +96 -0
- data/lib/dinstaller/service_status_recorder.rb +58 -0
- data/lib/dinstaller/software.rb +232 -0
- data/lib/dinstaller/storage/actions.rb +90 -0
- data/lib/dinstaller/storage/callbacks/activate.rb +93 -0
- data/lib/dinstaller/storage/callbacks/activate_luks.rb +93 -0
- data/lib/dinstaller/storage/callbacks/activate_multipath.rb +77 -0
- data/lib/dinstaller/storage/callbacks.rb +30 -0
- data/lib/dinstaller/storage/manager.rb +104 -0
- data/lib/dinstaller/storage/proposal.rb +197 -0
- data/lib/dinstaller/storage.rb +30 -0
- data/lib/dinstaller/users.rb +156 -0
- data/lib/dinstaller/with_progress.rb +63 -0
- data/lib/dinstaller.rb +5 -0
- data/share/dbus.conf +38 -0
- data/share/dbus.service +5 -0
- data/share/systemd.service +14 -0
- metadata +295 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) [2022] SUSE LLC
|
4
|
+
#
|
5
|
+
# All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This program is free software; you can redistribute it and/or modify it
|
8
|
+
# under the terms of version 2 of the GNU General Public License as published
|
9
|
+
# by the Free Software Foundation.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
12
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
14
|
+
# more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License along
|
17
|
+
# with this program; if not, contact SUSE LLC.
|
18
|
+
#
|
19
|
+
# To contact SUSE LLC about this file by physical or electronic mail, you may
|
20
|
+
# find current contact information at www.suse.com.
|
21
|
+
|
22
|
+
require "storage"
|
23
|
+
require "y2storage/callbacks/issues_callback"
|
24
|
+
require "dinstaller/storage/callbacks/activate_multipath"
|
25
|
+
require "dinstaller/storage/callbacks/activate_luks"
|
26
|
+
|
27
|
+
module DInstaller
|
28
|
+
module Storage
|
29
|
+
module Callbacks
|
30
|
+
# Callbacks to manage devices activation
|
31
|
+
class Activate < ::Storage::ActivateCallbacksLuks
|
32
|
+
include Y2Storage::Callbacks::IssuesCallback
|
33
|
+
|
34
|
+
# Constructor
|
35
|
+
#
|
36
|
+
# @param questions_manager [QuestionsManager]
|
37
|
+
# @param logger [Logger]
|
38
|
+
def initialize(questions_manager, logger)
|
39
|
+
super()
|
40
|
+
|
41
|
+
@questions_manager = questions_manager
|
42
|
+
@logger = logger
|
43
|
+
@issues = Y2Issues::List.new
|
44
|
+
end
|
45
|
+
|
46
|
+
# Messages are ignored to not bother the user
|
47
|
+
#
|
48
|
+
# See Storage::Callbacks#message in libstorage-ng
|
49
|
+
def message(_message); end
|
50
|
+
|
51
|
+
# Decides whether multipath should be activated
|
52
|
+
#
|
53
|
+
# @see ActivateMultipath
|
54
|
+
#
|
55
|
+
# @param looks_like_real_multipath [Boolean] true if the system seems to contain a multipath
|
56
|
+
# device.
|
57
|
+
# @return [Boolean]
|
58
|
+
def multipath(looks_like_real_multipath)
|
59
|
+
callback = ActivateMultipath.new(questions_manager, logger)
|
60
|
+
|
61
|
+
callback.call(looks_like_real_multipath)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Decides whether a LUKS device should be activated
|
65
|
+
#
|
66
|
+
# @see ActivateLuks
|
67
|
+
#
|
68
|
+
# @param info [Storage::LuksInfo]
|
69
|
+
# @param attempt [Numeric]
|
70
|
+
#
|
71
|
+
# @return [Storage::PairBoolString] Whether to activate the device and the password
|
72
|
+
def luks(info, attempt)
|
73
|
+
callback = ActivateLuks.new(questions_manager, logger)
|
74
|
+
|
75
|
+
activate, password = callback.call(info, attempt)
|
76
|
+
|
77
|
+
::Storage::PairBoolString.new(activate, password || "")
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
# @return [QuestionsManager]
|
83
|
+
attr_reader :questions_manager
|
84
|
+
|
85
|
+
# @return [Logger]
|
86
|
+
attr_reader :logger
|
87
|
+
|
88
|
+
# Mixin Y2Storage::Callbacks::IssuesCallback expects a #log method
|
89
|
+
alias_method :log, :logger
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) [2022] SUSE LLC
|
4
|
+
#
|
5
|
+
# All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This program is free software; you can redistribute it and/or modify it
|
8
|
+
# under the terms of version 2 of the GNU General Public License as published
|
9
|
+
# by the Free Software Foundation.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
12
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
14
|
+
# more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License along
|
17
|
+
# with this program; if not, contact SUSE LLC.
|
18
|
+
#
|
19
|
+
# To contact SUSE LLC about this file by physical or electronic mail, you may
|
20
|
+
# find current contact information at www.suse.com.
|
21
|
+
|
22
|
+
require "dinstaller/luks_activation_question"
|
23
|
+
require "dinstaller/can_ask_question"
|
24
|
+
require "y2storage/disk_size"
|
25
|
+
|
26
|
+
module DInstaller
|
27
|
+
module Storage
|
28
|
+
module Callbacks
|
29
|
+
# Callbacks for LUKS activation
|
30
|
+
class ActivateLuks
|
31
|
+
include CanAskQuestion
|
32
|
+
|
33
|
+
# Constructor
|
34
|
+
#
|
35
|
+
# @param questions_manager [QuestionsManager]
|
36
|
+
# @param logger [Logger]
|
37
|
+
def initialize(questions_manager, logger)
|
38
|
+
@questions_manager = questions_manager
|
39
|
+
@logger = logger
|
40
|
+
end
|
41
|
+
|
42
|
+
# Asks whether to activate a LUKS device
|
43
|
+
#
|
44
|
+
# @note The process waits until the question is answered.
|
45
|
+
#
|
46
|
+
# @param info [Storage::LuksInfo]
|
47
|
+
# @param attempt [Numeric]
|
48
|
+
#
|
49
|
+
# @return [Array(Boolean, String)] The first value is whether to activate the device, and
|
50
|
+
# the second one is the LUKS password. Note that the password would only be considered
|
51
|
+
# when the first value is true.
|
52
|
+
def call(info, attempt)
|
53
|
+
question = question(info, attempt)
|
54
|
+
|
55
|
+
ask(question) do |q|
|
56
|
+
logger.info("#{q.text} #{q.answer}")
|
57
|
+
|
58
|
+
activate = q.answer == :decrypt
|
59
|
+
password = q.password
|
60
|
+
|
61
|
+
[activate, password]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
# @return [QuestionsManager]
|
68
|
+
attr_reader :questions_manager
|
69
|
+
|
70
|
+
# @return [Logger]
|
71
|
+
attr_reader :logger
|
72
|
+
|
73
|
+
# Question to ask for LUKS activation
|
74
|
+
#
|
75
|
+
# @return [LuksActivationQuestion]
|
76
|
+
def question(info, attempt)
|
77
|
+
LuksActivationQuestion.new(info.device_name,
|
78
|
+
label: info.label,
|
79
|
+
size: formatted_size(info.size),
|
80
|
+
attempt: attempt)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Generates a formatted representation of the size
|
84
|
+
#
|
85
|
+
# @param size [Y2Storage::DiskSize]
|
86
|
+
# @return [String]
|
87
|
+
def formatted_size(value)
|
88
|
+
Y2Storage::DiskSize.new(value).to_human_string
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) [2022] SUSE LLC
|
4
|
+
#
|
5
|
+
# All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This program is free software; you can redistribute it and/or modify it
|
8
|
+
# under the terms of version 2 of the GNU General Public License as published
|
9
|
+
# by the Free Software Foundation.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
12
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
14
|
+
# more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License along
|
17
|
+
# with this program; if not, contact SUSE LLC.
|
18
|
+
#
|
19
|
+
# To contact SUSE LLC about this file by physical or electronic mail, you may
|
20
|
+
# find current contact information at www.suse.com.
|
21
|
+
|
22
|
+
require "dinstaller/question"
|
23
|
+
require "dinstaller/can_ask_question"
|
24
|
+
|
25
|
+
module DInstaller
|
26
|
+
module Storage
|
27
|
+
module Callbacks
|
28
|
+
# Callbacks for multipath activation
|
29
|
+
class ActivateMultipath
|
30
|
+
include CanAskQuestion
|
31
|
+
|
32
|
+
# Constructor
|
33
|
+
#
|
34
|
+
# @param questions_manager [QuestionsManager]
|
35
|
+
# @param logger [Logger]
|
36
|
+
def initialize(questions_manager, logger)
|
37
|
+
@questions_manager = questions_manager
|
38
|
+
@logger = logger
|
39
|
+
end
|
40
|
+
|
41
|
+
# Asks whether to activate multipath devices
|
42
|
+
#
|
43
|
+
# @note The process waits until the question is answered.
|
44
|
+
#
|
45
|
+
# @param looks_like_real_multipath [Boolean] see {Callbacks::Activate#multipath}.
|
46
|
+
# @return [Boolean]
|
47
|
+
def call(looks_like_real_multipath)
|
48
|
+
return false unless looks_like_real_multipath
|
49
|
+
|
50
|
+
ask(question) do |q|
|
51
|
+
logger.info("#{q.text} #{q.answer}")
|
52
|
+
|
53
|
+
q.answer == :yes
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
# @return [QuestionsManager]
|
60
|
+
attr_reader :questions_manager
|
61
|
+
|
62
|
+
# @return [Logger]
|
63
|
+
attr_reader :logger
|
64
|
+
|
65
|
+
# Question to ask for multipath activation
|
66
|
+
#
|
67
|
+
# @return [Question]
|
68
|
+
def question
|
69
|
+
text = "The system seems to have multipath hardware. " \
|
70
|
+
"Do you want to activate multipath?"
|
71
|
+
|
72
|
+
Question.new(text, options: [:yes, :no])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) [2022] SUSE LLC
|
4
|
+
#
|
5
|
+
# All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This program is free software; you can redistribute it and/or modify it
|
8
|
+
# under the terms of version 2 of the GNU General Public License as published
|
9
|
+
# by the Free Software Foundation.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
12
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
14
|
+
# more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License along
|
17
|
+
# with this program; if not, contact SUSE LLC.
|
18
|
+
#
|
19
|
+
# To contact SUSE LLC about this file by physical or electronic mail, you may
|
20
|
+
# find current contact information at www.suse.com.
|
21
|
+
|
22
|
+
module DInstaller
|
23
|
+
module Storage
|
24
|
+
# Module for callbacks related to storage actions
|
25
|
+
module Callbacks
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
require "dinstaller/storage/callbacks/activate"
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) [2022] SUSE LLC
|
4
|
+
#
|
5
|
+
# All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This program is free software; you can redistribute it and/or modify it
|
8
|
+
# under the terms of version 2 of the GNU General Public License as published
|
9
|
+
# by the Free Software Foundation.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
12
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
14
|
+
# more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License along
|
17
|
+
# with this program; if not, contact SUSE LLC.
|
18
|
+
#
|
19
|
+
# To contact SUSE LLC about this file by physical or electronic mail, you may
|
20
|
+
# find current contact information at www.suse.com.
|
21
|
+
|
22
|
+
require "yast"
|
23
|
+
require "y2storage/storage_manager"
|
24
|
+
require "dinstaller/storage/proposal"
|
25
|
+
require "dinstaller/storage/callbacks"
|
26
|
+
|
27
|
+
Yast.import "PackagesProposal"
|
28
|
+
|
29
|
+
module DInstaller
|
30
|
+
module Storage
|
31
|
+
# Manager to handle storage configuration
|
32
|
+
class Manager
|
33
|
+
def initialize(logger, config)
|
34
|
+
@logger = logger
|
35
|
+
@config = config
|
36
|
+
end
|
37
|
+
|
38
|
+
# Probes storage devices and performs an initial proposal
|
39
|
+
#
|
40
|
+
# @param questions_manager [QuestionsManager]
|
41
|
+
def probe(questions_manager)
|
42
|
+
# TODO: Add progress once this is moved to its own service
|
43
|
+
logger.info "Probing storage and performing proposal"
|
44
|
+
activate_devices(questions_manager)
|
45
|
+
probe_devices
|
46
|
+
proposal.calculate
|
47
|
+
end
|
48
|
+
|
49
|
+
# Prepares the partitioning to install the system
|
50
|
+
def install
|
51
|
+
add_packages
|
52
|
+
Yast::WFM.CallFunction("inst_prepdisk", [])
|
53
|
+
end
|
54
|
+
|
55
|
+
# Umounts the target file system
|
56
|
+
def finish
|
57
|
+
Yast::WFM.CallFunction("umount_finish", ["Write"])
|
58
|
+
end
|
59
|
+
|
60
|
+
# Storage proposal manager
|
61
|
+
#
|
62
|
+
# @return [Storage::Proposal]
|
63
|
+
def proposal
|
64
|
+
@proposal ||= Proposal.new(logger, config)
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
PROPOSAL_ID = "storage_proposal"
|
70
|
+
private_constant :PROPOSAL_ID
|
71
|
+
|
72
|
+
# @return [Logger]
|
73
|
+
attr_reader :logger
|
74
|
+
|
75
|
+
# @return [Config]
|
76
|
+
attr_reader :config
|
77
|
+
|
78
|
+
# Activates the devices, calling activation callbacks if needed
|
79
|
+
#
|
80
|
+
# @param questions_manager [QuestionsManager]
|
81
|
+
def activate_devices(questions_manager)
|
82
|
+
callbacks = Callbacks::Activate.new(questions_manager, logger)
|
83
|
+
|
84
|
+
Y2Storage::StorageManager.instance.activate(callbacks)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Probes the devices
|
88
|
+
def probe_devices
|
89
|
+
# TODO: probe callbacks
|
90
|
+
Y2Storage::StorageManager.instance.probe
|
91
|
+
end
|
92
|
+
|
93
|
+
# Adds the required packages to the list of resolvables to install
|
94
|
+
def add_packages
|
95
|
+
devicegraph = Y2Storage::StorageManager.instance.staging
|
96
|
+
packages = devicegraph.used_features.pkg_list
|
97
|
+
return if packages.empty?
|
98
|
+
|
99
|
+
logger.info "Selecting these packages for installation: #{packages}"
|
100
|
+
Yast::PackagesProposal.SetResolvables(PROPOSAL_ID, :package, packages)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) [2022] SUSE LLC
|
4
|
+
#
|
5
|
+
# All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This program is free software; you can redistribute it and/or modify it
|
8
|
+
# under the terms of version 2 of the GNU General Public License as published
|
9
|
+
# by the Free Software Foundation.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
12
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
14
|
+
# more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License along
|
17
|
+
# with this program; if not, contact SUSE LLC.
|
18
|
+
#
|
19
|
+
# To contact SUSE LLC about this file by physical or electronic mail, you may
|
20
|
+
# find current contact information at www.suse.com.
|
21
|
+
|
22
|
+
require "y2storage/storage_manager"
|
23
|
+
require "y2storage/guided_proposal"
|
24
|
+
require "y2storage/proposal_settings"
|
25
|
+
require "y2storage/dialogs/guided_setup/helpers/disk"
|
26
|
+
|
27
|
+
module DInstaller
|
28
|
+
module Storage
|
29
|
+
# Backend class to calculate a storage proposal
|
30
|
+
class Proposal
|
31
|
+
class NoProposalError < StandardError; end
|
32
|
+
|
33
|
+
# Constructor
|
34
|
+
#
|
35
|
+
# @param logger [Logger]
|
36
|
+
# @param config [Config]
|
37
|
+
def initialize(logger, config)
|
38
|
+
@logger = logger
|
39
|
+
@config = config
|
40
|
+
@listeners = []
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_on_change_listener(&block)
|
44
|
+
@listeners << block
|
45
|
+
end
|
46
|
+
|
47
|
+
def changed!
|
48
|
+
@listeners.each(&:call)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Available devices for installation
|
52
|
+
#
|
53
|
+
# @return [Array<Y2Storage::Device>]
|
54
|
+
def available_devices
|
55
|
+
disk_analyzer.candidate_disks
|
56
|
+
end
|
57
|
+
|
58
|
+
# Label that should be used to represent the given disk in the UI
|
59
|
+
#
|
60
|
+
# NOTE: this is likely a temporary solution. The label should not be calculated in the backend
|
61
|
+
# in the future. See the note about available_devices at {DBus::Storage::Proposal}.
|
62
|
+
#
|
63
|
+
# The label has the form: "NAME, SIZE, [USB], INSTALLED_SYSTEMS".
|
64
|
+
#
|
65
|
+
# Examples:
|
66
|
+
#
|
67
|
+
# "/dev/sda, 250.00 GiB, Windows, OpenSUSE"
|
68
|
+
# "/dev/sdb, 8.00 GiB, USB"
|
69
|
+
#
|
70
|
+
# @param device [Y2Storage::Device]
|
71
|
+
# @return [String]
|
72
|
+
def device_label(device)
|
73
|
+
disk_helper.label(device)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Name of devices where to perform the installation
|
77
|
+
#
|
78
|
+
# @raise [NoProposalError] if no proposal yet
|
79
|
+
#
|
80
|
+
# @return [Array<String>]
|
81
|
+
def candidate_devices
|
82
|
+
raise NoProposalError unless proposal
|
83
|
+
|
84
|
+
proposal.settings.candidate_devices
|
85
|
+
end
|
86
|
+
|
87
|
+
# Whether the proposal should create LVM devices
|
88
|
+
#
|
89
|
+
# @raise [NoProposalError] if no proposal yet
|
90
|
+
#
|
91
|
+
# @return [Boolean]
|
92
|
+
def lvm?
|
93
|
+
raise NoProposalError unless proposal
|
94
|
+
|
95
|
+
proposal.settings.use_lvm
|
96
|
+
end
|
97
|
+
|
98
|
+
# Calculates a new proposal
|
99
|
+
#
|
100
|
+
# @param settings [Hash] settings to calculate the proposal
|
101
|
+
# (e.g., { "use_lvm" => true, "candidate_devices" => ["/dev/sda"]}). Note that keys should
|
102
|
+
# match with a public setter.
|
103
|
+
#
|
104
|
+
# @return [Boolean] whether the proposal was correctly calculated
|
105
|
+
def calculate(settings = {})
|
106
|
+
proposal_settings = generate_proposal_settings(settings)
|
107
|
+
|
108
|
+
@proposal = Y2Storage::GuidedProposal.initial(
|
109
|
+
settings: proposal_settings,
|
110
|
+
devicegraph: probed_devicegraph,
|
111
|
+
disk_analyzer: disk_analyzer
|
112
|
+
)
|
113
|
+
save
|
114
|
+
changed!
|
115
|
+
|
116
|
+
!proposal.failed?
|
117
|
+
end
|
118
|
+
|
119
|
+
# Storage actions manager
|
120
|
+
#
|
121
|
+
# @fixme this method should directly return the actions
|
122
|
+
#
|
123
|
+
# @return [Storage::Actions]
|
124
|
+
def actions
|
125
|
+
# FIXME: this class could receive the storage manager instance
|
126
|
+
@actions ||= Actions.new(logger)
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
# @return [Logger]
|
132
|
+
attr_reader :logger
|
133
|
+
|
134
|
+
# @return [Config]
|
135
|
+
attr_reader :config
|
136
|
+
|
137
|
+
# @return [Y2Storage::InitialGuidedProposal]
|
138
|
+
attr_reader :proposal
|
139
|
+
|
140
|
+
# Generates proposal settings from the given values
|
141
|
+
#
|
142
|
+
# @param settings [Hash]
|
143
|
+
# @return [Y2Storage::ProposalSettings]
|
144
|
+
def generate_proposal_settings(settings)
|
145
|
+
proposal_settings = Y2Storage::ProposalSettings.new_for_current_product
|
146
|
+
|
147
|
+
config_volumes = read_config_volumes
|
148
|
+
# If no volumes are specified, just leave the default ones (hardcoded at Y2Storage)
|
149
|
+
proposal_settings.volumes = config_volumes unless config_volumes.empty?
|
150
|
+
|
151
|
+
settings.each { |k, v| proposal_settings.public_send("#{k}=", v) }
|
152
|
+
|
153
|
+
proposal_settings
|
154
|
+
end
|
155
|
+
|
156
|
+
# Reads the list of volumes from the D-Installer configuration
|
157
|
+
#
|
158
|
+
# @return [Array<Y2Storage::VolumeSpecification>]
|
159
|
+
def read_config_volumes
|
160
|
+
vols = config.data.fetch("storage", {}).fetch("volumes", [])
|
161
|
+
vols.map { |v| Y2Storage::VolumeSpecification.new(v) }
|
162
|
+
end
|
163
|
+
|
164
|
+
# Saves the proposal or restores initial devices if a proposal was not calculated
|
165
|
+
def save
|
166
|
+
if proposal.failed?
|
167
|
+
storage_manager.staging = probed_devicegraph.dup
|
168
|
+
else
|
169
|
+
storage_manager.proposal = proposal
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# @return [Y2Storage::DiskAnalyzer]
|
174
|
+
def disk_analyzer
|
175
|
+
storage_manager.probed_disk_analyzer
|
176
|
+
end
|
177
|
+
|
178
|
+
# Helper to generate a disk label
|
179
|
+
#
|
180
|
+
# @return [Y2Storage::Dialogs::GuidedSetup::Helpers::Disk]
|
181
|
+
def disk_helper
|
182
|
+
@disk_helper ||= Y2Storage::Dialogs::GuidedSetup::Helpers::Disk.new(disk_analyzer)
|
183
|
+
end
|
184
|
+
|
185
|
+
# Devicegraph representing the system
|
186
|
+
#
|
187
|
+
# @return [Y2Storage::Devicegraph]
|
188
|
+
def probed_devicegraph
|
189
|
+
storage_manager.probed
|
190
|
+
end
|
191
|
+
|
192
|
+
def storage_manager
|
193
|
+
Y2Storage::StorageManager.instance
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) [2022] SUSE LLC
|
4
|
+
#
|
5
|
+
# All Rights Reserved.
|
6
|
+
#
|
7
|
+
# This program is free software; you can redistribute it and/or modify it
|
8
|
+
# under the terms of version 2 of the GNU General Public License as published
|
9
|
+
# by the Free Software Foundation.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
12
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
14
|
+
# more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License along
|
17
|
+
# with this program; if not, contact SUSE LLC.
|
18
|
+
#
|
19
|
+
# To contact SUSE LLC about this file by physical or electronic mail, you may
|
20
|
+
# find current contact information at www.suse.com.
|
21
|
+
|
22
|
+
module DInstaller
|
23
|
+
# Namespace for storage backend
|
24
|
+
module Storage
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
require "dinstaller/storage/manager"
|
29
|
+
require "dinstaller/storage/proposal"
|
30
|
+
require "dinstaller/storage/actions"
|