Class: Dcmgr::Stm::VolumeContext

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/dcmgr/stm/volume_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(volume_id = nil) ⇒ VolumeContext

Returns a new instance of VolumeContext.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dcmgr/stm/volume_context.rb', line 8

def initialize(volume_id=nil)
  super({:volume_id => volume_id,
          :export_path => nil,
          :transport_information => nil,
          :instance_id => nil,
          :host_device_name => nil,
          :guest_device_name => nil,
          :deleted_at => nil,
          :attached_at => nil,
          :detached_at => nil,
        })
  @stm = Statemachine.build {
    startstate :registering
    superstate :volume_condition do
      trans :registering, :on_create, :creating
      trans :creating, :on_register, :available
      trans :available, :on_attach, :attaching
      trans :attaching, :on_attach, :attached
      trans :attached, :on_detach, :detaching
      trans :detaching, :on_detach, :available

      event :on_fail, :failed
      event :on_deregister, :deregistering
    end

    trans :failed, :on_create, :creating
    trans :failed, :on_register, :available
    trans :failed, :on_fail, :failed
    trans :failed, :on_deregister, :deleting
    trans :failed, :on_delete, :deleted
    trans :deregistering, :on_delete, :deleting
    trans :deleting, :on_delete, :deleted
    trans :deleted, :on_delete, :deleted
  }
  @stm.context = self
end

Instance Attribute Details

#stmObject (readonly)

Returns the value of attribute stm.



6
7
8
# File 'lib/dcmgr/stm/volume_context.rb', line 6

def stm
  @stm
end

Instance Method Details

#on_attachObject



57
58
59
# File 'lib/dcmgr/stm/volume_context.rb', line 57

def on_attach
  self.attached_at = Time.now
end

#on_deleteObject



53
54
55
# File 'lib/dcmgr/stm/volume_context.rb', line 53

def on_delete
  self.deleted_at = Time.now
end

#on_detachObject



61
62
63
# File 'lib/dcmgr/stm/volume_context.rb', line 61

def on_detach
  self.detached_at = Time.now
end

#stateObject



45
46
47
# File 'lib/dcmgr/stm/volume_context.rb', line 45

def state
  @stm.state
end

#to_hash(hash = {}) ⇒ Object



49
50
51
# File 'lib/dcmgr/stm/volume_context.rb', line 49

def to_hash(hash={})
  @table.dup.merge({:state=>@stm.state}).merge(hash)
end