Skip to content

Commit

Permalink
WIP: some starting point for AgamaProposal
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs committed Jul 17, 2024
1 parent 0b18f20 commit a24f1bc
Show file tree
Hide file tree
Showing 13 changed files with 1,166 additions and 0 deletions.
77 changes: 77 additions & 0 deletions service/lib/agama/storage/profile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# frozen_string_literal: true

# Copyright (c) [2022-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/boot_settings"

module Agama
module Storage
# Settings used to calculate an storage proposal.
class Profile
# Boot settings.
#
# @return [BootSettings]
attr_accessor :boot

attr_accessor :drives
attr_accessor :volume_groups
attr_accessor :md_raids
attr_accessor :btrfs_raids
attr_accessor :nfs_mounts

def initialize
@boot = BootSettings.new
@drives = []
@volume_groups = []
@md_raids = []
@btrfs_raids = []
@nfs_mounts = []
end

# Creates a new proposal settings object from JSON hash according to schema.
#
# @param settings_json [Hash]
# @param config [Config]
#
# @return [Settings]
def self.new_from_json(settings_json, config:)
Storage::SettingsConversions::FromJSON.new(settings_json).convert
end

# Generates a JSON hash according to schema.
#
# @return [Hash]
def to_json_settings
Storage::ProposalSettingsConversions::ToJSON.new(self).convert
end

private

# Device used for booting.
#
# @return [String, nil]
def boot_device
return nil unless boot.configure?

boot.device
end
end
end
end
55 changes: 55 additions & 0 deletions service/lib/agama/storage/settings/drive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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/settings/search"

module Agama
module Storage
module Settings
class Drive
attr_accessor :encrypt
attr_accessor :format
attr_accessor :mount
attr_accessor :ptable_type
attr_accessor :partitions

# @param mount_path [String]
def initialize
@partitions = []
end

def search_device(devicegraph, used_sids)
@search ||= default_search

search.find(self, devicegraph, used_sids)
end

def default_search
Search.new
end

def found_sid
search&.sid
end
end
end
end
end
35 changes: 35 additions & 0 deletions service/lib/agama/storage/settings/encrypt.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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 Settings
class Mount
attr_accessor :method
attr_accessor :key
attr_accessor :pbkd_function
attr_accessor :label
attr_accessor :cipher
attr_accessor :key_size
end
end
end
end
32 changes: 32 additions & 0 deletions service/lib/agama/storage/settings/format.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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 Settings
class Format
attr_accessor :filesystem
attr_accessor :label
attr_accessor :mkfs_options
end
end
end
end
36 changes: 36 additions & 0 deletions service/lib/agama/storage/settings/mount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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 Settings
class Mount
attr_accessor :path
attr_accessor :options
attr_accessor :mount_by

def initialize
@options = []
end
end
end
end
end
41 changes: 41 additions & 0 deletions service/lib/agama/storage/settings/partition.rb
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.

module Agama
module Storage
module Settings
class Partition
attr_accessor :id
attr_accessor :type
attr_accessor :size
attr_accessor :resize
attr_accessor :delete
attr_accessor :encrypt
attr_accessor :format
attr_accessor :mount

def search_device(devicegraph, parent_sid, used_sids)
search.find(self, devicegraph, used_sids, parent: parent_sid)
end
end
end
end
end
46 changes: 46 additions & 0 deletions service/lib/agama/storage/settings/search.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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 Settings
class Search
attr_reader :sid

def find(setting, devicegraph, used_sids, parent:)
devices = candidate_devices(setting, devicegraph, parent)
devices.reject! { |d| used_sids.include?(d.sid) }
@sid = devices.sort_by(&:name).first&.sid
end

def candidate_devices(setting, devicegraph, parent)
if setting.kind_of?(Drive)
devicegraph.blk_devices.select do |dev|
dev.is?(:disk_device, :stray_blk_device)
end
else
devicegraph.find_device(parent).partitions
end
end
end
end
end
end
31 changes: 31 additions & 0 deletions service/lib/agama/storage/settings/size_range.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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 Settings
class SizeRange
attr_accessor :min
attr_accessor :max
end
end
end
end
Loading

0 comments on commit a24f1bc

Please sign in to comment.