Class: OsUp::SystemState

Inherits:
Object
  • Object
show all
Includes:
OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System
Defined in:
lib/osup/system_state.rb

Overview

Preserves system state while a migration is run

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dataset, id, snapshot: []) ⇒ SystemState

Returns a new instance of SystemState.

Parameters:

  • dataset (String)
  • id (String)
  • snapshot (Array<Symbol>) (defaults to: [])

    datasets to snapshot



19
20
21
22
23
24
# File 'lib/osup/system_state.rb', line 19

def initialize(dataset, id, snapshot: [])
  @dataset = dataset
  @id = id
  @datasets = datasets_to_snapshot(snapshot)
  @snapshots = []
end

Instance Attribute Details

#datasetObject (readonly, protected)

Returns the value of attribute dataset.



56
57
58
# File 'lib/osup/system_state.rb', line 56

def dataset
  @dataset
end

#datasetsObject (readonly, protected)

Returns the value of attribute datasets.



56
57
58
# File 'lib/osup/system_state.rb', line 56

def datasets
  @datasets
end

#idObject (readonly, protected)

Returns the value of attribute id.



56
57
58
# File 'lib/osup/system_state.rb', line 56

def id
  @id
end

#snapshotsObject (readonly, protected)

Returns the value of attribute snapshots.



56
57
58
# File 'lib/osup/system_state.rb', line 56

def snapshots
  @snapshots
end

Class Method Details

.createObject

Create a new system state snapshot



10
11
12
13
14
# File 'lib/osup/system_state.rb', line 10

def self.create(*, **)
  s = new(*, **)
  s.create
  s
end

Instance Method Details

#commitObject

Changes made to the pool are solid, confirm them



36
37
38
39
40
# File 'lib/osup/system_state.rb', line 36

def commit
  snapshots.each do |snap|
    zfs(:destroy, nil, snap)
  end
end

#createObject

Create system snapshot



27
28
29
30
31
32
33
# File 'lib/osup/system_state.rb', line 27

def create
  datasets.each do |ds|
    snapshots << "#{ds}@osup-pre-#{id}"
  end

  zfs(:snapshot, nil, snapshots.join(' ')) if snapshots.any?
end

#datasets_to_snapshot(snapshot) ⇒ Object (protected)



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/osup/system_state.rb', line 58

def datasets_to_snapshot(snapshot)
  ret = []

  snapshot.each do |s|
    case s
    when :conf, :log, :hook
      ret << File.join(dataset, s.to_s)
    else
      raise "unsupported snapshot '#{s}'"
    end
  end

  ret
end

#log_typeObject



50
51
52
# File 'lib/osup/system_state.rb', line 50

def log_type
  "pool=#{dataset}"
end

#rollbackObject

Revert changes to the pool by restoring original state



43
44
45
46
47
48
# File 'lib/osup/system_state.rb', line 43

def rollback
  snapshots.each do |snap|
    zfs(:rollback, '-r', snap)
    zfs(:destroy, nil, snap)
  end
end