Project

General

Profile

Download (1.6 KB) Statistics
| Branch: | Tag: | Revision:
8838eb42 Ohad Levy
module Nic
class BMC < Managed
PROVIDERS = %w(IPMI)
6a2fce1f Marek Hulan
before_validation :ensure_physical
3b27c173 Marek Hulan
before_validation { |nic| nic.provider.try(:upcase!) }
d455f32c Marek Hulan
validates :provider, :presence => true, :inclusion => { :in => PROVIDERS }
6a2fce1f Marek Hulan
validates :mac, :presence => true, :if => :managed?
a9c70fb4 Shimon Shtein
validate :validate_bmc_proxy
6a2fce1f Marek Hulan
def virtual
false
end
alias_method :virtual?, :virtual
ecd9c9c6 Joseph Mitchell Magen
bb3572ff Daniel Lobato
register_to_enc_transformation :type, ->(type) { type.constantize.humanized_name }
177a281a Marek Hulan
40df7dfb Daniel Lobato
def proxy
a9c70fb4 Shimon Shtein
proxy = bmc_proxy
40df7dfb Daniel Lobato
raise Foreman::Exception.new(N_('Unable to find a proxy with BMC feature')) if proxy.nil?
ProxyAPI::BMC.new({ :host_ip => ip,
:url => proxy.url,
:user => username,
:password => password })
end

cad1b13c Tomas Strachota
def self.humanized_name
N_('BMC')
end

a1b2ee53 Marek Hulan
private

6a2fce1f Marek Hulan
def ensure_physical
self.virtual = false
true # don't stop validation chain
end

a1b2ee53 Marek Hulan
def enc_attributes
@enc_attributes ||= (super + %w(username password provider))
end
a9c70fb4 Shimon Shtein
private

def bmc_proxy
if subnet.present?
proxy = subnet.proxies.find { |subnet_proxy| subnet_proxy.has_feature?('BMC') }
end
proxy ||= SmartProxy.unscoped.with_features("BMC").first
proxy
end

def validate_bmc_proxy
return true unless managed?
return true if host && !host_managed?
unless bmc_proxy
errors.add(:type, N_('There is no proxy with BMC feature set up. Please register a smart proxy with this feature.'))
end
end
8838eb42 Ohad Levy
end
cad1b13c Tomas Strachota
Base.register_type(BMC)
3cdaa292 Dmitri Dolguikh
end