Class: Hookit::Resource::Zfs

Inherits:
Base
  • Object
show all
Defined in:
lib/hookit/resource/zfs.rb

Instance Attribute Summary

Attributes inherited from Base

#dict

Instance Method Summary collapse

Methods inherited from Base

#action, actions, #can_run?, default_action, #default_action, field, #not_if, #only_if

Constructor Details

#initialize(name) ⇒ Zfs

Returns a new instance of Zfs.



15
16
17
18
# File 'lib/hookit/resource/zfs.rb', line 15

def initialize(name)
  snapshot(name) unless snapshot
  super
end

Instance Method Details

#clone!Object



71
72
73
# File 'lib/hookit/resource/zfs.rb', line 71

def clone!
  run_command! "zfs clone #{snapshot} #{dataset}"
end

#destroy!Object



60
61
62
63
64
65
# File 'lib/hookit/resource/zfs.rb', line 60

def destroy!
  `zfs list -t snapshot | grep #{snapshot}`
  if $?.exitstatus == 0
    run_command! "zfs destroy #{snapshot}"
  end 
end

#receive!Object



43
44
45
# File 'lib/hookit/resource/zfs.rb', line 43

def receive!
  run_command! "#{source.to_s.strip} | zfs receive -F #{dataset}"
end

#rollback!Object



67
68
69
# File 'lib/hookit/resource/zfs.rb', line 67

def rollback!
  run_command! "zfs rollback -r #{snapshot}"
end

#run(action) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/hookit/resource/zfs.rb', line 20

def run(action)
  case action
  when :send
    send!
  when :receive
    receive!
  when :transmit
    transmit!
  when :snapshot
    snapshot!
  when :destroy
    destroy!
  when :rollback
    rollback!
  when :clone
    clone!
  end
end

#send!Object



39
40
41
# File 'lib/hookit/resource/zfs.rb', line 39

def send!
  run_command! "zfs send #{snapshot} | #{destination}"
end

#snapshot!Object



55
56
57
58
# File 'lib/hookit/resource/zfs.rb', line 55

def snapshot!
  destroy!
  run_command! "zfs snapshot #{snapshot}"
end

#transmit!Object



47
48
49
50
51
52
53
# File 'lib/hookit/resource/zfs.rb', line 47

def transmit!
  if ssh_host
    run_command! "zfs send #{options} #{snapshot} | ssh -o stricthostkeychecking=no #{ssh_host} zfs receive -F #{dataset}"
  else
    run_command! "zfs send #{options} #{snapshot} | zfs receive -F #{dataset}"
  end
end