forked from agama-project/agama
-
Notifications
You must be signed in to change notification settings - Fork 0
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
9ba3f55
commit 1582a5c
Showing
23 changed files
with
1,041 additions
and
507 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,111 @@ | ||
# 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/configs" | ||
require "agama/storage/proposal_settings_reader" | ||
require "agama/storage/volume_templates_builder" | ||
|
||
module Agama | ||
module Storage | ||
# Class for building configs. | ||
class ConfigBuilder | ||
# @todo Replace product_config param by a ProductDefinition. | ||
# | ||
# @param product_config [Agama::Config] | ||
def initialize(product_config) | ||
@product_config = product_config | ||
end | ||
|
||
# Default drive config from the product definition. | ||
# | ||
# @param path [String, nil] | ||
# @return [Configs::Drive] | ||
def default_drive(path = nil) | ||
Configs::Drive.new.tap do |drive| | ||
drive.encryption = default_encryption | ||
drive.filesystem = default_filesystem(path) | ||
end | ||
end | ||
|
||
# Default partition config from the product definition. | ||
# | ||
# @param path [String, nil] | ||
# @return [Configs::Partition] | ||
def default_partition(path = nil) | ||
Configs::Partition.new.tap do |partition| | ||
partition.encryption = default_encryption | ||
partition.filesystem = default_filesystem(path) | ||
end | ||
end | ||
|
||
private | ||
|
||
# @return [Agama::Config] | ||
attr_reader :product_config | ||
|
||
# Default encryption config from the product definition. | ||
# | ||
# @return [Configs::Encryption] | ||
def default_encryption | ||
Configs::Encryption.new.tap do |config| | ||
config.password = settings.encryption.password | ||
config.method = settings.encryption.method | ||
config.pbkd_function = settings.encryption.pbkd_function | ||
end | ||
end | ||
|
||
# Default format config from the product definition. | ||
# | ||
# @param path [String, nil] | ||
# @return [Configs::Filesystem] | ||
def default_filesystem(path = nil) | ||
path ||= "" | ||
|
||
Configs::Filesystem.new.tap do |config| | ||
config.type = default_fstype(path) | ||
end | ||
end | ||
|
||
# Default filesystem type config from the product definition. | ||
# | ||
# @param path [String] | ||
# @return [Configs::FilesystemType] | ||
def default_fstype(path = nil) | ||
volume = volume_builder.for(path || "") | ||
|
||
Configs::FilesystemType.new.tap do |config| | ||
config.fs_type = volume.fs_type | ||
config.btrfs = volume.btrfs | ||
end | ||
end | ||
|
||
# @return [ProposalSettings] | ||
def settings | ||
@settings ||= ProposalSettingsReader.new(product_config).read | ||
end | ||
|
||
# @return [VolumeTemplatesBuilder] | ||
def volume_builder | ||
@volume_builder ||= VolumeTemplatesBuilder.new_from_config(product_config) | ||
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
75 changes: 75 additions & 0 deletions
75
service/lib/agama/storage/config_conversions/from_json_conversions/base.rb
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,75 @@ | ||
# 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/configs/drive" | ||
require "agama/storage/configs/partition" | ||
|
||
module Agama | ||
module Storage | ||
module ConfigConversions | ||
module FromJSONConversions | ||
# Base class for conversions from JSON hash according to schema. | ||
class Base | ||
# @param config_builder [ConfigBuilder, nil] | ||
def initialize(config_builder = nil) | ||
@config_builder = config_builder | ||
end | ||
|
||
# Performs the conversion from Hash according to the JSON schema. | ||
# | ||
# @param default [Object] Any config from {Storage::Configs}. | ||
# @return [Object] Any config from {Storage::Configs}. | ||
def convert(default) | ||
default.dup.tap do |config| | ||
conversions(config).each do |property, value| | ||
next if skip?(property, value) | ||
|
||
config.public_send("#{property}=", value) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
# @return [ConfigBuilder, nil] | ||
attr_reader :config_builder | ||
|
||
# Values to apply to the config. | ||
# | ||
# @param _default [Object] Any config from {Storage::Configs}. | ||
# @return [Hash] e.g., { name: "/dev/vda" }. | ||
def conversions(_default) | ||
{} | ||
end | ||
|
||
# Whether to skip the assignment of the property. | ||
# | ||
# @param _property [Symbol] | ||
# @param value [Object] | ||
# @return [Boolean] | ||
def skip?(_property, value) | ||
value.nil? | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.