Class: Dcmgr::Models::MacLease
- Defined in:
- lib/dcmgr/models/mac_lease.rb
Overview
MAC address lease information
Constant Summary
Constants inherited from BaseNew
Class Method Summary collapse
-
.default_vendor_id(hypervisor) ⇒ Object
show default vendor ID for the hypervisor.
-
.lease(mac_addr) ⇒ Object
register MAC address.
Methods inherited from BaseNew
Proxy, dataset, default_row_lock_mode=, install_data, install_data_hooks, lock!, #to_hash, unlock!, #with_timestamps?
Class Method Details
.default_vendor_id(hypervisor) ⇒ Object
show default vendor ID for the hypervisor. The virtual interface can be applied any valid MAC address. But using the well known vendor IDs for hypervisor have some benefits. For example, 70-persistent-net.rules issue can be avoided with newer udev release.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dcmgr/models/mac_lease.rb', line 29 def self.default_vendor_id(hypervisor) case hypervisor.to_sym when :kvm '525400' when :lxc # LXC is not known with the specific vendor ID. This may be wrong. '525400' else raise "Unknown hypervisor name: #{hypervisor}" end end |
.lease(mac_addr) ⇒ Object
register MAC address.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dcmgr/models/mac_lease.rb', line 9 def self.lease(mac_addr) case mac_addr.size when 12 when 6 # Assign bottom 6 device ID dynamically. vendor_id = mac_addr.dup begin mac_addr = vendor_id + ("%02x%02x%02x" % [rand(0xff),rand(0xff),rand(0xff)]) end while self.find(:mac_addr=> mac_addr) else raise ArgumentError, "Invalid MAC address string: 6 or 12 length of HEX value is needed." end create(:mac_addr=>mac_addr) end |