Class: OpenC3::InterfaceStatusModel
- 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
Constant Summary collapse
- INTERFACES_PRIMARY_KEY =
'openc3_interface_status'- ROUTERS_PRIMARY_KEY =
'openc3_router_status'
Instance Attribute Summary collapse
-
#clients ⇒ Object
Returns the value of attribute clients.
-
#rxbytes ⇒ Object
Returns the value of attribute rxbytes.
-
#rxcnt ⇒ Object
Returns the value of attribute rxcnt.
-
#rxsize ⇒ Object
Returns the value of attribute rxsize.
-
#state ⇒ Object
Returns the value of attribute state.
-
#txbytes ⇒ Object
Returns the value of attribute txbytes.
-
#txcnt ⇒ Object
Returns the value of attribute txcnt.
-
#txsize ⇒ Object
Returns the value of attribute txsize.
Attributes inherited from Model
#name, #plugin, #scope, #updated_at
Class Method Summary collapse
-
._get_key ⇒ Object
Helper method to return the correct primary key based on class name.
-
._get_type ⇒ Object
Helper method to return the correct type based on class name.
- .all(scope:) ⇒ Object
-
.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.
- .names(scope:) ⇒ Object
Instance Method Summary collapse
- #as_json(*a) ⇒ Object
-
#initialize(name:, state:, clients: 0, txsize: 0, rxsize: 0, txbytes: 0, rxbytes: 0, txcnt: 0, rxcnt: 0, updated_at: nil, plugin: nil, scope:) ⇒ InterfaceStatusModel
constructor
A new instance of InterfaceStatusModel.
Methods inherited from Model
#check_disable_erb, #create, #deploy, #destroy, #destroyed?, #diff, 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
Returns a new instance of InterfaceStatusModel.
70 71 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 |
# File 'lib/openc3/models/interface_status_model.rb', line 70 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
#clients ⇒ Object
Returns the value of attribute clients.
29 30 31 |
# File 'lib/openc3/models/interface_status_model.rb', line 29 def clients @clients end |
#rxbytes ⇒ Object
Returns the value of attribute rxbytes.
33 34 35 |
# File 'lib/openc3/models/interface_status_model.rb', line 33 def rxbytes @rxbytes end |
#rxcnt ⇒ Object
Returns the value of attribute rxcnt.
35 36 37 |
# File 'lib/openc3/models/interface_status_model.rb', line 35 def rxcnt @rxcnt end |
#rxsize ⇒ Object
Returns the value of attribute rxsize.
31 32 33 |
# File 'lib/openc3/models/interface_status_model.rb', line 31 def rxsize @rxsize end |
#state ⇒ Object
Returns the value of attribute state.
28 29 30 |
# File 'lib/openc3/models/interface_status_model.rb', line 28 def state @state end |
#txbytes ⇒ Object
Returns the value of attribute txbytes.
32 33 34 |
# File 'lib/openc3/models/interface_status_model.rb', line 32 def txbytes @txbytes end |
#txcnt ⇒ Object
Returns the value of attribute txcnt.
34 35 36 |
# File 'lib/openc3/models/interface_status_model.rb', line 34 def txcnt @txcnt end |
#txsize ⇒ Object
Returns the value of attribute txsize.
30 31 32 |
# File 'lib/openc3/models/interface_status_model.rb', line 30 def txsize @txsize end |
Class Method Details
._get_key ⇒ Object
Helper method to return the correct primary key based on class name
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/openc3/models/interface_status_model.rb', line 58 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_type ⇒ Object
Helper method to return the correct type based on class name
53 54 55 |
# File 'lib/openc3/models/interface_status_model.rb', line 53 def self._get_type self.name.to_s.split("Model")[0].upcase.split("::")[-1] end |
.all(scope:) ⇒ Object
47 48 49 |
# File 'lib/openc3/models/interface_status_model.rb', line 47 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
39 40 41 |
# File 'lib/openc3/models/interface_status_model.rb', line 39 def self.get(name:, scope:) super("#{scope}__#{_get_key}", name: name) end |
.names(scope:) ⇒ Object
43 44 45 |
# File 'lib/openc3/models/interface_status_model.rb', line 43 def self.names(scope:) super("#{scope}__#{_get_key}") end |
Instance Method Details
#as_json(*a) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/openc3/models/interface_status_model.rb', line 99 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 |