Skip to content

Commit

Permalink
Merge pull request #610 from yast/btrfs_storage_ui
Browse files Browse the repository at this point in the history
[Storage-UI] Add Btrfs options
  • Loading branch information
dgdavid committed May 19, 2020
2 parents ae3a4ed + dbc076d commit dfc98bc
Show file tree
Hide file tree
Showing 36 changed files with 1,257 additions and 107 deletions.
4 changes: 3 additions & 1 deletion src/lib/autoinstall/presenters/drive_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ def initialize(id, label)
RAID = new(:CT_RAID, N_("RAID")).freeze
# DriveType for CT_BCACHE
BCACHE = new(:CT_BCACHE, N_("bcache")).freeze
# DriveType for CT_BTRFS
BTRFS = new(:CT_BTRFS, N_("Btrfs")).freeze

# All drive types
ALL = [DISK, RAID, LVM, BCACHE].freeze
ALL = [DISK, RAID, LVM, BCACHE, BTRFS].freeze

# All possible types
#
Expand Down
28 changes: 23 additions & 5 deletions src/lib/autoinstall/presenters/partition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def usage
:filesystem
elsif bcache_backing_for
:bcache_backing
elsif btrfs_name
:btrfs_member
else
:none
end
Expand Down Expand Up @@ -85,17 +87,21 @@ def drive_type
#
# @return [Array<String>]
def available_bcaches
drives = drive.parent.drives.select { |d| d.type == :CT_BCACHE }
drives.map(&:device).compact
devices_for(type: :CT_BCACHE)
end

# Values to suggest for Btrfs devices fields
#
# @return [Array<String>]
def available_btrfs
devices_for(type: :CT_BTRFS)
end

# Values to suggest for the lvm_group field
#
# @return [Array<String>]
def available_lvm_groups
vgs = drive.parent.drives.select { |d| d.type == :CT_LVM }
names = vgs.map(&:device).compact
names.map { |n| n.delete_prefix("/dev/") }
devices_for(type: :CT_LVM).map { |n| n.delete_prefix("/dev/") }
end

private
Expand All @@ -117,6 +123,15 @@ def device_name
lv_name
end

# Return available devices names of given type
#
# @param type [Symbol] the drive type to look for
# @return [Array<String>] available devices names
def devices_for(type:)
drives = drive.parent.drives.select { |d| d.type == type }
drives.map(&:device).compact
end

# Whether the partition has a mount point
#
# @return [Boolean] true when there is a not empty mount point; false otherwise
Expand Down Expand Up @@ -166,6 +181,9 @@ def usage_label
when :bcache_backing
# TRANSLATORS: %s is a placeholder for the name of a bcache device
Kernel.format(_("Backing for %s"), bcache_backing_for)
when :btrfs_member
# TRANSLATORS: %s is a placeholder for the name of a Btrfs filesystem
Kernel.format(_("Part of %s"), btrfs_name)
when :none
_("Not used")
end
Expand Down
28 changes: 10 additions & 18 deletions src/lib/autoinstall/widgets/storage/bcache_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,22 @@ def initialize(*args)
super
end

# @macro seeCustomWidget
def contents
MarginBox(
0.5,
0,
VBox(
Left(HSquash(MinWidth(15, device_widget))),
VSpacing(0.5),
Left(cache_mode_widget),
VStretch()
)
)
# @see DrivePage#widgets
def widgets
[
HSquash(MinWidth(15, device_widget)),
cache_mode_widget
]
end

# @macro seeAbstractWidget
def init
# @see DrivePage#init_widget_values
def init_widgets_values
device_widget.value = section.device
cache_mode_widget.value = section.bcache_options&.cache_mode
end

# Returns the widgets values
#
# @return [Hash<String,Object>]
def values
# @see DrivePage#widgets_values
def widgets_values
{
"device" => device_widget.value,
"bcache_options" => {
Expand Down
40 changes: 40 additions & 0 deletions src/lib/autoinstall/widgets/storage/btrfs_device.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) [2020] 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 "yast"
require "cwm/common_widgets"

module Y2Autoinstallation
module Widgets
module Storage
# Determines a Btrfs device
class BtrfsDevice < CWM::InputField
def initalize
textdomain "autoinst"
super
end

# @macro seeAbstractWidget
def label
_("Device")
end
end
end
end
end
77 changes: 77 additions & 0 deletions src/lib/autoinstall/widgets/storage/btrfs_member_attrs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright (c) [2020] 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 "yast"
require "cwm/custom_widget"
require "autoinstall/widgets/storage/btrfs_name"

module Y2Autoinstallation
module Widgets
module Storage
# Btrfs member attributes
#
# It groups those attributes that are specific for a partition being used as a Btrfs member.
#
# @see PartitionUsageTab
class BtrfsMemberAttrs < CWM::CustomWidget
# Constructor
#
# @param section [Presenters::Partition] presenter for the partition section
def initialize(section)
textdomain "autoinst"
super()
@section = section
end

# @macro seeAbstractWidget
def label
""
end

# @macro seeCustomWidget
def contents
Left(HSquash(MinWidth(15, btrfs_name_widget)))
end

# @macro seeAbstractWidget
def init
btrfs_name_widget.items = section.available_btrfs
btrfs_name_widget.value = section.btrfs_name
end

# Returns the widgets values
#
# @return [Hash<String,Object>]
def values
{ "btrfs_name" => btrfs_name_widget.value }
end

private

# @return [Presenters::Partition] presenter for the partition section
attr_reader :section

# Widget for setting the Btrfs multi-device filesystem
def btrfs_name_widget
@btrfs_name_widget ||= BtrfsName.new
end
end
end
end
end
50 changes: 50 additions & 0 deletions src/lib/autoinstall/widgets/storage/btrfs_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright (c) [2020] 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 "yast"
require "cwm/common_widgets"

module Y2Autoinstallation
module Widgets
module Storage
# Widget to specify the Btrfs multi-device filesystem in which the device will be included.
class BtrfsName < CWM::ComboBox
def initalize
textdomain "autoinst"
super
end

# @macro seeAbstractWidget
def label
_("Btrfs Name")
end

# @macro seeAbstractWidget
def opt
[:editable]
end

def items=(devices)
values = [["", ""]] + devices.map { |i| [i, i] }
change_items(values)
end
end
end
end
end
83 changes: 83 additions & 0 deletions src/lib/autoinstall/widgets/storage/btrfs_page.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright (c) [2020] 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 "yast"
require "autoinstall/widgets/storage/drive_page"
require "autoinstall/widgets/storage/btrfs_device"
require "autoinstall/widgets/storage/data_raid_level"
require "autoinstall/widgets/storage/metadata_raid_level"

module Y2Autoinstallation
module Widgets
module Storage
# This page allows to edit a drive section representing a Btrfs device
class BtrfsPage < DrivePage
# @see DrivePage#initialize
def initialize(*args)
textdomain "autoinst"
super
end

# @see DrivePage#widgets
def widgets
[
HSquash(MinWidth(15, device_widget)),
data_raid_level_widget,
metadata_raid_level_widget
]
end

# @see DrivePage#init_widgets_values
def init_widgets_values
device_widget.value = section.device
data_raid_level_widget.value = section.btrfs_options&.data_raid_level
metadata_raid_level_widget.value = section.btrfs_options&.metadata_raid_level
end

# @see DrivePage#widgets_values
def widgets_values
{
"device" => device_widget.value,
"btrfs_options" => {
"data_raid_level" => data_raid_level_widget.value,
"metadata_raid_level" => metadata_raid_level_widget.value
}
}
end

private

# Widget for setting the device
def device_widget
@device_widget ||= BtrfsDevice.new
end

# Widget for setting the data RAID level
def data_raid_level_widget
@data_raid_level_widget ||= DataRaidLevel.new
end

# Widget for setting the metadata RAID level
def metadata_raid_level_widget
@metadata_raid_level_widget ||= MetadataRaidLevel.new
end
end
end
end
end
Loading

0 comments on commit dfc98bc

Please sign in to comment.