Skip to content

Commit

Permalink
Merge 768bbb5 into 4e50ce4
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed May 17, 2020
2 parents 4e50ce4 + 768bbb5 commit 58ba895
Show file tree
Hide file tree
Showing 19 changed files with 659 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/lib/autoinstall/presenters/drive_type.rb
Expand Up @@ -44,9 +44,11 @@ def initialize(id, label)
LVM = new(:CT_LVM, N_("LVM")).freeze
# DriveType for CT_RAID
RAID = new(:CT_RAID, N_("RAID")).freeze
# DriveType for CT_BCACHE
BCACHE = new(:CT_BCACHE, N_("bcache")).freeze

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

# All possible types
#
Expand Down
13 changes: 13 additions & 0 deletions src/lib/autoinstall/presenters/partition.rb
Expand Up @@ -49,6 +49,8 @@ def usage
:lvm_pv
elsif filesystem || mounted?
:filesystem
elsif bcache_backing_for
:bcache_backing
else
:none
end
Expand Down Expand Up @@ -79,6 +81,14 @@ def drive_type
drive_presenter.type
end

# Values to suggest for bcache devices fields
#
# @return [Array<String>]
def available_bcaches
drives = drive.parent.drives.select { |d| d.type == :CT_BCACHE }
drives.map(&:device).compact
end

# Values to suggest for the lvm_group field
#
# @return [Array<String>]
Expand Down Expand Up @@ -153,6 +163,9 @@ def usage_label
when :lvm_pv
# TRANSLATORS: %s is a placeholder for the name of a RAID
Kernel.format(_("Part of %s"), lvm_group)
when :bcache_backing
# TRANSLATORS: %s is a placeholder for the name of a bcache device
Kernel.format(_("Backing for %s"), bcache_backing_for)
when :none
_("Not used")
end
Expand Down
78 changes: 78 additions & 0 deletions src/lib/autoinstall/widgets/storage/bcache_backing_attrs.rb
@@ -0,0 +1,78 @@
# 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/bcache_backing_for"

module Y2Autoinstallation
module Widgets
module Storage
# Bcache backing device attributes
#
# It groups those attributes that are specific for a partition being used as a bcache backing
# device.
#
# @see PartitionUsageTab
class BcacheBackingAttrs < 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, backing_for_widget)))
end

# @macro seeAbstractWidget
def init
backing_for_widget.items = section.available_bcaches
backing_for_widget.value = section.bcache_backing_for
end

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

private

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

# Widget for setting the bcache backing device
def backing_for_widget
@backing_for_widget ||= BcacheBackingFor.new
end
end
end
end
end
50 changes: 50 additions & 0 deletions src/lib/autoinstall/widgets/storage/bcache_backing_for.rb
@@ -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 bcache device which is going to be backed
class BcacheBackingFor < CWM::ComboBox
def initalize
textdomain "autoinst"
super
end

# @macro seeAbstractWidget
def label
_("Device")
end

# @macro seeAbstractWidget
def opt
[:editable]
end

def items=(devices)
values = [["", ""]] + devices.map { |i| [i, i] }
change_items(values)
end
end
end
end
end
40 changes: 40 additions & 0 deletions src/lib/autoinstall/widgets/storage/bcache_device.rb
@@ -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 bcache device
class BcacheDevice < CWM::InputField
def initalize
textdomain "autoinst"
super
end

# @macro seeAbstractWidget
def label
_("Device")
end
end
end
end
end
82 changes: 82 additions & 0 deletions src/lib/autoinstall/widgets/storage/bcache_page.rb
@@ -0,0 +1,82 @@
# 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/bcache_device"
require "autoinstall/widgets/storage/cache_mode"

module Y2Autoinstallation
module Widgets
module Storage
# This page allows to edit a drive section representing a bcache device
class BcachePage < DrivePage
# @see DrivePage#initialize
def initialize(*args)
textdomain "autoinst"
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()
)
)
end

# @macro seeAbstractWidget
def init
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
{
"device" => device_widget.value,
"bcache_options" => {
"cache_mode" => cache_mode_widget.value
}
}
end

private

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

# Widget for setting the cache mode
def cache_mode_widget
@cache_mode_widget ||= CacheMode.new
end
end
end
end
end
49 changes: 49 additions & 0 deletions src/lib/autoinstall/widgets/storage/cache_mode.rb
@@ -0,0 +1,49 @@
# 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"
require "y2storage"

module Y2Autoinstallation
module Widgets
module Storage
# Widget to select the bcache cache mode
#
# It's part of the bcache_options attribute for a bcache drive section of an AutoYaST profile.
class CacheMode < CWM::ComboBox
# Constructor
def initialize
textdomain "autoinst"
super()
end

# @macro seeAbstractWidget
def label
_("Cache Mode")
end

# @macro seeComboBox
def items
Y2Storage::CacheMode.all.map { |i| [i.to_s, i.to_s] }
end
end
end
end
end
1 change: 1 addition & 0 deletions src/lib/autoinstall/widgets/storage/overview_tree_pager.rb
Expand Up @@ -23,6 +23,7 @@
require "autoinstall/widgets/storage/disk_page"
require "autoinstall/widgets/storage/raid_page"
require "autoinstall/widgets/storage/lvm_page"
require "autoinstall/widgets/storage/bcache_page"
require "autoinstall/widgets/storage/partition_page"
require "autoinstall/widgets/storage/add_drive_button"
require "autoinstall/widgets/storage/add_partition_button"
Expand Down
7 changes: 7 additions & 0 deletions src/lib/autoinstall/widgets/storage/partition_usage_tab.rb
Expand Up @@ -24,6 +24,7 @@
require "autoinstall/widgets/storage/filesystem_attrs"
require "autoinstall/widgets/storage/raid_attrs"
require "autoinstall/widgets/storage/lvm_pv_attrs"
require "autoinstall/widgets/storage/bcache_backing_attrs"
require "autoinstall/widgets/storage/lvm_partition_attrs"
require "autoinstall/widgets/storage/encryption_attrs"
require "autoinstall/widgets/storage/size_selector"
Expand Down Expand Up @@ -105,6 +106,7 @@ def relevant_widgets
filesystem_widget,
raid_widget,
lvm_pv_widget,
bcache_backing_widget,
encryption_widget
]
end
Expand All @@ -124,6 +126,11 @@ def lvm_pv_widget
@lvm_pv_widget ||= LvmPvAttrs.new(partition)
end

# Widget grouping attributes related to a bcache backing device
def bcache_backing_widget
@bcache_backing_widget ||= BcacheBackingAttrs.new(partition)
end

# Widget for setting encryption related attributes
def encryption_widget
@encryption_widget ||= EncryptionAttrs.new(partition)
Expand Down
5 changes: 3 additions & 2 deletions src/lib/autoinstall/widgets/storage/used_as.rb
Expand Up @@ -54,9 +54,10 @@ def items
# TRANSLATORS: option for setting the partition as a RAID member
[:raid, _("RAID member")],
# TRANSLATORS: option for setting the partition as an LVM physical volume
[:lvm_pv, _("LVM physical volume")]
[:lvm_pv, _("LVM physical volume")],
# TRANSLATORS: option for setting the partition as a bcache backing device
[:bcache_backing, _("Bcache backing device")]
# ["bcache_caching", _("Bcache caching device")],
# ["bcache_backing", _("Bcache backing device")],
# ["btrfs_member", _("Btrfs multi-device member")]
]
end
Expand Down

0 comments on commit 58ba895

Please sign in to comment.