Class: Facts::Solaris::IsVirtual

Inherits:
Object
  • Object
show all
Defined in:
lib/facter/facts/solaris/is_virtual.rb

Constant Summary collapse

FACT_NAME =
'is_virtual'

Instance Method Summary collapse

Constructor Details

#initializeIsVirtual

Returns a new instance of IsVirtual.



8
9
10
# File 'lib/facter/facts/solaris/is_virtual.rb', line 8

def initialize
  @log = Facter::Log.new(self)
end

Instance Method Details

#call_the_resolverObject



12
13
14
15
16
17
18
19
20
# File 'lib/facter/facts/solaris/is_virtual.rb', line 12

def call_the_resolver
  @log.debug('Solaris Virtual Resolver')

  fact_value = check_ldom || check_zone || check_xen || check_other_facts || 'physical'

  @log.debug("Fact value is: #{fact_value}")

  Facter::ResolvedFact.new(FACT_NAME, check_if_virtual(fact_value))
end

#check_if_virtual(found_vm) ⇒ Object



59
60
61
# File 'lib/facter/facts/solaris/is_virtual.rb', line 59

def check_if_virtual(found_vm)
  Facter::Util::Facts::PHYSICAL_HYPERVISORS.count(found_vm).zero?
end

#check_ldomObject



22
23
24
25
26
27
# File 'lib/facter/facts/solaris/is_virtual.rb', line 22

def check_ldom
  @log.debug('Checking LDoms')
  return unless Facter::Resolvers::Solaris::Ldom.resolve(:role_control) == 'false'

  Facter::Resolvers::Solaris::Ldom.resolve(:role_impl)
end

#check_other_factsObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/facter/facts/solaris/is_virtual.rb', line 43

def check_other_facts
  isa = Facter::Resolvers::Uname.resolve(:processor)
  klass = isa == 'sparc' ? 'DmiSparc' : 'Dmi'

  product_name = Facter::Resolvers::Solaris.const_get(klass).resolve(:product_name)
  bios_vendor = Facter::Resolvers::Solaris.const_get(klass).resolve(:bios_vendor)

  return 'kvm' if bios_vendor&.include?('Amazon EC2')

  return unless product_name

  Facter::Util::Facts::HYPERVISORS_HASH.each { |key, value| return value if product_name.include?(key) }

  nil
end

#check_xenObject



38
39
40
41
# File 'lib/facter/facts/solaris/is_virtual.rb', line 38

def check_xen
  @log.debug('Checking XEN')
  Facter::Resolvers::Xen.resolve(:vm)
end

#check_zoneObject



29
30
31
32
33
34
35
36
# File 'lib/facter/facts/solaris/is_virtual.rb', line 29

def check_zone
  @log.debug('Checking LDoms')
  zone_name = Facter::Resolvers::Solaris::ZoneName.resolve(:current_zone_name)

  return if zone_name == 'global'

  'zone'
end