-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Use AgamaProposal for the initial storage proposal
- Loading branch information
Showing
3 changed files
with
120 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) [2024] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "agama/storage/config_conversions" | ||
|
||
module Agama | ||
module Storage | ||
# Reader for the initial storage config | ||
class ConfigReader | ||
# @param agama_config [Agama::Config] | ||
def initialize(agama_config) | ||
@agama_config = agama_config | ||
end | ||
|
||
# Generates a storage config from the Agama control file. | ||
# | ||
# @return [Storage::Config] | ||
def read | ||
ConfigConversions::FromJSON.new(json, default_paths: default_paths).convert | ||
end | ||
|
||
private | ||
|
||
# @return [Agama::Config] | ||
attr_reader :agama_config | ||
|
||
def default_paths | ||
@default_paths ||= agama_config.default_paths | ||
end | ||
|
||
def space_policy | ||
@space_policy ||= agama_config.data.dig("storage", "space_policy") | ||
end | ||
|
||
def lvm? | ||
return @lvm unless @lvm.nil? | ||
|
||
@lvm = !!agama_config.data.dig("storage", "lvm") | ||
end | ||
|
||
def json | ||
lvm? ? json_for_lvm : json_for_disk | ||
end | ||
|
||
def json_for_disk | ||
{ | ||
drives: [ | ||
{ partitions: [partition_for_existing, volumes_generator].compact } | ||
] | ||
} | ||
end | ||
|
||
def json_for_lvm | ||
{ | ||
drives: [ | ||
{ | ||
alias: "target", | ||
partitions: [partition_for_existing].compact | ||
} | ||
], | ||
volume_groups: [ | ||
{ | ||
name: "system", | ||
physicalVolumes: [pvs_generator], | ||
logicalVolumes: [volumes_generator] | ||
} | ||
] | ||
} | ||
end | ||
|
||
def volumes_generator | ||
{ generate: "default" } | ||
end | ||
|
||
def pvs_generator | ||
{ generate: ["target"] } | ||
end | ||
|
||
def partition_for_existing | ||
return unless ["delete", "resize"].include?(space_policy) | ||
|
||
partition = { search: "*" } | ||
|
||
if space_policy == "delete" | ||
partition[:delete] = true | ||
else | ||
partition[:size] = { min: 0, max: "current" } | ||
end | ||
|
||
partition | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters