-
Notifications
You must be signed in to change notification settings - Fork 983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixes #9296 - Ensure bond has a mac address of one of attached iface #2142
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 } | ||
|
||
|
@@ -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| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps this would be better mac_addresses = self.host.interfaces.where(:identifier => attached_devices_identifiers).pluck(:mac) |
||
self.host.interfaces.where(identifier: a).first.mac | ||
} | ||
self.mac = nil unless mac_addresses.include? self.mac | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd combine L53-L56 like this mac_addresses = mac_addresses.compact # actually this should get to previous mac_addresses SQL...
self.mac = mac_addresses.first unless mac_addresses.include?(self.mac) overall I'm not sure about this, we'd silently override user custom input if it's another mac, I'd rather override the mac only if it's nil, what do you think? |
||
unless self.mac | ||
self.mac = mac_addresses.first | ||
end | ||
self.update_column(:mac, self.mac) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we move it to before validation, it will be saved in normal save chain (within transaction) |
||
end | ||
end | ||
|
||
Base.register_type(Bond) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this happen before validation?