-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a73acce
commit 0a2922d
Showing
2 changed files
with
109 additions
and
0 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
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,100 @@ | ||
# 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. | ||
|
||
module Agama | ||
module Storage | ||
# Class for solving a storage config. | ||
# | ||
# It assigns proper devices and size values according to the product and the system. | ||
class ConfigJSONSolver | ||
# @param devicegraph [Y2Storage::Devicegraph] | ||
# @param product_config [Agama::Config] | ||
def initialize(product_config) | ||
@product_config = product_config | ||
end | ||
|
||
# Solves all the search and size configs within a given config. | ||
# | ||
# @note The config object is modified. | ||
# | ||
# @param config [Config] | ||
def solve(config_json) | ||
@config_json = config_json | ||
|
||
solve_partitions | ||
solve_logical_volumes | ||
end | ||
|
||
private | ||
|
||
# @return [Hash] | ||
attr_reader :config_json | ||
|
||
# @return [Agama::Config] | ||
attr_reader :product_config | ||
|
||
def solve_partitions | ||
configs_with_partitions_keyword.each { |c| solve_partitions_keyword(c) } | ||
end | ||
|
||
def solve_logical_volumes | ||
configs_with_logical_volumes_keyword.each { |c| solve_logical_volumes_keyword(c) } | ||
end | ||
|
||
def configs_with_partitions_keyword | ||
configs = drive_configs | ||
end | ||
|
||
def explicit_paths | ||
configs_with_filesystem | ||
.select { |c| c.is_a?(Hash) } | ||
.map { |c| c.dig(:filesystem, :path) } | ||
.compact | ||
end | ||
|
||
def configs_with_filesystem | ||
drive_configs + partition_configs + logical_volume_configs | ||
end | ||
|
||
def drive_configs | ||
config_json[:drives] || [] | ||
end | ||
|
||
def partition_configs | ||
drive_configs = config_json[:drives] | ||
return [] unless drive_configs | ||
|
||
drive_configs | ||
.flat_map { |c| c[:partitions] } | ||
.compact | ||
end | ||
|
||
def logical_volume_configs | ||
volume_group_configs = config_json[:volumeGroups] | ||
return [] unless volume_group_configs | ||
|
||
volume_group_configs | ||
.flat_map { |c| c[:logicalVolumes] } | ||
.compact | ||
end | ||
end | ||
end | ||
end |