Class: OpenC3::InterfaceStatusModel

Inherits:
Model show all
Defined in:
lib/openc3/models/interface_status_model.rb

Overview

Stores the status about an interface. This class also implements logic to handle status for a router since the functionality is identical (only difference is the Redis key used).

Direct Known Subclasses

RouterStatusModel

Constant Summary collapse

INTERFACES_PRIMARY_KEY =
'openc3_interface_status'
ROUTERS_PRIMARY_KEY =
'openc3_router_status'

Instance Attribute Summary collapse

Attributes inherited from Model

#name, #plugin, #scope, #updated_at

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#check_disable_erb, #create, #deploy, #destroy, #destroyed?, filter, find_all_by_plugin, from_json, get_all_models, get_model, handle_config, set, store, store_queued, #undeploy, #update

Constructor Details

#initialize(name:, state:, clients: 0, txsize: 0, rxsize: 0, txbytes: 0, rxbytes: 0, txcnt: 0, rxcnt: 0, updated_at: nil, plugin: nil, scope:) ⇒ InterfaceStatusModel



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/openc3/models/interface_status_model.rb', line 75

def initialize(
  name:,
  state:,
  clients: 0,
  txsize: 0,
  rxsize: 0,
  txbytes: 0,
  rxbytes: 0,
  txcnt: 0,
  rxcnt: 0,
  updated_at: nil,
  plugin: nil,
  scope:
)
  if self.class._get_type == 'INTERFACESTATUS'
    super("#{scope}__#{INTERFACES_PRIMARY_KEY}", name: name, updated_at: updated_at, plugin: plugin, scope: scope)
  else
    super("#{scope}__#{ROUTERS_PRIMARY_KEY}", name: name, updated_at: updated_at, plugin: plugin, scope: scope)
  end
  @state = state
  @clients = clients
  @txsize = txsize
  @rxsize = rxsize
  @txbytes = txbytes
  @rxbytes = rxbytes
  @txcnt = txcnt
  @rxcnt = rxcnt
end

Instance Attribute Details

#clientsObject

Returns the value of attribute clients.



34
35
36
# File 'lib/openc3/models/interface_status_model.rb', line 34

def clients
  @clients
end

#rxbytesObject

Returns the value of attribute rxbytes.



38
39
40
# File 'lib/openc3/models/interface_status_model.rb', line 38

def rxbytes
  @rxbytes
end

#rxcntObject

Returns the value of attribute rxcnt.



40
41
42
# File 'lib/openc3/models/interface_status_model.rb', line 40

def rxcnt
  @rxcnt
end

#rxsizeObject

Returns the value of attribute rxsize.



36
37
38
# File 'lib/openc3/models/interface_status_model.rb', line 36

def rxsize
  @rxsize
end

#stateObject

Returns the value of attribute state.



33
34
35
# File 'lib/openc3/models/interface_status_model.rb', line 33

def state
  @state
end

#txbytesObject

Returns the value of attribute txbytes.



37
38
39
# File 'lib/openc3/models/interface_status_model.rb', line 37

def txbytes
  @txbytes
end

#txcntObject

Returns the value of attribute txcnt.



39
40
41
# File 'lib/openc3/models/interface_status_model.rb', line 39

def txcnt
  @txcnt
end

#txsizeObject

Returns the value of attribute txsize.



35
36
37
# File 'lib/openc3/models/interface_status_model.rb', line 35

def txsize
  @txsize
end

Class Method Details

._get_keyObject

Helper method to return the correct primary key based on class name



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/openc3/models/interface_status_model.rb', line 63

def self._get_key
  type = _get_type
  case type
  when 'INTERFACESTATUS'
    INTERFACES_PRIMARY_KEY
  when 'ROUTERSTATUS'
    ROUTERS_PRIMARY_KEY
  else
    raise "Unknown type #{type} from class #{self.name}"
  end
end

._get_typeObject

Helper method to return the correct type based on class name



58
59
60
# File 'lib/openc3/models/interface_status_model.rb', line 58

def self._get_type
  self.name.to_s.split("Model")[0].upcase.split("::")[-1]
end

.all(scope:) ⇒ Object



52
53
54
# File 'lib/openc3/models/interface_status_model.rb', line 52

def self.all(scope:)
  super("#{scope}__#{_get_key}")
end

.get(name:, scope:) ⇒ Object

NOTE: The following three class methods are used by the ModelController and are reimplemented to enable various Model class methods to work



44
45
46
# File 'lib/openc3/models/interface_status_model.rb', line 44

def self.get(name:, scope:)
  super("#{scope}__#{_get_key}", name: name)
end

.names(scope:) ⇒ Object



48
49
50
# File 'lib/openc3/models/interface_status_model.rb', line 48

def self.names(scope:)
  super("#{scope}__#{_get_key}")
end

Instance Method Details

#as_json(*a) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/openc3/models/interface_status_model.rb', line 104

def as_json(*a)
  {
    'name' => @name,
    'state' => @state,
    'clients' => @clients,
    'txsize' => @txsize,
    'rxsize' => @rxsize,
    'txbytes' => @txbytes,
    'rxbytes' => @rxbytes,
    'txcnt' => @txcnt,
    'rxcnt' => @rxcnt,
    'plugin' => @plugin,
    'updated_at' => @updated_at
  }
end