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
1 parent
19a0a43
commit c627ec8
Showing
2 changed files
with
117 additions
and
0 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,78 @@ | ||
#!/usr/bin/env ruby | ||
# | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2015] 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 "storage" | ||
|
||
module Yast | ||
module Storage | ||
# Singleton class for the libstorage object. | ||
# | ||
# You can simply use Storage.instance to use it and create a libstorage | ||
# instance if there isn't one yet; this will use common default parameters | ||
# for creating it. | ||
# | ||
# If you need special parameters for creating it, you can use | ||
# Storage.create_instance with a custom ::Storage::Environment (notice the | ||
# difference between the global ::Storage namespace which is libstorage and | ||
# this Yast::Storage namespace). | ||
# | ||
# By default (unless disabled in the ::Storage::Environment), creating the | ||
# instance will also start hardware probing. This is why there is an alias | ||
# name Storage.start_probing to make this explicit. | ||
# | ||
class Storage | ||
class << self | ||
@instance = nil | ||
|
||
# Return the singleton for the libstorage object. This will create one | ||
# for the first call, which will also trigger hardware probing. | ||
def instance | ||
create_instance unless @instance | ||
@instance | ||
end | ||
|
||
# Create the singleton for the libstorage object. | ||
# | ||
# Create your own Storage::Environment for custom purposes like mocking | ||
# the hardware probing etc. | ||
def create_instance(storage_environment = nil) | ||
if storage_environment.nil? | ||
storage_environment = ::Storage::Environment.new(true) | ||
# TO DO: Set up logging | ||
end | ||
# FIXME: Remove this | ||
print "Creating Storage object\n" | ||
@instance = ::Storage::Storage.new(storage_environment) | ||
end | ||
|
||
alias_method :start_probing, :create_instance | ||
|
||
# Destroy the singleton for the libstorage object. | ||
def destroy_instance | ||
@instance = nil | ||
end | ||
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