Skip to content

Commit

Permalink
fixes #9296 - Ensure bond has a mac address of one of attached iface
Browse files Browse the repository at this point in the history
In order for some operations (like changing the IP address) of a bond to
work, it must have a mac address. This ensures that a) a mac address is
assigned, and b) that it belongs to one of the interfaces involved in
the bond.
  • Loading branch information
bcrochet committed Feb 9, 2015
1 parent c1a73b1 commit 3ca4b40
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/models/nic/bond.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Bond < Managed
validates :attached_devices, :format => { :with => /\A[a-z0-9#{SEPARATOR}.:_-]+\Z/ }, :allow_blank => true

before_save :ensure_virtual
after_save :ensure_mac

register_to_enc_transformation :type, lambda { |type| type.constantize.humanized_name }

Expand Down Expand Up @@ -44,6 +45,17 @@ def ensure_virtual
def enc_attributes
@enc_attributes ||= (super + %w(mode attached_devices bond_options))
end

def ensure_mac
mac_addresses = attached_devices_identifiers.collect { |a|
self.host.interfaces.where(identifier: a).first.mac
}
self.mac = nil unless mac_addresses.include? self.mac
unless self.mac
self.mac = mac_addresses.first
end
self.update_column(:mac, self.mac)
end
end

Base.register_type(Bond)
Expand Down

0 comments on commit 3ca4b40

Please sign in to comment.