Skip to content

Commit

Permalink
Merge pull request #1138 from joseivanlopez/add_current_device
Browse files Browse the repository at this point in the history
Add current device to the tables
  • Loading branch information
joseivanlopez authored Sep 22, 2020
2 parents bf6daa8 + b9034c7 commit 24ec0af
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 187 deletions.
21 changes: 19 additions & 2 deletions src/lib/y2partitioner/widgets/pages/bcache.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) [2018] SUSE LLC
# Copyright (c) [2018-2020] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -18,6 +18,7 @@
# find current contact information at www.suse.com.

require "y2partitioner/icons"
require "y2partitioner/widgets/tabs"
require "y2partitioner/widgets/pages/base"
require "y2partitioner/widgets/pages/bcaches"
require "y2partitioner/widgets/bcache_description"
Expand All @@ -26,6 +27,8 @@
require "y2partitioner/widgets/device_delete_button"
require "y2partitioner/widgets/partition_table_add_button"
require "y2partitioner/widgets/partitions_tab"
require "y2partitioner/widgets/used_devices_tab"
require "y2partitioner/widgets/bcache_edit_button"

module Y2Partitioner
module Widgets
Expand Down Expand Up @@ -67,7 +70,8 @@ def contents
Left(
Tabs.new(
BcacheTab.new(device),
PartitionsTab.new(device, @pager)
PartitionsTab.new(device, @pager),
BcacheUsedDevicesTab.new(device, @pager)
)
)
)
Expand Down Expand Up @@ -120,6 +124,19 @@ def buttons
]
end
end

# A Tab for the used devices of a Bcache
class BcacheUsedDevicesTab < UsedDevicesTab
# @see UsedDevicesTab#used_devices
def used_devices
([device.backing_device] + device.bcache_cset.blk_devices).compact
end

# @see UsedDevicesTab#buttons
def buttons
Right(BcacheEditButton.new(device: device))
end
end
end
end
end
44 changes: 12 additions & 32 deletions src/lib/y2partitioner/widgets/pages/btrfs.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) [2017-2019] SUSE LLC
# Copyright (c) [2017-2020] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -18,21 +18,21 @@
# find current contact information at www.suse.com.

require "y2partitioner/icons"
require "y2partitioner/widgets/tabs"
require "y2partitioner/widgets/pages/base"
require "y2partitioner/widgets/pages/btrfs_filesystems"
require "y2partitioner/widgets/used_devices_tab"
require "y2partitioner/widgets/filesystem_description"
require "y2partitioner/widgets/btrfs_edit_button"
require "y2partitioner/widgets/used_devices_edit_button"
require "y2partitioner/widgets/device_delete_button"
require "y2partitioner/widgets/tabs"

module Y2Partitioner
module Widgets
module Pages
# Page for a BTRFS filesystem
#
# This page contains a {FilesystemTab} and a {UsedDevicesTab}.
# This page contains a {FilesystemTab} and a {BtrfsUsedDevicesTab}.
class Btrfs < Base
# @return [Y2Storage::Filesystems::Btrfs]
attr_reader :filesystem
Expand Down Expand Up @@ -103,7 +103,7 @@ def title
def tabs
tabs = [
FilesystemTab.new(filesystem, initial: true),
BtrfsDevicesTab.new(filesystem, pager)
BtrfsUsedDevicesTab.new(filesystem, pager)
]

Tabs.new(*tabs)
Expand Down Expand Up @@ -153,36 +153,16 @@ def buttons
end
end

# A Tab for the devices used by a Btrfs
class BtrfsDevicesTab < UsedDevicesTab
# Constructor
#
# @param filesystem [Y2Storage::Filesystems::Btrfs]
# @param pager [CWM::TreePager]
def initialize(filesystem, pager)
@filesystem = filesystem

super(devices, pager)
# A Tab for the used devices of a Btrfs
class BtrfsUsedDevicesTab < UsedDevicesTab
# @see UsedDevicesTab#used_devices
def used_devices
device.plain_blk_devices
end

# @macro seeCustomWidget
def contents
@contents ||= VBox(
table,
Right(UsedDevicesEditButton.new(device: filesystem))
)
end

private

# @return [Y2Storage::Filesystems::Btrfs]
attr_reader :filesystem

# Devices used by the filesystem
#
# @return [Array<Y2Storage::BlkDevice>]
def devices
filesystem.plain_blk_devices
# @see UsedDevicesTab#buttons
def buttons
Right(UsedDevicesEditButton.new(device: device))
end
end
end
Expand Down
30 changes: 13 additions & 17 deletions src/lib/y2partitioner/widgets/pages/disk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# find current contact information at www.suse.com.

require "y2partitioner/icons"
require "y2partitioner/widgets/tabs"
require "y2partitioner/widgets/pages/base"
require "y2partitioner/widgets/disk_device_description"
require "y2partitioner/widgets/used_devices_tab"
Expand All @@ -28,10 +29,10 @@
module Y2Partitioner
module Widgets
module Pages
# Page for a disk device (Disk, Dasd, BIOS RAID, Multipath or Bcache).
# Page for a disk device (Disk, Dasd, BIOS RAID or Multipath).
#
# This page contains a {DiskTab} and a {PartitionsTab}. In case of Multipath
# or BIOS RAID, it also contains a {UsedDevicesTab}.
# or BIOS RAID, it also contains a {DiskUsedDevicesTab}.
class Disk < Base
# @return [Y2Storage::BlkDevice] Disk device this page is about
attr_reader :disk
Expand All @@ -40,7 +41,7 @@ class Disk < Base
# Constructor
#
# @param disk [Y2Storage::Disk, Y2Storage::Dasd, Y2Storage::DmRaid,
# Y2Storage::MdMember, Y2Storage::Multipath, Y2Storage::Bcache]
# Y2Storage::MdMember, Y2Storage::Multipath]
# @param pager [CWM::TreePager]
def initialize(disk, pager)
textdomain "storage"
Expand Down Expand Up @@ -88,7 +89,7 @@ def tabs
PartitionsTab.new(disk, @pager)
]

tabs << UsedDevicesTab.new(used_devices, @pager) if used_devices_tab?
tabs << DiskUsedDevicesTab.new(disk, @pager) if used_devices_tab?

Tabs.new(*tabs)
end
Expand All @@ -99,19 +100,6 @@ def tabs
def used_devices_tab?
disk.is?(:multipath, :dm_raid, :md)
end

# Devices used by the RAID or Multipath
#
# @return [Array<BlkDevice>]
def used_devices
if disk.is?(:multipath, :dm_raid)
disk.parents
elsif disk.is?(:md)
disk.devices
else
[]
end
end
end

# A Tab for disk device description
Expand Down Expand Up @@ -159,6 +147,14 @@ def buttons
buttons
end
end

# A Tab for the used devices of a Multipath or BIOS RAID
class DiskUsedDevicesTab < UsedDevicesTab
# @see UsedDevicesTab#used_devices
def used_devices
device.is?(:multipath, :dm_raid) ? device.parents : []
end
end
end
end
end
64 changes: 14 additions & 50 deletions src/lib/y2partitioner/widgets/pages/lvm_vg.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) [2017] SUSE LLC
# Copyright (c) [2017-2020] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -17,8 +17,8 @@
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "y2partitioner/widgets/tabs"
require "y2partitioner/icons"
require "y2partitioner/widgets/tabs"
require "y2partitioner/widgets/pages/base"
require "y2partitioner/widgets/pages/lvm"
require "y2partitioner/widgets/configurable_blk_devices_table"
Expand All @@ -31,6 +31,7 @@
require "y2partitioner/widgets/device_delete_button"
require "y2partitioner/widgets/device_buttons_set"
require "y2partitioner/widgets/columns"
require "y2partitioner/widgets/used_devices_tab"

module Y2Partitioner
module Widgets
Expand Down Expand Up @@ -167,68 +168,31 @@ def table(buttons_set)
end

# Returns all logical volumes of a volume group, including thin pools
# and thin volumes
# and thin volumes. Note that it also includes the Volume Group.
#
# @see Y2Storage::LvmVg#all_lvm_lvs
#
# @return [Array<Y2Storage::LvmLv>]
# @return [Array<Y2Storage::LvmVg, Y2Storage::LvmLv>]
def devices
@lvm_vg.all_lvm_lvs
[@lvm_vg] + @lvm_vg.all_lvm_lvs
end
end

# A Tab for the LVM physical volumes of a volume group
class LvmPvTab < CWM::Tab
# Constructor
#
# @param lvm_vg [Y2Storage::Lvm_vg]
# @param pager [CWM::TreePager]
def initialize(lvm_vg, pager)
textdomain "storage"

@lvm_vg = lvm_vg
@pager = pager
end

# @macro seeAbstractWidget
class LvmPvTab < UsedDevicesTab
# @see UsedDevicesTab#label
def label
_("&Physical Volumes")
end

# @macro seeCustomWidget
def contents
# Page wants a WidgetTerm, not an AbstractWidget
@contents ||= VBox(
table,
Right(LvmVgResizeButton.new(device: @lvm_vg))
)
# @see UsedDevicesTab#used_devices
def used_devices
device.lvm_pvs.map(&:plain_blk_device)
end

private

# Returns a table with all physical volumes of a volume group
#
# @return [ConfigurableBlkDevicesTable]
def table
return @table unless @table.nil?

@table = ConfigurableBlkDevicesTable.new(devices, @pager)
@table.show_columns(*columns)
@table
end

def columns
[
Columns::Device,
Columns::Size,
Columns::Format,
Columns::Encrypted,
Columns::Type
]
end

def devices
@lvm_vg.lvm_pvs.map(&:plain_blk_device)
# @see UsedDevicesTab#buttons
def buttons
Right(LvmVgResizeButton.new(device: device))
end
end
end
Expand Down
34 changes: 12 additions & 22 deletions src/lib/y2partitioner/widgets/pages/md_raid.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) [2017] SUSE LLC
# Copyright (c) [2017-2020] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -18,6 +18,7 @@
# find current contact information at www.suse.com.

require "y2partitioner/icons"
require "y2partitioner/widgets/tabs"
require "y2partitioner/device_graphs"
require "y2partitioner/widgets/pages/base"
require "y2partitioner/widgets/pages/md_raids"
Expand All @@ -32,7 +33,7 @@
module Y2Partitioner
module Widgets
module Pages
# A Page for a md raid device: contains {MdTab}, {PartitionsTab} and {MdDevicesTab}
# A Page for a md raid device: contains {MdTab}, {PartitionsTab} and {MdUsedDevicesTab}
class MdRaid < Base
# Constructor
#
Expand Down Expand Up @@ -69,7 +70,7 @@ def contents
Left(
Tabs.new(
MdTab.new(@md, initial: true),
MdDevicesTab.new(@md, @pager),
MdUsedDevicesTab.new(@md, @pager),
PartitionsTab.new(@md, @pager)
)
)
Expand Down Expand Up @@ -120,27 +121,16 @@ def contents
end
end

# A Tab for the devices used by a Software RAID
class MdDevicesTab < UsedDevicesTab
# Constructor
#
# @param md [Y2Storage::Md]
# @param pager [CWM::TreePager]
# @param initial [Boolean] if it is the initial tab
def initialize(md, pager, initial: false)
textdomain "storage"

super(md.devices, pager)
@md = md
@initial = initial
# A Tab for the used devices of a MD RAID
class MdUsedDevicesTab < UsedDevicesTab
# @see UsedDevicesTab#used_devices
def used_devices
device.devices
end

# @macro seeCustomWidget
def contents
@contents ||= VBox(
table,
Right(UsedDevicesEditButton.new(device: @md))
)
# @see UsedDevicesTab#buttons
def buttons
Right(UsedDevicesEditButton.new(device: device))
end
end
end
Expand Down
Loading

0 comments on commit 24ec0af

Please sign in to comment.