Class: OsUp::SystemState
- Inherits:
-
Object
- Object
- OsUp::SystemState
- 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
-
#dataset ⇒ Object
readonly
protected
Returns the value of attribute dataset.
-
#datasets ⇒ Object
readonly
protected
Returns the value of attribute datasets.
-
#id ⇒ Object
readonly
protected
Returns the value of attribute id.
-
#snapshots ⇒ Object
readonly
protected
Returns the value of attribute snapshots.
Class Method Summary collapse
-
.create ⇒ Object
Create a new system state snapshot.
Instance Method Summary collapse
-
#commit ⇒ Object
Changes made to the pool are solid, confirm them.
-
#create ⇒ Object
Create system snapshot.
- #datasets_to_snapshot(snapshot) ⇒ Object protected
-
#initialize(dataset, id, snapshot: []) ⇒ SystemState
constructor
A new instance of SystemState.
- #log_type ⇒ Object
-
#rollback ⇒ Object
Revert changes to the pool by restoring original state.
Constructor Details
#initialize(dataset, id, snapshot: []) ⇒ SystemState
Returns a new instance of SystemState.
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
#dataset ⇒ Object (readonly, protected)
Returns the value of attribute dataset.
56 57 58 |
# File 'lib/osup/system_state.rb', line 56 def dataset @dataset end |
#datasets ⇒ Object (readonly, protected)
Returns the value of attribute datasets.
56 57 58 |
# File 'lib/osup/system_state.rb', line 56 def datasets @datasets end |
#id ⇒ Object (readonly, protected)
Returns the value of attribute id.
56 57 58 |
# File 'lib/osup/system_state.rb', line 56 def id @id end |
#snapshots ⇒ Object (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
.create ⇒ Object
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
#commit ⇒ Object
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 |
#create ⇒ Object
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_type ⇒ Object
50 51 52 |
# File 'lib/osup/system_state.rb', line 50 def log_type "pool=#{dataset}" end |
#rollback ⇒ Object
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 |