Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Docsis
- class DhcpLog < Docsis::ApplicationRecord
- self.table_name = :dhcp_log
- self.primary_key = false
- self.store_full_sti_class = false
- after_initialize :readonly!
- scope :ack, -> {where(sending: :ack)}
- scope :nak, -> {where(sending: :nak)}
- scope :offer, -> {where(sending: :offer)}
- scope :q_ack, -> {where(sending: :q_ack)}
- scope :q_nak, -> {where(sending: :q_nak)}
- enum sending: {
- ack: 'ACK',
- nak: 'NAK',
- offer: 'OFFER',
- q_ack: 'Q_ACK',
- q_nak: 'Q_NAK'
- }
- enum type: {
- CM: 'CM',
- CPE: 'CPE',
- MTA: 'MTA',
- 'NO-AUTH': 'NO-AUTH'
- }
- enum dynamic_flag: {
- yes: 'YES' ,
- no: 'NO'
- }, _prefix: :dynamic_flag
- enum mcache_flag: {
- yes: 'YES',
- no: 'NO'
- }, _prefix: :mcache_flag
- def modem_macaddr
- macaddr_ntoa(b_modem_macaddr)
- end
- def macaddr
- macaddr_ntoa(b_macaddr)
- end
- def ipaddr
- IPAddr.new(b_ipaddr, Socket::AF_INET).to_s
- end
- # Return Docsis::Modem corresponding to this log entry
- def modem
- Docsis::Modem.find(modem_macaddr)
- end
- protected
- def self.sti_name
- case self.name.demodulize
- when 'ModemLog'
- 'CM'
- when 'CustomerPremisesEquipmentLog'
- 'CPE'
- when 'MultimediaTerminalAdapterLog'
- 'MTA'
- else
- super
- end
- end
- def self.compute_type(type_name) # :nodoc
- case type_name
- when 'CM'
- ModemLog
- when 'CPE'
- CustomerPremisesEquipmentLog
- when 'MTA'
- MultimediaTerminalAdapterLog
- else
- super
- end
- end
- private
- def macaddr_ntoa(b_addr)
- MacAddress.new('%012X' % b_addr).to_s
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement