Class: OpenNebula::Records

Inherits:
RecordsSource show all
Defined in:
service/records/records.rb

Overview

(History)Records source class for fullfilling Timeline

Instance Attribute Summary

Attributes inherited from RecordsSource

#id

Instance Method Summary collapse

Methods inherited from RecordsSource

check_source, #find, #key, #records, tl_filter

Constructor Details

#initialize(id) ⇒ Records

inits RecordsSource class with Record class as base



92
93
94
# File 'service/records/records.rb', line 92

def initialize id
  super(Record, id)
end

Instance Method Details

#init_state(stime) ⇒ Object

Calculates nitial state for timeline(such as VM was turn on before stime, state would be 'on')



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'service/records/records.rb', line 97

def init_state stime
  prev = @records.where { time < stime }.order(Sequel.desc :time).limit(1).to_a.last
  if prev.nil? then
    curr = @records.where { time >= stime }.limit(1).to_a.first
    return {} if curr.nil?

    {
      state: curr.state
    }
  else
    {
      state: prev.state
    }
  end
end