Class: ForemanDatacenter::DeviceType

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Authorizable, ScopedSearchExtensions
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



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/models/foreman_datacenter/device_type.rb', line 48

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)


70
71
72
# File 'app/models/foreman_datacenter/device_type.rb', line 70

def child?
  subdevice_role == 'Child'
end

#devices_countObject



42
43
44
45
46
# File 'app/models/foreman_datacenter/device_type.rb', line 42

def devices_count
  @devices_count ||= self.class.where(id: id).
      joins(:devices).
      count
end

#management_interfacesObject



78
79
80
# File 'app/models/foreman_datacenter/device_type.rb', line 78

def management_interfaces
  interface_templates.select(&:mgmt_only)
end

#network_interfacesObject



74
75
76
# File 'app/models/foreman_datacenter/device_type.rb', line 74

def network_interfaces
  interface_templates.reject(&:mgmt_only)
end

#parent?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'app/models/foreman_datacenter/device_type.rb', line 66

def parent?
  subdevice_role == 'Parent'
end

#to_labelObject



82
83
84
# File 'app/models/foreman_datacenter/device_type.rb', line 82

def to_label
  model
end