-
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.
- Loading branch information
1 parent
a4ed02e
commit 1047992
Showing
11 changed files
with
458 additions
and
26 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
51 changes: 51 additions & 0 deletions
51
service/lib/agama/storage/config_conversions/to_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,51 @@ | ||
# 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/to_model_conversions/base" | ||
require "agama/storage/configs/filesystem" | ||
|
||
module Agama | ||
module Storage | ||
module ConfigConversions | ||
module ToModelConversions | ||
# Drive conversion to JSON hash according to schema. | ||
class Filesystem < Base | ||
# @see Base | ||
def self.config_type | ||
Configs::Filesystem | ||
end | ||
|
||
private | ||
|
||
# @see Base#conversions | ||
def conversions | ||
{ | ||
# TODO | ||
default: false, | ||
type: config.type&.fs_type&.to_s, | ||
snapshots: config.btrfs_snapshots? | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
62 changes: 62 additions & 0 deletions
62
service/lib/agama/storage/config_conversions/to_model_conversions/partition.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,62 @@ | ||
# 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/to_model_conversions/base" | ||
# require "agama/storage/config_conversions/to_model_conversions/with_encryption" | ||
require "agama/storage/config_conversions/to_model_conversions/with_filesystem" | ||
require "agama/storage/configs/partition" | ||
|
||
module Agama | ||
module Storage | ||
module ConfigConversions | ||
module ToModelConversions | ||
# Partition conversion to JSON hash according to schema. | ||
class Partition < Base | ||
# include WithEncryption | ||
include WithFilesystem | ||
|
||
# @see Base | ||
def self.config_type | ||
Configs::Partition | ||
end | ||
|
||
private | ||
|
||
# @see Base#conversions | ||
def conversions | ||
{ | ||
name: config.found_device&.name, | ||
alias: config.alias, | ||
id: config.id&.to_s, | ||
mountPath: config.filesystem&.path, | ||
filesystem: convert_filesystem, | ||
# size: convert_size, | ||
delete: config.delete?, | ||
deleteIfNeeded: config.delete_if_needed?, | ||
# resize: convert_resize, | ||
# resizeIfNeeded: convert_resize_if_needed | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
82 changes: 82 additions & 0 deletions
82
service/lib/agama/storage/config_conversions/to_model_conversions/space_policy.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,82 @@ | ||
# 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 ToModelConversions | ||
# Drive conversion to JSON hash according to schema. | ||
class SpacePolicy | ||
# TODO: make it work with volume groups and raids too? | ||
# | ||
# @param config [Configs::Drive] | ||
def initialize(config) | ||
@config = config | ||
end | ||
|
||
def convert | ||
return "delete" if config.filesystem || delete_all_partition? | ||
return "resize" if shrink_all_partition? | ||
return "custom" if delete_partition? || resize_partition? | ||
|
||
"keep" | ||
end | ||
|
||
private | ||
|
||
attr_reader :config | ||
|
||
def delete_all_partition? | ||
config.partitions | ||
.select(&:delete?) | ||
.any? { |p| search_all?(p) } | ||
end | ||
|
||
def shrink_all_partition? | ||
config.partitions.any? { |p| shrink_all?(p) } | ||
end | ||
|
||
def delete_partition? | ||
config.partitions | ||
.select(&:found_device) | ||
.any? { |p| p.delete? || p.delete_if_needed? } | ||
end | ||
|
||
def resize_partition? | ||
config.partitions | ||
.select(&:found_device) | ||
.any? { |p| !p.size.default? } | ||
end | ||
|
||
def search_all?(partition_config) | ||
partition_config.search && | ||
partition_config.search.always_match? && | ||
partition_config.search.max.nil? | ||
end | ||
|
||
def shrink_all?(partition_config) | ||
partition_config.size && partition_config.size.min.to_i == 0 | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
41 changes: 41 additions & 0 deletions
41
service/lib/agama/storage/config_conversions/to_model_conversions/with_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,41 @@ | ||
# 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/to_model_conversions/filesystem" | ||
|
||
module Agama | ||
module Storage | ||
module ConfigConversions | ||
module ToModelConversions | ||
# Mixin for filesystem conversion to JSON. | ||
module WithFilesystem | ||
# @return [Hash, nil] | ||
def convert_filesystem | ||
filesystem = config.filesystem | ||
return unless filesystem | ||
|
||
ToModelConversions::Filesystem.new(filesystem).convert | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
53 changes: 53 additions & 0 deletions
53
service/lib/agama/storage/config_conversions/to_model_conversions/with_partitions.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,53 @@ | ||
# 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/to_model_conversions/partition" | ||
|
||
module Agama | ||
module Storage | ||
module ConfigConversions | ||
module ToModelConversions | ||
# Mixin for partitions conversion to JSON. | ||
module WithPartitions | ||
# @return [Array<Hash>] | ||
def convert_partitions | ||
valid_partitions | ||
.map { |p| ToModelConversions::Partition.new(p).convert } | ||
.compact | ||
end | ||
|
||
def valid_partitions | ||
partitions_to_create + partitions_to_reuse | ||
end | ||
|
||
def partitions_to_create | ||
config.partitions.reject(&:search) + | ||
config.partitions.select { |p| p.search&.create_device? } | ||
end | ||
|
||
def partitions_to_reuse | ||
config.partitions.select(&:found_device) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
40 changes: 40 additions & 0 deletions
40
service/lib/agama/storage/config_conversions/to_model_conversions/with_space_policy.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,40 @@ | ||
# 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/to_model_conversions/space_policy" | ||
|
||
module Agama | ||
module Storage | ||
module ConfigConversions | ||
module ToModelConversions | ||
# Mixin for filesystem conversion to JSON. | ||
module WithSpacePolicy | ||
# @return [Hash, nil] | ||
def convert_space_policy | ||
return unless config.respond_to?(:partitions) | ||
|
||
ToModelConversions::SpacePolicy.new(config).convert | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.