Class: PEBuild::Cap::Facts::Base Abstract
- Inherits:
-
Object
- Object
- PEBuild::Cap::Facts::Base
- Defined in:
- lib/pe_build/cap/facts/base.rb
Overview
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.
Instance Attribute Summary collapse
- #machine ⇒ Object readonly
Class Method Summary collapse
-
.pebuild_facts(machine) ⇒ Hash
Retrieve facts from a guest VM.
Instance Method Summary collapse
-
#architecture ⇒ String
Returns the native architecture of the OS.
-
#basic_facts ⇒ Hash
Determine basic info about a guest.
-
#initialize(machine) ⇒ Base
constructor
A new instance of Base.
-
#load_facts ⇒ Hash
Load Facts from the guest VM.
-
#os_info ⇒ Hash
Returns info about the OS type.
- #puppet_path ⇒ Object
-
#release_info ⇒ Hash
Returns info about the OS version.
Constructor Details
#initialize(machine) ⇒ Base
Returns a new instance of Base.
26 27 28 |
# File 'lib/pe_build/cap/facts/base.rb', line 26 def initialize(machine) @machine = machine end |
Instance Attribute Details
#machine ⇒ Object (readonly)
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.
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
#architecture ⇒ String
Returns the native architecture of the OS
73 74 75 |
# File 'lib/pe_build/cap/facts/base.rb', line 73 def architecture raise NotImplementedError end |
#basic_facts ⇒ Hash
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.
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_facts ⇒ Hash
Load Facts from the guest VM
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_info ⇒ Hash
Returns info about the OS type
81 82 83 |
# File 'lib/pe_build/cap/facts/base.rb', line 81 def os_info raise NotImplementedError end |
#puppet_path ⇒ Object
30 31 32 |
# File 'lib/pe_build/cap/facts/base.rb', line 30 def puppet_path @puppet_path ||= find_puppet end |
#release_info ⇒ Hash
Returns info about the OS version
90 91 92 |
# File 'lib/pe_build/cap/facts/base.rb', line 90 def release_info raise NotImplementedError end |