Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Nov 18, 2024
1 parent f27e7c6 commit 4ac41ca
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 41 deletions.
4 changes: 2 additions & 2 deletions service/lib/agama/storage/config_conversions/to_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
module Agama
module Storage
module ConfigConversions
# Config conversion to JSON hash according to model schema.
# Config conversion to model according to the JSON schema.
class ToModel
# @param config [Storage::Config]
def initialize(config)
@config = config
end

# Performs the conversion to Hash according to the JSON model schema.
# Performs the conversion to config model according to the JSON schema.
#
# @return [Hash]
def convert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,18 @@
# 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/boot"
require "agama/storage/config_conversions/from_model_conversions/config"
# require "agama/storage/config_conversions/from_json_conversions/drive"
# require "agama/storage/config_conversions/from_json_conversions/encryption"
# require "agama/storage/config_conversions/from_json_conversions/encryption_properties"
# require "agama/storage/config_conversions/from_json_conversions/filesystem"
# require "agama/storage/config_conversions/from_json_conversions/logical_volume"
# require "agama/storage/config_conversions/from_json_conversions/partition"
# require "agama/storage/config_conversions/from_json_conversions/search"
# require "agama/storage/config_conversions/from_json_conversions/size"
# require "agama/storage/config_conversions/from_json_conversions/volume_group"
require "agama/storage/config_conversions/to_model_conversions/base"
require "agama/storage/config_conversions/to_model_conversions/config"
require "agama/storage/config_conversions/to_model_conversions/drive"
require "agama/storage/config_conversions/to_model_conversions/filesystem"
require "agama/storage/config_conversions/to_model_conversions/partition"
require "agama/storage/config_conversions/to_model_conversions/size"
require "agama/storage/config_conversions/to_model_conversions/space_policy"

module Agama
module Storage
module ConfigConversions
# Conversions to JSON according to model schema.
# Conversions to model according to the JSON schema.
module ToModelConversions
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module Agama
module Storage
module ConfigConversions
module ToModelConversions
# Base class for conversions to JSON hash according to schema.
# Base class for conversions to model according to the JSON schema.
class Base
# Defines the expected config type to perform the conversion.
#
Expand All @@ -41,7 +41,7 @@ def initialize(config)
@config = config
end

# Performs the conversion to Hash according to the JSON schema.
# Performs the conversion to model according to the JSON schema.
#
# @return [Hash, nil]
def convert
Expand All @@ -61,7 +61,7 @@ def convert
# @return [Object] The config type is provided by the {.config_type} method.
attr_reader :config

# Values to generate the JSON.
# Values to generate the model.
#
# @return [Hash] e.g., { name: "/dev/vda" }.
def conversions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@

require "agama/storage/config"
require "agama/storage/config_conversions/to_model_conversions/base"
# require "agama/storage/config_conversions/to_json_conversions/boot"
require "agama/storage/config_conversions/to_model_conversions/drive"
# require "agama/storage/config_conversions/to_json_conversions/volume_group"

module Agama
module Storage
module ConfigConversions
module ToModelConversions
# Config conversion to JSON hash according to model schema.
# Config conversion to model according to the JSON schema.
class Config < Base
# @see Base
def self.config_type
Expand All @@ -48,6 +46,7 @@ def convert_drives
valid_drives.map { |d| ToModelConversions::Drive.new(d).convert }
end

# @return [Array<Configs::Drive>]
def valid_drives
config.drives.select(&:found_device)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,20 @@
# find current contact information at www.suse.com.

require "agama/storage/config_conversions/to_model_conversions/base"
# require "agama/storage/config_conversions/to_json_conversions/with_encryption"
require "agama/storage/config_conversions/to_model_conversions/with_filesystem"
require "agama/storage/config_conversions/to_model_conversions/with_space_policy"
require "agama/storage/config_conversions/to_model_conversions/with_partitions"
# require "agama/storage/config_conversions/to_json_conversions/with_ptable_type"
# require "agama/storage/config_conversions/to_json_conversions/with_search"
require "agama/storage/config_conversions/to_model_conversions/with_space_policy"
require "agama/storage/configs/drive"

module Agama
module Storage
module ConfigConversions
module ToModelConversions
# Drive conversion to JSON hash according to schema.
# Drive conversion to model according to the JSON schema.
class Drive < Base
# include WithSearch
# include WithEncryption
include WithFilesystem
include WithSpacePolicy
# include WithPtableType
include WithPartitions
include WithSpacePolicy

# @see Base
def self.config_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Agama
module Storage
module ConfigConversions
module ToModelConversions
# Drive conversion to JSON hash according to schema.
# Drive conversion to model according to the JSON schema.
class Filesystem < Base
# @see Base
def self.config_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module Agama
module Storage
module ConfigConversions
module ToModelConversions
# Partition conversion to JSON hash according to schema.
# Partition conversion to model according to the JSON schema.
class Partition < Base
include WithFilesystem
include WithSize
Expand Down Expand Up @@ -56,12 +56,14 @@ def conversions
}
end

# @return [Booelan]
def convert_resize
size = config.size

!size.nil? && !size.default? && size.min == size.max
end

# @return [Booelan]
def convert_resize_if_needed
size = config.size

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Agama
module Storage
module ConfigConversions
module ToModelConversions
# Size conversion to JSON hash according to schema.
# Size conversion to model according to the JSON schema.
class Size < Base
# @see Base
def self.config_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ module Agama
module Storage
module ConfigConversions
module ToModelConversions
# Drive conversion to JSON hash according to schema.
# Space policy conversion to model according to the JSON schema.
class SpacePolicy
# TODO: make it work with volume groups and raids too?
# TODO: make it work with volume groups and raids too.
#
# @param config [Configs::Drive]
def initialize(config)
@config = config
end

# @return [String]
def convert
return "delete" if config.filesystem || delete_all_partition?
return "resize" if shrink_all_partition?
Expand All @@ -42,39 +43,50 @@ def convert

private

# @return [Configs::Drive]
attr_reader :config

# @return [Boolean]
def delete_all_partition?
config.partitions.any? { |p| delete_all?(p) }
end

# @return [Boolean]
def shrink_all_partition?
config.partitions.any? { |p| shrink_all?(p) }
end

# @return [Boolean]
def delete_partition?
config.partitions
.select(&:found_device)
.any? { |p| p.delete? || p.delete_if_needed? }
end

# @return [Boolean]
def resize_partition?
config.partitions
.select(&:found_device)
.any? { |p| !p.size.default? }
end

# @param partition_config [Configs::Partition]
# @return [Boolean]
def delete_all?(partition_config)
search_all?(partition_config) && partition_config.delete?
end

# @param partition_config [Configs::Partition]
# @return [Boolean]
def shrink_all?(partition_config)
search_all?(partition_config) &&
!partition_config.size.nil? &&
!partition_config.size.min.nil? &&
partition_config.size.min.to_i == 0
end

# @param partition_config [Configs::Partition]
# @return [Boolean]
def search_all?(partition_config)
!partition_config.search.nil? &&
partition_config.search.always_match? &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Agama
module Storage
module ConfigConversions
module ToModelConversions
# Mixin for filesystem conversion to JSON.
# Mixin for filesystem conversion to model according to the JSON schema.
module WithFilesystem
# @return [Hash, nil]
def convert_filesystem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Agama
module Storage
module ConfigConversions
module ToModelConversions
# Mixin for partitions conversion to JSON.
# Mixin for partitions conversion to model according to the JSON schema.
module WithPartitions
# @return [Array<Hash>]
def convert_partitions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Agama
module Storage
module ConfigConversions
module ToModelConversions
# Mixin for size conversion to JSON.
# Mixin for size conversion to model according to the JSON schema.
module WithSize
# @return [Hash, nil]
def convert_size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ module Agama
module Storage
module ConfigConversions
module ToModelConversions
# Mixin for filesystem conversion to JSON.
# Mixin for space policy conversion to model according to the JSON schema.
module WithSpacePolicy
# @return [Hash, nil]
# @return [String, nil]
def convert_space_policy
return unless config.respond_to?(:partitions)

Expand Down
1 change: 1 addition & 0 deletions service/lib/agama/storage/configs/filesystem_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
module Agama
module Storage
module Configs
# Config for a filesystem type.
class FilesystemType
# @return [Boolean]
attr_accessor :default
Expand Down
2 changes: 1 addition & 1 deletion service/lib/agama/storage/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def storage_json(solved: false)
end
end

# Config model according to the model JSON schema.
# Config model according to the JSON schema.
#
# @return [Hash, nil] nil if there is no config.
def model_json
Expand Down

0 comments on commit 4ac41ca

Please sign in to comment.