Skip to content

Commit

Permalink
Use singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
shundhammer committed Dec 22, 2015
1 parent 19a0a43 commit c627ec8
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
78 changes: 78 additions & 0 deletions src/lib/storage/singleton.rb
@@ -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
39 changes: 39 additions & 0 deletions src/lib/storage/storage_proposal.rb
Expand Up @@ -24,6 +24,7 @@
require "yast"
require "storage"
require_relative "./disk_size"
require_relative "./singleton"
require "pp"

# This file can be invoked separately for minimal testing.
Expand Down Expand Up @@ -125,17 +126,47 @@ def initialize(mount_point)
# or by resizing an existing Windows partiton.
#
class SpaceMaker
attr_reader :volumes

# Initialize.
# @param volumes [list of Storage::Volume] volumes to find space for.
# The volumes might be changed by this class.
#
# @param settings [Storage::Settings] parameters to use
#
def initialize(volumes, settings)
@volumes = volumes
@settings = settings
storage = Storage.instance
storage = Storage.instance
storage = Storage.instance
end

# Try to detect empty (unpartitioned) space.
def find_space
end

# Use force to create space: Try to resize an existing Windows
# partition or delete partitions until there is enough free space.
def make_space
end

# Check if there are any Linux partitions on any of the disks.
# This may be a normal Linux partition (type 0x83), a Linux swap
# partition (type 0x82), an LVM partition, or a RAID partition.
def linux_partitions?
end

# Check if there is a MS Windows partition that could possibly be
# resized.
#
# @return [bool] 'true# if there is a Windows partition, 'false' if not.
def windows_partition?
# TO DO
false
end

# Resize an existing MS Windows partition to free up disk space.
def resize_windows_partition
# TO DO
end
Expand Down Expand Up @@ -195,6 +226,13 @@ def choose_disk

# Create a storage proposal.
def propose
# TO DO: Reset staging
Storage.start_probing
space_maker = SpaceMaker.new(@volumes, @settings)
end

def proposal_text
# TO DO
"No disks found - no storage proposal possible"
end
end
Expand All @@ -207,5 +245,6 @@ def propose
proposal = Yast::Storage::Proposal.new
proposal.settings.root_filesystem_type = :XFS
proposal.settings.use_separate_home = false
proposal.propose
pp proposal
end

0 comments on commit c627ec8

Please sign in to comment.