Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions rust/agama-lib/share/storage.model.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@
"additionalProperties": false,
"required": ["vgName"],
"properties": {
"name": { "type": "string" },
"vgName": { "type": "string" },
"extentSize": { "type": "integer" },
"targetDevices": {
"type": "array",
"items": { "type": "string" }
},
"spacePolicy": { "$ref": "#/$defs/spacePolicy" },
"logicalVolumes": {
"type": "array",
"items": { "$ref": "#/$defs/logicalVolume" }
Expand All @@ -110,12 +112,17 @@
"type": "object",
"additionalProperties": false,
"properties": {
"name": { "type": "string" },
"lvName": { "type": "string" },
"mountPath": { "type": "string" },
"filesystem": { "$ref": "#/$defs/filesystem" },
"size": { "$ref": "#/$defs/size" },
"stripes": { "type": "integer" },
"stripeSize": { "type": "integer" }
"stripeSize": { "type": "integer" },
"size": { "$ref": "#/$defs/size" },
"delete": { "type": "boolean" },
"deleteIfNeeded": { "type": "boolean" },
"resize": { "type": "boolean" },
"resizeIfNeeded": { "type": "boolean" }
}
},
"spacePolicy": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2024-2025] SUSE LLC
# Copyright (c) [2024-2026] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -130,7 +130,7 @@ def convert_volume_groups(targets)
# @return [Configs::VolumeGroup]
def convert_volume_group(volume_group_model, targets)
FromModelConversions::VolumeGroup
.new(volume_group_model, targets, model_json[:encryption])
.new(volume_group_model, product_config, targets, model_json[:encryption])
.convert
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
require "agama/storage/config_conversions/from_model_conversions/base"
require "agama/storage/config_conversions/from_model_conversions/with_encryption"
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/config_conversions/from_model_conversions/with_volumes"
require "agama/storage/configs/drive"

module Agama
Expand All @@ -36,7 +36,7 @@ class Drive < Base
include WithEncryption
include WithFilesystem
include WithPtableType
include WithPartitions
include WithVolumes
include WithSearch

# @param model_json [Hash]
Expand Down Expand Up @@ -72,7 +72,7 @@ def conversions
encryption: convert_encryption,
filesystem: convert_filesystem,
ptable_type: convert_ptable_type,
partitions: convert_partitions(encryption_model)
partitions: convert_volumes(encryption_model)
}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# 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_delete"
require "agama/storage/config_conversions/from_model_conversions/with_filesystem"
require "agama/storage/config_conversions/from_model_conversions/with_size"
require "agama/storage/config_conversions/from_model_conversions/with_search"
Expand All @@ -32,6 +33,7 @@ module ConfigConversions
module FromModelConversions
# Logical volume conversion from model according to the JSON schema.
class LogicalVolume < Base
include WithDelete
include WithFilesystem
include WithSize
include WithSearch
Expand All @@ -50,12 +52,14 @@ def default_config
# @return [Hash]
def conversions
{
name: logical_volume_model[:lvName],
search: convert_search,
filesystem: convert_filesystem,
size: convert_size,
stripes: logical_volume_model[:stripes],
stripe_size: convert_stripe_size
name: logical_volume_model[:lvName],
search: convert_search,
filesystem: convert_filesystem,
size: convert_size,
stripes: logical_volume_model[:stripes],
stripe_size: convert_stripe_size,
delete: convert_delete,
delete_if_needed: convert_delete_if_needed
}
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2025] SUSE LLC
# Copyright (c) [2025-2026] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -22,9 +22,9 @@
require "agama/storage/config_conversions/from_model_conversions/base"
require "agama/storage/config_conversions/from_model_conversions/with_encryption"
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/config_conversions/from_model_conversions/with_volumes"
require "agama/storage/configs/md_raid"

module Agama
Expand All @@ -36,7 +36,7 @@ class MdRaid < Base
include WithEncryption
include WithFilesystem
include WithPtableType
include WithPartitions
include WithVolumes
include WithSearch

# @param model_json [Hash]
Expand Down Expand Up @@ -72,7 +72,7 @@ def conversions
encryption: convert_encryption,
filesystem: convert_filesystem,
ptable_type: convert_ptable_type,
partitions: convert_partitions(encryption_model)
partitions: convert_volumes(encryption_model)
}
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2024-2025] SUSE LLC
# Copyright (c) [2024-2026] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -20,6 +20,7 @@
# 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_delete"
require "agama/storage/config_conversions/from_model_conversions/with_encryption"
require "agama/storage/config_conversions/from_model_conversions/with_filesystem"
require "agama/storage/config_conversions/from_model_conversions/with_search"
Expand All @@ -33,6 +34,7 @@ module ConfigConversions
module FromModelConversions
# Partition conversion from model according to the JSON schema.
class Partition < Base
include WithDelete
include WithSearch
include WithEncryption
include WithFilesystem
Expand Down Expand Up @@ -79,24 +81,6 @@ def convert_id

Y2Storage::PartitionId.find(value)
end

# TODO: do not delete if the partition is used by other device (VG, RAID, etc).
# @return [Boolean]
def convert_delete
# Do not mark to delete if the partition is used.
return false if partition_model[:mountPath]

partition_model[:delete]
end

# TODO: do not delete if the partition is used by other device (VG, RAID, etc).
# @return [Boolean]
def convert_delete_if_needed
# Do not mark to delete if the partition is used.
return false if partition_model[:mountPath]

partition_model[:deleteIfNeeded]
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
# 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/logical_volume"
require "agama/storage/config_conversions/from_model_conversions/encryption"
require "agama/storage/config_conversions/from_model_conversions/with_search"
require "agama/storage/config_conversions/from_model_conversions/with_volumes"
require "agama/storage/configs/volume_group"
require "y2storage/disk_size"

Expand All @@ -33,12 +33,15 @@ module FromModelConversions
# Volume group conversion from model according to the JSON schema.
class VolumeGroup < Base
include WithSearch
include WithVolumes

# @param model_json [Hash]
# @param product_config [Agama::Config]
# @param targets [Array<Configs::Drive, Configs::MdRaid>]
# @param encryption_model [Hash, nil]
def initialize(model_json, targets, encryption_model = nil)
def initialize(model_json, product_config, targets, encryption_model = nil)
super(model_json)
@product_config = product_config
@targets = targets
@encryption_model = encryption_model
end
Expand All @@ -47,6 +50,9 @@ def initialize(model_json, targets, encryption_model = nil)

alias_method :volume_group_model, :model_json

# @return [Agama::Config]
attr_reader :product_config

# @return [Array<Configs::Drive, Configs::MdRaid>]
attr_reader :targets

Expand All @@ -68,7 +74,7 @@ def conversions
extent_size: convert_extent_size,
physical_volumes_devices: convert_physical_volumes_devices,
physical_volumes_encryption: convert_physical_volumes_encryption,
logical_volumes: convert_logical_volumes
logical_volumes: convert_volumes
}
end

Expand Down Expand Up @@ -97,14 +103,6 @@ def convert_physical_volumes_encryption
FromModelConversions::Encryption.new(encryption_model).convert
end

# @return [Array<Configs::LogicalVolume>, nil]
def convert_logical_volumes
logical_volumes_model = volume_group_model[:logicalVolumes]
return unless logical_volumes_model

logical_volumes_model.map { |l| FromModelConversions::LogicalVolume.new(l).convert }
end

# @param name [String]
# @return [Configs::Drive, Configs::MdRaid, nil]
def target(name)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

# Copyright (c) [2026] 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
# Mixin for delete properties conversion.
module WithDelete
# TODO: do not delete if the volume is used by other device (VG, RAID, etc).
# @return [Boolean]
def convert_delete
# Do not mark to delete if the volume is used.
return false if model_json[:mountPath]

model_json[:delete]
end

# TODO: do not delete if the volume is used by other device (VG, RAID, etc).
# @return [Boolean]
def convert_delete_if_needed
# Do not mark to delete if the volume is used.
return false if model_json[:mountPath]

model_json[:deleteIfNeeded]
end
end
end
end
end
end
Loading
Loading