Class: ForemanDatacenter::DeviceType

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/foreman_datacenter/device_type.rb

Constant Summary collapse

SUBDEVICE_ROLES =
['None', 'Parent', 'Child'].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_host(host) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/foreman_datacenter/device_type.rb', line 27

def self.for_host(host)
  fact = host.fact_value_by_name('productname')
  if fact
    device_type = find_by(model: fact.value)
    if device_type
      device_type
    else
      manufacturer = Manufacturer.for_host(host)
      if manufacturer
        create(
          manufacturer: manufacturer,
          model: fact.value
        )
      end
    end
  end
end

Instance Method Details

#child?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/models/foreman_datacenter/device_type.rb', line 49

def child?
  subdevice_role == 'Child'
end

#management_interfacesObject



57
58
59
# File 'app/models/foreman_datacenter/device_type.rb', line 57

def management_interfaces
  interface_templates.select(&:mgmt_only)
end

#network_interfacesObject



53
54
55
# File 'app/models/foreman_datacenter/device_type.rb', line 53

def network_interfaces
  interface_templates.reject(&:mgmt_only)
end

#parent?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/models/foreman_datacenter/device_type.rb', line 45

def parent?
  subdevice_role == 'Parent'
end