Skip to content

Commit

Permalink
Fixes #30627 - mac address is not required for virtual resources
Browse files Browse the repository at this point in the history
  • Loading branch information
domitea committed Aug 24, 2020
1 parent 6bd234d commit 586ec8f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/models/nic/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Base < ApplicationRecord
validate :mac_uniqueness,
:if => proc { |nic| nic.managed? && nic.host && nic.host.managed? && !nic.host.compute? && !nic.virtual? && nic.mac.present? }
validates :mac, :presence => true,
:if => proc { |nic| nic.managed? && nic.host_managed? && !nic.host.compute? && !nic.virtual? && (nic.provision? || nic.subnet.present? || nic.subnet6.present?) }
:if => proc { |nic| nic.managed? && nic.host_managed? && !nic.host.compute? && !nic.virtual? && !nic.host.compute_provides?(:mac) && (nic.provision? || nic.subnet.present? || nic.subnet6.present?) }
validate :validate_mac_is_unicast,
:if => proc { |nic| nic.managed? && !nic.virtual? }
validates :mac, :mac_address => true, :allow_blank => true
Expand All @@ -45,6 +45,8 @@ class Base < ApplicationRecord
validates :subnet, :belongs_to_host_taxonomy => { :taxonomy => :organization }
validates :subnet6, :belongs_to_host_taxonomy => { :taxonomy => :organization }

validate :check_blank_mac_for_virtual_resources, on: :create

scope :bmc, -> { where(:type => "Nic::BMC") }
scope :bonds, -> { where(:type => "Nic::Bond") }
scope :bridges, -> { where(:type => "Nic::Bridge") }
Expand Down Expand Up @@ -358,6 +360,12 @@ def interface_attribute_uniqueness(attr, base = Nic::Base.where(nil))
db_candidates = db_candidates.select { |c| c.id != id && in_memory_candidates.map(&:id).include?(c.id) }
errors.add(attr, :taken) if db_candidates.present?
end

def check_blank_mac_for_virtual_resources
if host.compute_provides?(:mac) && mac.present?
errors.add(:mac, _("can't be set for this compute resource because it's provided"))
end
end
end
end

Expand Down

0 comments on commit 586ec8f

Please sign in to comment.