Class: Dcmgr::Models::InstanceNic
- Inherits:
-
BaseNew
- Object
- Sequel::Model
- BaseNew
- Dcmgr::Models::InstanceNic
show all
- Defined in:
- lib/dcmgr/models/instance_nic.rb
Overview
Network interface for running instance.
Constant Summary
Constants inherited
from BaseNew
BaseNew::LOCK_TABLES_KEY
Instance Method Summary
collapse
Methods inherited from BaseNew
Proxy, dataset, install_data, install_data_hooks, lock!, unlock!
Instance Method Details
#before_destroy ⇒ Object
44
45
46
47
48
|
# File 'lib/dcmgr/models/instance_nic.rb', line 44
def before_destroy
MacLease.find(:mac_addr=>self.mac_addr).destroy
ip && ip.destroy
super
end
|
#before_validation ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/dcmgr/models/instance_nic.rb', line 27
def before_validation
newlease=nil
m = self[:mac_addr] = normalize_mac_addr(self[:mac_addr])
if m
if m.size == 6
newlease = MacLease.lease(m)
else
MacLease.create(:mac_addr=>m)
end
else
newlease = MacLease.lease()
end
self[:mac_addr] = newlease.mac_addr if newlease
super
end
|
#pretty_mac_addr(delim = ':') ⇒ Object
58
59
60
|
# File 'lib/dcmgr/models/instance_nic.rb', line 58
def pretty_mac_addr(delim=':')
self.mac_addr.unpack('A2'*6).join(delim)
end
|
#to_hash ⇒ Object
21
22
23
24
25
|
# File 'lib/dcmgr/models/instance_nic.rb', line 21
def to_hash
h = values.dup.merge(super)
h.delete(:instance_id)
h
end
|
#validate ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/dcmgr/models/instance_nic.rb', line 50
def validate
super
unless self.mac_addr.size == 12 && self.mac_addr =~ /^[0-9a-f]{12}$/
errors.add(:mac_addr, "Invalid mac address syntax: #{self.mac_addr}")
end
end
|