Class: Cosmos::InterfaceStatusModel

Inherits:
EphemeralModel show all
Defined in:
lib/cosmos/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 =
'cosmos_interface_status'
ROUTERS_PRIMARY_KEY =
'cosmos_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 EphemeralModel

store

Methods inherited from Model

#as_config, #create, #deploy, #destroy, #destroyed?, filter, find_all_by_plugin, from_json, get_all_models, get_model, handle_config, set, store, #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

Returns a new instance of InterfaceStatusModel.



72
73
74
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
# File 'lib/cosmos/models/interface_status_model.rb', line 72

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.



31
32
33
# File 'lib/cosmos/models/interface_status_model.rb', line 31

def clients
  @clients
end

#rxbytesObject

Returns the value of attribute rxbytes.



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

def rxbytes
  @rxbytes
end

#rxcntObject

Returns the value of attribute rxcnt.



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

def rxcnt
  @rxcnt
end

#rxsizeObject

Returns the value of attribute rxsize.



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

def rxsize
  @rxsize
end

#stateObject

Returns the value of attribute state.



30
31
32
# File 'lib/cosmos/models/interface_status_model.rb', line 30

def state
  @state
end

#txbytesObject

Returns the value of attribute txbytes.



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

def txbytes
  @txbytes
end

#txcntObject

Returns the value of attribute txcnt.



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

def txcnt
  @txcnt
end

#txsizeObject

Returns the value of attribute txsize.



32
33
34
# File 'lib/cosmos/models/interface_status_model.rb', line 32

def txsize
  @txsize
end

Class Method Details

._get_keyObject

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



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cosmos/models/interface_status_model.rb', line 60

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



55
56
57
# File 'lib/cosmos/models/interface_status_model.rb', line 55

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

.all(scope:) ⇒ Object



49
50
51
# File 'lib/cosmos/models/interface_status_model.rb', line 49

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



41
42
43
# File 'lib/cosmos/models/interface_status_model.rb', line 41

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

.names(scope:) ⇒ Object



45
46
47
# File 'lib/cosmos/models/interface_status_model.rb', line 45

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

Instance Method Details

#as_jsonObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/cosmos/models/interface_status_model.rb', line 101

def as_json
  {
    '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