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
a55a65e
commit bb85ecc
Showing
17 changed files
with
1,778 additions
and
1 deletion.
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
50 changes: 50 additions & 0 deletions
50
service/lib/agama/storage/config_conversions/from_model.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,50 @@ | ||
# 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/config" | ||
require "agama/storage/config_conversions/from_model_conversions/config" | ||
|
||
module Agama | ||
module Storage | ||
module ConfigConversions | ||
# Config conversion from model according to the JSON schema. | ||
class FromModel | ||
# @param model_json [Hash] | ||
def initialize(model_json) | ||
@model_json = model_json | ||
end | ||
|
||
# Performs the conversion from model according to the JSON schema. | ||
# | ||
# @return [Storage::Config] | ||
def convert | ||
# TODO: Raise error if model_json does not match the JSON schema. | ||
FromModelConversions::Config.new(model_json).convert | ||
end | ||
|
||
private | ||
|
||
# @return [Hash] | ||
attr_reader :model_json | ||
end | ||
end | ||
end | ||
end |
38 changes: 38 additions & 0 deletions
38
service/lib/agama/storage/config_conversions/from_model_conversions.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,38 @@ | ||
# 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/from_model_conversions/config" | ||
require "agama/storage/config_conversions/from_model_conversions/drive" | ||
require "agama/storage/config_conversions/from_model_conversions/filesystem" | ||
require "agama/storage/config_conversions/from_model_conversions/filesystem_type" | ||
require "agama/storage/config_conversions/from_model_conversions/partition" | ||
require "agama/storage/config_conversions/from_model_conversions/search" | ||
require "agama/storage/config_conversions/from_model_conversions/size" | ||
|
||
module Agama | ||
module Storage | ||
module ConfigConversions | ||
# Conversions from model according to the JSON schema. | ||
module FromModelConversions | ||
end | ||
end | ||
end | ||
end |
70 changes: 70 additions & 0 deletions
70
service/lib/agama/storage/config_conversions/from_model_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,70 @@ | ||
# 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 | ||
module ConfigConversions | ||
module FromModelConversions | ||
# Base class for conversions from model according to the JSON schema. | ||
class Base | ||
# @param model_json [Hash] | ||
def initialize(model_json) | ||
@model_json = model_json | ||
end | ||
|
||
# Performs the conversion from model according to the JSON schema. | ||
# | ||
# @return [Object] A {Config} or any its configs from {Storage::Configs}. | ||
def convert | ||
config = default_config | ||
|
||
conversions.each do |property, value| | ||
next if value.nil? | ||
|
||
config.public_send("#{property}=", value) | ||
end | ||
|
||
config | ||
end | ||
|
||
private | ||
|
||
# @return [Hash] | ||
attr_reader :model_json | ||
|
||
# Default config object (defined by derived classes). | ||
# | ||
# @return [Object] | ||
def default_config | ||
raise "Undefined default config" | ||
end | ||
|
||
# Values to apply to the config. | ||
# | ||
# @return [Hash] e.g., { name: "/dev/vda" }. | ||
def conversions | ||
{} | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
65 changes: 65 additions & 0 deletions
65
service/lib/agama/storage/config_conversions/from_model_conversions/config.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,65 @@ | ||
# 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/from_model_conversions/base" | ||
require "agama/storage/config_conversions/from_model_conversions/drive" | ||
require "agama/storage/config" | ||
|
||
module Agama | ||
module Storage | ||
module ConfigConversions | ||
module FromModelConversions | ||
# Config conversion from model according to the JSON schema. | ||
class Config < Base | ||
private | ||
|
||
# @see Base | ||
# @return [Storage::Config] | ||
def default_config | ||
Storage::Config.new | ||
end | ||
|
||
# @see Base#conversions | ||
# @return [Hash] | ||
def conversions | ||
{ | ||
drives: convert_drives | ||
} | ||
end | ||
|
||
# @return [Array<Configs::Drive>, nil] | ||
def convert_drives | ||
drive_models = model_json[:drives] | ||
return unless drive_models | ||
|
||
drive_models.map { |d| convert_drive(d) } | ||
end | ||
|
||
# @param drive_model [Hash] | ||
# @return [Configs::Drive] | ||
def convert_drive(drive_model) | ||
FromModelConversions::Drive.new(drive_model).convert | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
65 changes: 65 additions & 0 deletions
65
service/lib/agama/storage/config_conversions/from_model_conversions/drive.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,65 @@ | ||
# 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/from_model_conversions/base" | ||
require "agama/storage/config_conversions/from_model_conversions/with_filesystem" | ||
require "agama/storage/config_conversions/from_model_conversions/with_partitions" | ||
require "agama/storage/config_conversions/from_model_conversions/with_ptable_type" | ||
require "agama/storage/config_conversions/from_model_conversions/with_search" | ||
require "agama/storage/configs/drive" | ||
|
||
module Agama | ||
module Storage | ||
module ConfigConversions | ||
module FromModelConversions | ||
# Drive conversion from model according to the JSON schema. | ||
class Drive < Base | ||
private | ||
|
||
include WithFilesystem | ||
include WithPtableType | ||
include WithPartitions | ||
include WithSearch | ||
|
||
alias_method :drive_model, :model_json | ||
|
||
# @see Base | ||
# @return [Configs::Drive] | ||
def default_config | ||
Configs::Drive.new | ||
end | ||
|
||
# @see Base#conversions | ||
# @return [Hash] | ||
def conversions | ||
{ | ||
search: convert_search, | ||
alias: drive_model[:alias], | ||
filesystem: convert_filesystem, | ||
ptable_type: convert_ptable_type, | ||
partitions: convert_partitions | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
60 changes: 60 additions & 0 deletions
60
service/lib/agama/storage/config_conversions/from_model_conversions/filesystem.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,60 @@ | ||
# 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/from_model_conversions/base" | ||
require "agama/storage/config_conversions/from_model_conversions/filesystem_type" | ||
require "agama/storage/configs/filesystem" | ||
|
||
module Agama | ||
module Storage | ||
module ConfigConversions | ||
module FromModelConversions | ||
# Filesystem conversion from model according to the JSON schema. | ||
class Filesystem < Base | ||
private | ||
|
||
# @see Base | ||
# @return [Configs::Filesystem] | ||
def default_config | ||
Configs::Filesystem.new | ||
end | ||
|
||
# @see Base#conversions | ||
# @return [Hash] | ||
def conversions | ||
{ | ||
path: model_json[:mountPath], | ||
type: convert_type | ||
} | ||
end | ||
|
||
# @return [Configs::FilesystemType, nil] | ||
def convert_type | ||
filesystem_model = model_json[:filesystem] | ||
return if filesystem_model.nil? | ||
|
||
FromModelConversions::FilesystemType.new(filesystem_model).convert | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.