Class: Zfs::Dataset

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, properties = {}, options = {}) ⇒ Dataset

Returns a new instance of Dataset.



6
7
8
9
10
11
12
# File 'lib/zfs/dataset.rb', line 6

def initialize(name, properties={}, options={})
  @name = name
  @properties = properties
  if properties[snapshot_property] == "mysql"
    self.contains_db!(properties[snapshot_property])
  end
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



5
6
7
# File 'lib/zfs/dataset.rb', line 5

def db
  @db
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/zfs/dataset.rb', line 3

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



4
5
6
# File 'lib/zfs/dataset.rb', line 4

def properties
  @properties
end

Class Method Details

.list(properties = []) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/zfs/dataset.rb', line 23

def self.list(properties=[])
  datasets = []
  cmd_properties = ["name"] + properties
  cmd="zfs list -H -t filesystem,volume -o #{cmd_properties.join(",")} -s name"
  puts cmd if $debug
  IO.popen cmd do |io|
    io.readlines.each do |line|
      values = line.split
      name = values.shift
      dataset_properties = {}
      properties.each_with_index do |property_name, i|
        value = values[i]
        next if value == '-'
        dataset_properties[property_name] = value
      end
      datasets << self.new(name, dataset_properties)
    end
  end
  datasets
end

Instance Method Details

#==(dataset) ⇒ Object



14
15
16
# File 'lib/zfs/dataset.rb', line 14

def ==(dataset)
  dataset.equal?(self) || (dataset && dataset.name == @name)
end

#contains_db!(kind) ⇒ Object



18
19
20
21
# File 'lib/zfs/dataset.rb', line 18

def contains_db!(kind)
  @db = kind
  self
end