Revision a5dc3e23
Added by Daniel Lobato Garcia about 9 years ago
app/models/host/base.rb | ||
---|---|---|
end
|
||
|
||
def primary_interface
|
||
# Build a dummy object if host is unmanaged and without interfaces.
|
||
# Unmanaged hosts still have the interface requirement due to delegations and certain validations.
|
||
# A refactoring that allows unmanaged hosts to exist without interfaces is sorely needed.
|
||
build_required_interfaces unless managed? || interfaces.detect(&:primary)
|
||
get_interface_by_flag(:primary)
|
||
end
|
||
|
||
... | ... | |
end
|
||
|
||
def build_required_interfaces(attrs = {})
|
||
self.interfaces.build(attrs.merge(:primary => true, :type => 'Nic::Managed')) if self.primary_interface.nil?
|
||
self.primary_interface.provision = true if self.provision_interface.nil?
|
||
self.interfaces.build(attrs.merge(:primary => true, :type => 'Nic::Managed')) if get_interface_by_flag(:primary).nil?
|
||
get_interface_by_flag(:primary).provision = true if self.provision_interface.nil?
|
||
end
|
||
|
||
def set_interface(attributes, name, iface)
|
Also available in: Unified diff
Fixes #10111 - Use a dummy primary interface for unmanaged hosts
Unmanaged hosts require a host interface due to delegation of networking
attributes, and some others like 'name'. Since unmanaged hosts do not
necessarily have an interface associated (unless created through puppet
facts importer), we provide a dummy interface to prevent errors.
Ideally this should go away as soon as unmanaged hosts are a different
class or Host::Base, moving validations and other particularities
to Host::Managed.