Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Jun 26, 2024
1 parent 655abab commit f515b56
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions service/lib/agama/storage/proposal_settings_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def self.to_y2storage(settings, config:)
ToY2Storage.new(settings, config: config).convert
end

# Performs conversion from Hash according to JSON schema.
# Performs conversion from Hash according to the JSON schema.
#
# @param schema_settings [Hash]
# @param config [Agama::Config]
Expand All @@ -58,7 +58,7 @@ def self.from_schema(schema_settings, config:)
FromSchema.new(schema_settings, config: config).convert
end

# Performs conversion according to JSON schema.
# Performs conversion according to the JSON schema.
#
# @param settings [Agama::Storage::ProposalSettings]
# @return [Hash]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@
module Agama
module Storage
module ProposalSettingsConversion
# Proposal settings conversion from Hash according to JSON schema.
# Proposal settings conversion from Hash according to the JSON schema.
class FromSchema
# @param schema_settings [Hash]
# @param config [Agama::Config]
# @param config [Config]
def initialize(schema_settings, config:)
# @todo Raise error if schema_settings does not match the JSON schema.
@schema_settings = schema_settings
@config = config
end

# Performs the conversion from Hash according to JSON schema.
# Performs the conversion from Hash according to the JSON schema.
#
# @return [Agama::Storage::ProposalSettings]
# @return [ProposalSettings]
def convert
device_settings = target_conversion
boot_settings = boot_conversion
Expand All @@ -65,7 +65,7 @@ def convert
# @return [Hash]
attr_reader :schema_settings

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

def target_conversion
Expand Down Expand Up @@ -124,6 +124,7 @@ def space_conversion
end
end

# @param action [Hash]
def action_conversion(action)
return action.invert unless action[:forceDelete]

Expand All @@ -141,10 +142,10 @@ def volumes_conversion

# Adds the missing required volumes to the list of volumes.
#
# @param volumes [Array<Agama::Storage::Volume>]
# @param default_volumes [Array<Agama::Storage::Volume>] volumes includes required ones.
# @param volumes [Array<Volume>]
# @param default_volumes [Array<Volume>] Default volumes including the required ones.
#
# @return [Array<Agama::Storage::Volume>]
# @return [Array<Volume>]
def add_required_volumes(volumes, default_volumes)
mount_paths = volumes.map(&:mount_path)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
module Agama
module Storage
module ProposalSettingsConversion
# Proposal settings conversion according to JSON schema.
# Proposal settings conversion according to the JSON schema.
class ToSchema
# @param settings [Agama::Storage::ProposalSettings]
# @param settings [ProposalSettings]
def initialize(settings)
@settings = settings
end

# Performs the conversion according to JSON schema.
# Performs the conversion according to the JSON schema.
#
# @return [Hash]
def convert
Expand All @@ -49,7 +49,7 @@ def convert

private

# @return [Agama::Storage::ProposalSettings]
# @return [ProposalSettings]
attr_reader :settings

def target_conversion
Expand Down
4 changes: 2 additions & 2 deletions service/lib/agama/storage/volume_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def self.to_y2storage(volume)
ToY2Storage.new(volume).convert
end

# Performs conversion from Hash according to JSON schema.
# Performs conversion from Hash according to the JSON schema.
#
# @param volume_schema [Hash]
# @param config [Agama::Config]
Expand All @@ -54,7 +54,7 @@ def self.from_schema(volume_schema, config:)
FromSchema.new(volume_schema, config: config).convert
end

# Performs conversion according to JSON schema.
# Performs conversion according to the JSON schema.
#
# @param volume [Agama::Storage::Volume]
# @return [Hash]
Expand Down
11 changes: 7 additions & 4 deletions service/lib/agama/storage/volume_conversion/from_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
module Agama
module Storage
module VolumeConversion
# Volume conversion from Hash according to JSON schema.
# Volume conversion from Hash according to the JSON schema.
class FromSchema
# @param volume_schema [Hash]
# @param config [Agama::Config]
# @param config [Config]
def initialize(volume_schema, config:)
# @todo Raise error if volume_schema does not match the JSON schema.
@volume_schema = volume_schema
@config = config
end

# Performs the conversion from Hash according to JSON schema.
# Performs the conversion from Hash according to the JSON schema.
#
# @return [Agama::Storage::Volume]
# @return [Volume]
def convert
default_volume.tap do |volume|
mount_conversion(volume)
Expand All @@ -57,6 +57,7 @@ def convert
# @return [Agama::Config]
attr_reader :config

# @param volume [Volume]
def mount_conversion(volume)
path_value = volume_schema.dig(:mount, :path)
options_value = volume_schema.dig(:mount, :options)
Expand All @@ -65,6 +66,7 @@ def mount_conversion(volume)
volume.mount_options = options_value if options_value
end

# @param volume [Volume]
def filesystem_conversion(volume)
filesystem_schema = volume_schema[:filesystem]
return unless filesystem_schema
Expand Down Expand Up @@ -97,6 +99,7 @@ def filesystem_hash_conversion(volume, filesystem)
end

# @todo Support array format ([min, max]) and string format ("2 GiB")
# @param volume [Volume]
def size_conversion(volume)
size_schema = volume_schema[:size]
return unless size_schema
Expand Down
8 changes: 4 additions & 4 deletions service/lib/agama/storage/volume_conversion/to_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
module Agama
module Storage
module VolumeConversion
# Volume conversion according to JSON schema.
# Volume conversion according to the JSON schema.
class ToSchema
# @param volume [Agama::Storage::Volume]
# @param volume [Volume]
def initialize(volume)
@volume = volume
end

# Performs the conversion according to JSON schema.
# Performs the conversion according to the JSON schema.
#
# @return [Hash]
def convert
Expand All @@ -49,7 +49,7 @@ def convert

private

# @return [Agama::Storage::Volume]
# @return [Volume]
attr_reader :volume

def mount_conversion
Expand Down

0 comments on commit f515b56

Please sign in to comment.