Skip to content

Commit

Permalink
WIP: Use AgamaProposal for the initial storage proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs committed Oct 25, 2024
1 parent fd2433e commit d139a2b
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 3 deletions.
112 changes: 112 additions & 0 deletions service/lib/agama/storage/config_reader.rb
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
6 changes: 3 additions & 3 deletions service/lib/agama/storage/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
require "agama/storage/callbacks"
require "agama/storage/iscsi/manager"
require "agama/storage/finisher"
require "agama/storage/proposal_settings_reader"
require "agama/storage/config_reader"
require "agama/issue"
require "agama/with_locale"
require "agama/with_issues"
Expand Down Expand Up @@ -216,8 +216,8 @@ def probe_devices

# Calculates the proposal using the settings from the config file.
def calculate_proposal
settings = ProposalSettingsReader.new(config).read
proposal.calculate_guided(settings)
settings = ConfigReader.new(config).read
proposal.calculate_agama(settings)
end

# Adds the required packages to the list of resolvables to install
Expand Down

0 comments on commit d139a2b

Please sign in to comment.