-
Notifications
You must be signed in to change notification settings - Fork 19
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
Showing
8 changed files
with
319 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2018] 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 "y2partitioner/dialogs/bcache" | ||
require "y2partitioner/device_graphs" | ||
|
||
Yast.import "Popup" | ||
|
||
module Y2Partitioner | ||
module Actions | ||
# Action following click on Add Bcache button. | ||
class AddBcache | ||
def run | ||
dialog = Dialogs::Bcache.new(device_graph, usable_blk_devices, | ||
usable_blk_devices + existing_caches) | ||
|
||
create_device(dialog) if dialog.run == :next | ||
:finish | ||
end | ||
|
||
private | ||
|
||
def create_device(dialog) | ||
backing = dialog.backing_device | ||
raise "Invalid result #{dialog.inspect}. Backing not found." unless backing | ||
|
||
caching = dialog.caching_device | ||
raise "Invalid result #{dialog.inspect}. Caching not found." unless caching | ||
|
||
bcache = backing.create_bcache(Y2Storage::Bcache.find_free_name(device_graph)) | ||
|
||
if !caching.is?(:bcache_cset) | ||
caching.remove_descendants | ||
caching = caching.create_bcache_cset | ||
end | ||
|
||
bcache.attach_bcache_cset(caching) | ||
end | ||
|
||
def device_graph | ||
DeviceGraphs.instance.current | ||
end | ||
|
||
def usable_blk_devices | ||
device_graph.blk_devices.select do |dev| | ||
dev.component_of.empty? && | ||
(dev.filesystem.nil? || dev.filesystem.mount_point.nil?) && | ||
(!dev.respond_to?(:partitions) || dev.partitions.empty?) | ||
end | ||
end | ||
|
||
def existing_caches | ||
device_graph.bcache_csets | ||
end | ||
end | ||
end | ||
end |
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,177 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2017] 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 "yast2/popup" | ||
require "cwm/common_widgets" | ||
require "y2partitioner/dialogs/base" | ||
|
||
module Y2Partitioner | ||
module Dialogs | ||
# Form to set the backing and caching device for bcache. | ||
# Part of {Actions::AddBcache}. | ||
class Bcache < Base | ||
# @param device_graph [Y2Storage::DeviceGraph] graph on which it operates | ||
# @param suitable_backing [Array<Y2Storage::BlkDevice>] devices that can be used for backing | ||
# @param suitable_caching [Array<Y2Storage::BlkDevice,Y2Storage::BcacheCset>] | ||
# devices that can be used for caching | ||
# @param device [Y2Storage::Bcache] device if already exists or nil for newly created one. | ||
def initialize(device_graph, suitable_backing, suitable_caching, device = nil) | ||
# TODO: handle if device is passed | ||
textdomain "storage" | ||
@caching = CachingDevice.new(device_graph, device, suitable_caching) | ||
@backing = BackingDevice.new(device_graph, device, suitable_backing, @caching) | ||
@device_graph = device_graph | ||
end | ||
|
||
# @macro seeDialog | ||
def title | ||
_("Bcache Device") | ||
end | ||
|
||
# @macro seeDialog | ||
def contents | ||
VBox( | ||
HBox( | ||
@backing, | ||
HSpacing(1), | ||
@caching | ||
), | ||
VSpacing(1) | ||
) | ||
end | ||
|
||
# Selected caching device. Undefined if result of dialog is not `:next` | ||
# @return [Y2Storage::BlkDevice, Y2Storage::BcacheCset] | ||
def caching_device | ||
@caching.result | ||
end | ||
|
||
# Selected backing device. Undefined if result of dialog is not `:next` | ||
# @return [Y2Storage::BlkDevice] | ||
def backing_device | ||
@backing.result | ||
end | ||
|
||
# Widget to select the backing device | ||
class BackingDevice < CWM::ComboBox | ||
def initialize(device_graph, device, devices, caching) | ||
textdomain "storage" | ||
@device = device | ||
@devices = devices | ||
@device_graph = device_graph | ||
@caching = caching | ||
end | ||
|
||
def label | ||
_("Backing Device") | ||
end | ||
|
||
def items | ||
@devices.map do |dev| | ||
[dev.sid, dev.name] | ||
end | ||
end | ||
|
||
def help | ||
# TODO: write it | ||
"" | ||
end | ||
|
||
def init | ||
return unless @device | ||
|
||
self.value = @device.sid | ||
end | ||
|
||
def store | ||
val = value | ||
@result = @device_graph.find_device(val) | ||
end | ||
|
||
def validate | ||
log.info "selected value #{value.inspect}" | ||
# value can be empty string if there is no items | ||
if value.nil? || value == "" | ||
Yast2::Popup.show( | ||
_("Empty backing device is not yet supported"), | ||
headline: _("Cannot Create Bcache") | ||
) | ||
return false | ||
elsif value == @caching.value | ||
Yast2::Popup.show( | ||
_("Backing and Caching device cannot be identical."), | ||
headline: _("Cannot Create Bcache") | ||
) | ||
return false | ||
else | ||
true | ||
end | ||
end | ||
|
||
attr_reader :result | ||
end | ||
|
||
# Widget to select the caching device | ||
class CachingDevice < CWM::ComboBox | ||
def initialize(device_graph, device, devices) | ||
textdomain "storage" | ||
@device_graph = device_graph | ||
@device = device | ||
@devices = devices | ||
end | ||
|
||
def label | ||
_("Caching Device") | ||
end | ||
|
||
def items | ||
@devices.map do |dev| | ||
case dev | ||
when Y2Storage::BcacheCset | ||
[dev.sid, dev.display_name] | ||
else | ||
[dev.sid, dev.name] | ||
end | ||
end | ||
end | ||
|
||
def help | ||
# TODO: write it | ||
"" | ||
end | ||
|
||
def init | ||
return unless @device | ||
|
||
self.value = @device.sid | ||
end | ||
|
||
def store | ||
val = value | ||
@result = @device_graph.find_device(val) | ||
end | ||
|
||
attr_reader :result | ||
end | ||
end | ||
end | ||
end |
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,49 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2018] 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" | ||
require "y2partitioner/actions/add_bcache" | ||
|
||
module Y2Partitioner | ||
module Widgets | ||
# Button for opening a wizard to add a new Bcache array | ||
class BcacheAddButton < CWM::PushButton | ||
# Constructor | ||
def initialize | ||
textdomain "storage" | ||
end | ||
|
||
# @macro seeAbstractWidget | ||
def label | ||
# TRANSLATORS: button label to add a new Bcache device | ||
_("Add Bcache...") | ||
end | ||
|
||
# @macro seeAbstractWidget | ||
# @see Actions::AddMd | ||
def handle | ||
res = Actions::AddBcache.new.run | ||
res == :finish ? :redraw : nil | ||
end | ||
end | ||
end | ||
end |
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
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
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