Class: Facter::Util::SolarisZones Private
- Inherits:
-
Object
- Object
- Facter::Util::SolarisZones
- Defined in:
- lib/facter/util/solaris_zones.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Provide a set of utility methods to interact with Solaris zones. This class is expected to be instantiated once per set of resolutions in order to cache the output of the zoneadm command, which can be quite expensive.
Instance Attribute Summary collapse
- #zone_hash ⇒ Object readonly private
- #zoneadm_cmd ⇒ Object readonly private
- #zoneadm_keys ⇒ Object readonly private
- #zoneadm_output ⇒ Object readonly private
Class Method Summary collapse
-
.add_facts ⇒ Object
private
add_facts defines all of the facts for solaris zones, for example ‘zones`, `zone_global_id`, `zone_global_status`, etc…
Instance Method Summary collapse
-
#add_dynamic_facts ⇒ Object
private
add_dynamic_facts defines all of the dynamic facts derived from parsing the output of the zoneadm command.
-
#count ⇒ Fixnum?
private
count returns the number of running zones, including the global zone.
-
#flush! ⇒ Object
private
flush! purges the saved data from the zoneadm_cmd output.
-
#flushed? ⇒ Boolean
private
flushed? returns true if the instance has no parsed data accessible via the #zone_hash method.
-
#initialize(opts = {}) ⇒ SolarisZones
constructor
private
A new instance of SolarisZones.
-
#refresh ⇒ Hash
private
refresh executes the zoneadm_cmd and stores the output data.
Constructor Details
#initialize(opts = {}) ⇒ SolarisZones
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of SolarisZones.
52 53 54 55 56 57 58 |
# File 'lib/facter/util/solaris_zones.rb', line 52 def initialize(opts = {}) @zoneadm_keys = [:id, :name, :status, :path, :uuid, :brand, :iptype] @zoneadm_cmd = opts[:zoneadm_cmd] || '/usr/sbin/zoneadm list -cp' if opts[:zoneadm_output] @zoneadm_output = opts[:zoneadm_output] end end |
Instance Attribute Details
#zone_hash ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/facter/util/solaris_zones.rb', line 12 def zone_hash @zone_hash end |
#zoneadm_cmd ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 |
# File 'lib/facter/util/solaris_zones.rb', line 13 def zoneadm_cmd @zoneadm_cmd end |
#zoneadm_keys ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 |
# File 'lib/facter/util/solaris_zones.rb', line 15 def zoneadm_keys @zoneadm_keys end |
#zoneadm_output ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 |
# File 'lib/facter/util/solaris_zones.rb', line 14 def zoneadm_output @zoneadm_output end |
Class Method Details
.add_facts ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
add_facts defines all of the facts for solaris zones, for example ‘zones`, `zone_global_id`, `zone_global_status`, etc… This method defines the static fact named `zones`. The value of this fact is the numver of zones reported by the zoneadm system command. The `zones` fact also defines all of the dynamic facts describing the following seven attribute values for each zone.
Zones may be added to the system while Facter is loaded. In order to define new dynamic facts that reflect this new information, the ‘virtual` will define new facts as a side effect of refreshing it’s own value.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/facter/util/solaris_zones.rb', line 30 def self.add_facts model = new model.refresh model.add_dynamic_facts Facter.add("zones") do setcode do model.refresh if model.flushed? model.add_dynamic_facts model.count end on_flush do model.flush! end end end |
Instance Method Details
#add_dynamic_facts ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
add_dynamic_facts defines all of the dynamic facts derived from parsing the output of the zoneadm command. The zone facts are dynamic, so this method has the behavior of figuring out what dynamic zone facts need to be defined and how they should be resolved.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/facter/util/solaris_zones.rb', line 69 def add_dynamic_facts model = self zone_hash.each_pair do |zone, attr_hsh| attr_hsh.keys.each do |attr| Facter.add("zone_#{zone}_#{attr}") do setcode do model.refresh if model.flushed? # Don't resolve if the zone has since been deleted if zone_hsh = model.zone_hash[zone] zone_hsh[attr] # the value end end on_flush do model.flush! end end end end end |
#count ⇒ Fixnum?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
count returns the number of running zones, including the global zone. This method is intended to be used from the setcode block of the ‘zones` fact.
131 132 133 134 135 |
# File 'lib/facter/util/solaris_zones.rb', line 131 def count if @zone_hash @zone_hash.size end end |
#flush! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
flush! purges the saved data from the zoneadm_cmd output
141 142 143 144 |
# File 'lib/facter/util/solaris_zones.rb', line 141 def flush! @zoneadm_output = nil @zone_hash = nil end |
#flushed? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
flushed? returns true if the instance has no parsed data accessible via the #zone_hash method.
153 154 155 |
# File 'lib/facter/util/solaris_zones.rb', line 153 def flushed? !@zone_hash end |
#refresh ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
refresh executes the zoneadm_cmd and stores the output data.
95 96 97 98 |
# File 'lib/facter/util/solaris_zones.rb', line 95 def refresh @zoneadm_output = Facter::Core::Execution.execute(zoneadm_cmd, {:on_fail => nil}) parse! end |