Created
September 15, 2015 12:45
-
-
Save ares/35d72ff3af6f60d2ccda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def set_interfaces(parser) | |
# if host has no information in primary interface we try to match it and update it | |
# instead of creating new interface, suggested primary interface mac and identifier | |
# is saved to primary interface so we match it in updating code below | |
if !self.managed? && self.primary_interface.mac.blank? && self.primary_interface.identifier.blank? | |
identifier, values = parser.suggested_primary_interface(self) | |
self.primary_interface.mac = Net::Validations.normalize_mac(values[:macaddress]) | |
self.primary_interface.identifier = identifier | |
self.primary_interface.save! | |
end | |
interface_objects = parser.interfaces.map do |name, attributes| | |
iface = get_interface_scope(name, attributes).first || interface_class(name).new(:managed => false) | |
# create or update existing interface | |
set_interface(attributes, name, iface) | |
iface | |
end | |
self.interfaces = interface_objects | |
ipmi = parser.ipmi_interface | |
if ipmi.present? | |
existing = self.interfaces.where(:mac => ipmi[:macaddress], :type => Nic::BMC).first | |
iface = existing || Nic::BMC.new(:managed => false) | |
iface.provider ||= 'IPMI' | |
set_interface(ipmi, 'ipmi', iface) | |
self.interfaces << iface | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment