-
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.
storage: create LVM config from JSON
- Loading branch information
1 parent
9b81ed2
commit ed5805c
Showing
7 changed files
with
334 additions
and
110 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
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
88 changes: 88 additions & 0 deletions
88
service/lib/agama/storage/config_conversions/from_json_conversions/logical_volume.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,88 @@ | ||
# 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_json_conversions/base" | ||
require "agama/storage/config_conversions/from_json_conversions/with_encryption" | ||
require "agama/storage/config_conversions/from_json_conversions/with_filesystem" | ||
require "agama/storage/config_conversions/from_json_conversions/with_size" | ||
require "agama/storage/configs/logical_volume" | ||
require "y2storage/disk_size" | ||
|
||
module Agama | ||
module Storage | ||
module ConfigConversions | ||
module FromJSONConversions | ||
# Logical volume conversion from JSON hash according to schema. | ||
class LogicalVolume < Base | ||
include WithEncryption | ||
include WithFilesystem | ||
include WithSize | ||
|
||
# @param logical_volume_json [Hash] | ||
# @param config_builder [ConfigBuilder, nil] | ||
def initialize(logical_volume_json, config_builder: nil) | ||
super(config_builder) | ||
@logical_volume_json = logical_volume_json | ||
end | ||
|
||
# @see Base#convert | ||
# | ||
# @param default [Configs::LogicalVolume, nil] | ||
# @return [Configs::LogicalVolume] | ||
def convert(default = nil) | ||
super(default || Configs::LogicalVolume.new) | ||
end | ||
|
||
private | ||
|
||
# @return [Hash] | ||
attr_reader :logical_volume_json | ||
|
||
# @see Base#conversions | ||
# | ||
# @param default [Configs::LogicalVolume] | ||
# @return [Hash] | ||
def conversions(default) | ||
{ | ||
alias: logical_volume_json[:alias], | ||
encryption: convert_encryption(logical_volume_json, default: default.encryption), | ||
filesystem: convert_filesystem(logical_volume_json, default: default.filesystem), | ||
size: convert_size(logical_volume_json, default: default.size), | ||
name: logical_volume_json[:name], | ||
stripes: logical_volume_json[:stripes], | ||
stripe_size: convert_stripe_size, | ||
pool: logical_volume_json[:pool], | ||
used_pool: logical_volume_json[:usedPool] | ||
} | ||
end | ||
|
||
# @return [Y2Storage::DiskSize, nil] | ||
def convert_stripe_size | ||
value = logical_volume_json[:stripeSize] | ||
return unless value | ||
|
||
Y2Storage::DiskSize.new(value) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
92 changes: 92 additions & 0 deletions
92
service/lib/agama/storage/config_conversions/from_json_conversions/volume_group.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,92 @@ | ||
# 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_json_conversions/base" | ||
require "agama/storage/config_conversions/from_json_conversions/logical_volume" | ||
require "agama/storage/configs/drive" | ||
|
||
module Agama | ||
module Storage | ||
module ConfigConversions | ||
module FromJSONConversions | ||
# Volume group conversion from JSON hash according to schema. | ||
class VolumeGroup < Base | ||
# @param volume_group_json [Hash] | ||
# @param config_builder [ConfigBuilder, nil] | ||
def initialize(volume_group_json, config_builder: nil) | ||
super(config_builder) | ||
@volume_group_json = volume_group_json | ||
end | ||
|
||
# @see Base#convert | ||
# | ||
# @param default [Configs::VolumeGroup, nil] | ||
# @return [Configs::VolumeGroup] | ||
def convert(default = nil) | ||
super(default || Configs::VolumeGroup.new) | ||
end | ||
|
||
private | ||
|
||
# @return [Hash] | ||
attr_reader :volume_group_json | ||
|
||
# @see Base#conversions | ||
# | ||
# @param _default [Configs::VolumeGroup] | ||
# @return [Hash] | ||
def conversions(_default) | ||
{ | ||
name: volume_group_json[:name], | ||
extend_size: convert_extend_size, | ||
physical_volumes: volume_group_json[:physicalVolumes], | ||
logical_volumes: convert_logical_volumes | ||
} | ||
end | ||
|
||
# @return [Y2Storage::DiskSize, nil] | ||
def convert_extend_size | ||
value = volume_group_json[:extendSize] | ||
return unless value | ||
|
||
Y2Storage::DiskSize.new(value) | ||
end | ||
|
||
# @return [Array<Configs::LogicalVolume>, nil] | ||
def convert_logical_volumes | ||
logical_volumes_json = volume_group_json[:logicalVolumes] | ||
return unless logical_volumes_json | ||
|
||
logical_volumes_json.map { |l| convert_logical_volume(l) } | ||
end | ||
|
||
# @param logical_volume_json [Hash] | ||
# @return [Configs::LogicalVolume] | ||
def convert_logical_volume(logical_volume_json) | ||
FromJSONConversions::LogicalVolume | ||
.new(logical_volume_json, config_builder: config_builder) | ||
.convert | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
105 changes: 0 additions & 105 deletions
105
service/lib/agama/storage/config_conversions/volume_group/from_json.rb
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.