Class: PEBuild::Cap::Facts::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/pe_build/cap/facts/base.rb

Overview

This class is abstract.

Subclass and override #architecture, #os_info and #release_info to implement for a particular guest operating system.

Base class for retrieving facts from guest VMs

This class implements a Guest Capability for Fact retrieval. Puppet will be queried, if installed. Otherwise, a minimal set of base facts willPuppetbe returned by #basic_facts.

Since:

  • 0.13.0

Direct Known Subclasses

POSIX, Windows

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine) ⇒ Base

Returns a new instance of Base.

Since:

  • 0.13.0



26
27
28
# File 'lib/pe_build/cap/facts/base.rb', line 26

def initialize(machine)
  @machine = machine
end

Instance Attribute Details

#machineObject (readonly)

Since:

  • 0.13.0



24
25
26
# File 'lib/pe_build/cap/facts/base.rb', line 24

def machine
  @machine
end

Class Method Details

.pebuild_facts(machine) ⇒ Hash

Retrieve facts from a guest VM

See #load_facts for implementation details.

Returns:

  • (Hash)

    A hash of facts.

Since:

  • 0.13.0



20
21
22
# File 'lib/pe_build/cap/facts/base.rb', line 20

def self.pebuild_facts(machine)
  new(machine).load_facts
end

Instance Method Details

#architectureString

Returns the native architecture of the OS

Returns:

  • (String)

    An architecture, such as i386 or x86_64.

Raises:

  • (NotImplementedError)

Since:

  • 0.13.0



73
74
75
# File 'lib/pe_build/cap/facts/base.rb', line 73

def architecture
  raise NotImplementedError
end

#basic_factsHash

Determine basic info about a guest

This function returns a minimal set of basic facts which should be sufficient to determine what software to install on the guest.

Returns:

  • (Hash)

    A hash containing the architecture and os facts.

Since:

  • 0.13.0



61
62
63
64
65
66
67
68
# File 'lib/pe_build/cap/facts/base.rb', line 61

def basic_facts
  {
    'architecture' => architecture,
    'os' => {
      'release' => release_info
    }.update(os_info)
  }
end

#load_factsHash

Load Facts from the guest VM

Returns:

  • (Hash)

    A hash of facts from Puppet, if installed.

  • (Hash)

    A hash containing the results of #basic_facts if Facter is not installed.

Since:

  • 0.13.0



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pe_build/cap/facts/base.rb', line 39

def load_facts
  unless puppet_path.nil?
    certname  = sudo("#{puppet_path} agent --configprint certname")[:stdout].chomp
    raw_facts = JSON.load(sudo("#{puppet_path} facts find --render-as json --terminus facter #{certname}")[:stdout])
    facts = raw_facts['values']
    # Keep the certname of the agent.
    facts['certname'] = certname
  else
    # Puppet isn't installed yet, so we gather a minimal set of info.
    facts = basic_facts
  end

  # JSON.load can do funny things. Sort by top-level key.
  Hash[facts.sort]
end

#os_infoHash

Returns info about the OS type

Returns:

  • (Hash)

    A hash containing the family of the operating system and, optionally, the name.

Raises:

  • (NotImplementedError)

Since:

  • 0.13.0



81
82
83
# File 'lib/pe_build/cap/facts/base.rb', line 81

def os_info
  raise NotImplementedError
end

#puppet_pathObject

Since:

  • 0.13.0



30
31
32
# File 'lib/pe_build/cap/facts/base.rb', line 30

def puppet_path
  @puppet_path ||= find_puppet
end

#release_infoHash

Returns info about the OS version

Returns:

  • (Hash)

    A hash containing the full version strying of the operating system and, optionally, the minor and major release versions.

Raises:

  • (NotImplementedError)

Since:

  • 0.13.0



90
91
92
# File 'lib/pe_build/cap/facts/base.rb', line 90

def release_info
  raise NotImplementedError
end