Class: ZFS

Inherits:
Object
  • Object
show all
Defined in:
lib/SANStore/zfs/zfs.rb

Overview

Defines a class capable of manipulating ZFS volumes. This classes uses the standard command line tools (zfs and zpool), not the C API.

Class Method Summary collapse

Class Method Details

.delete_volume(volume_path) ⇒ Object

Delete (destroy) a volume from the ZFS pool. This command can handle both raw paths, and absolute paths.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/SANStore/zfs/zfs.rb', line 38

def self.delete_volume(volume_path)
  
  # Work out if this is a raw volume path, or an absolute path
  if volume_path.index(/\/dev\/zvol\/rdsk/) then
    # This is a relative path, so we need to split the
    # device prefix off to get the volume path
    volume_path = volume_path.partition(/\/dev\/zvol\/rdsk/)[2]
  end

  # Remove any slash prefixes
  if volume_path[0] == 0x2F then
    volume_path = volume_path[1..volume_path.length]
  end 
  
  # Delete the volume from the system
  SANStore::CLI::Logger.instance.log_level(:low, :delete, "Removing ZFS volume #{volume_path} from the file-store")
  cmd = %x[zfs destroy -r -f #{volume_path}]
  
end

.new_volume(volume_path, volume_size) ⇒ Object

Create a new volume, at the specified location and of the specified size.

NOTE: This command currently only supports the creation of sparse volumes. If you really need pre-allocated volumes for some reason, this command needs to be extended



28
29
30
31
32
33
34
# File 'lib/SANStore/zfs/zfs.rb', line 28

def self.new_volume(volume_path, volume_size)
  
  # Create the volume
  SANStore::CLI::Logger.instance.log_level(:low, :create, "#{volume_size} ZFS volume at #{volume_path}")
  cmd = %x[zfs create -s -V #{volume_size} #{volume_path}]

end