Class: OsCtld::Migration::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/osctld/migration/log.rb

Overview

This class serves as a scratchpad for migrations

Both the source and the destination nodes have an instance of this class per container. This class determines whether the next step of the migration can proceed, stores names of snapshots created during the migration and other settings.

Constant Summary collapse

STATES =
%i(stage base incremental cancel transfer cleanup)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Log

Returns a new instance of Log

Parameters:

  • opts (Hash)

    options

Options Hash (opts):

  • role (Symbol)

    `:source`, `:destination`

  • state (Symbol)
  • snapshots (Array<String>)
  • opts (Hash)


27
28
29
30
31
32
# File 'lib/osctld/migration/log.rb', line 27

def initialize(opts)
  @role = opts[:role]
  @state = opts[:state] || :stage
  @snapshots = opts[:snapshots] || []
  @opts = opts[:opts] || {}
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts



11
12
13
# File 'lib/osctld/migration/log.rb', line 11

def opts
  @opts
end

#roleObject (readonly)

Returns the value of attribute role



11
12
13
# File 'lib/osctld/migration/log.rb', line 11

def role
  @role
end

#snapshotsObject (readonly)

Returns the value of attribute snapshots



11
12
13
# File 'lib/osctld/migration/log.rb', line 11

def snapshots
  @snapshots
end

#stateObject

Returns the value of attribute state



11
12
13
# File 'lib/osctld/migration/log.rb', line 11

def state
  @state
end

Class Method Details

.load(cfg) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/osctld/migration/log.rb', line 13

def self.load(cfg)
  new(
    role: cfg['role'].to_sym,
    state: cfg['state'].to_sym,
    snapshots: cfg['snapshots'],
    opts: Hash[cfg['opts'].map { |k,v| [k.to_sym, v] }],
  )
end

Instance Method Details

#can_continue?(next_state) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/osctld/migration/log.rb', line 43

def can_continue?(next_state)
  syncs = %i(base incremental)
  return false if state == :cancel

  next_i = STATES.index(next_state)
  return false unless next_i

  return true if syncs.include?(state) && syncs.include?(next_state)

  cur_i = STATES.index(state)
  return false if next_i < cur_i
  return true if next_i > cur_i
  false
end

#dumpObject



34
35
36
37
38
39
40
41
# File 'lib/osctld/migration/log.rb', line 34

def dump
  {
    'role' => role.to_s,
    'state' => state.to_s,
    'snapshots' => snapshots,
    'opts' => Hash[opts.map { |k,v| [k.to_s, v] }],
  }
end