Module: Puppet::Sap::Facts::Instances
- Defined in:
- lib/puppet/sap/facts.rb
Overview
Honestly, I shamelessly stole this structure from the puppet-jenkins module. This component contains all of the actual code generating fact data for a given host.
Constant Summary collapse
- SAP_DIR =
Constant paths
'/usr/sap'.freeze
- DB2_DIR =
'/db2'.freeze
- SCMOPT_DIR =
'/scmopt'.freeze
- LC_DIR =
'/sapdb'.freeze
- LC_DATA_DIR =
'/sapdb/data'.freeze
Class Method Summary collapse
-
.add_sid(sid) ⇒ Object
Add the specified SID to the current structure unless it’s already present.
-
.check_db2 ⇒ Object
Identify all local db2 instances and collect relevant details.
-
.check_livecache ⇒ Object
Indentify all local liveCache components (sapdb) and return relevant details.
-
.check_profiles(sid, insttype, instnum) ⇒ Array[String]
Identifies the profile files corresponding to the current instance.
-
.check_sap_instances ⇒ Array[String]
Constructs a listing of all local instances via the contents of the /usr/sap directory.
-
.check_sap_sid(sid) ⇒ Object
Determine the local instance details for a given SAP SID Returns a hash containing the following detail for each instance number * ‘type` - SAP instance type name, e.g.
-
.check_scmopt ⇒ Object
Check for the presence of an SCM optimizer install.
-
.get_file_sid(file) ⇒ String
Determine SID from file owner.
-
.initialize ⇒ Object
Bastardized initialization method which triggers all of the data extractions for this fact.
-
.inst_classes ⇒ Array[String]
Returns a sorted unique array listing the SAP component classes present on this node.
-
.list_dir(dir) ⇒ Array[String]
Lists the contents of the specified directory if it exists.
-
.sid?(str) ⇒ Boolean
Constant Patterns.
-
.sid_data ⇒ Hash[String, Hash]
Returns the hash of SID data reflected by this node.
Class Method Details
.add_sid(sid) ⇒ Object
Add the specified SID to the current structure unless it’s already present
67 68 69 70 71 72 |
# File 'lib/puppet/sap/facts.rb', line 67 def self.add_sid(sid) return if @sid_data.key?(sid) inst = {} inst[:instances] = {} @sid_data[sid] = inst end |
.check_db2 ⇒ Object
Identify all local db2 instances and collect relevant details
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/puppet/sap/facts.rb', line 75 def self.check_db2 entries = list_dir(DB2_DIR) entries.each do |entry| next unless sid?(entry) sid = entry.strip inst_data = {} inst_data[:type] = 'db2' inst_data[:class] = 'db-db2' @inst_classes << inst_data[:class] # TODO: get the version of db2 from /db2/db2#{sid}/sqllib/bin/db2level add_sid(sid) @sid_data[sid][:instances][:database] = inst_data end end |
.check_livecache ⇒ Object
Indentify all local liveCache components (sapdb) and return relevant details
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/puppet/sap/facts.rb', line 95 def self.check_livecache entries = list_dir(LC_DIR) return if entries.empty? # Determine the SID for this local livecache data sid = get_file_sid(LC_DATA_DIR) return if sid.nil? add_sid(sid) inst_data = {} inst_data[:type] = 'livecache' # Check to see if the livecache client is present if entries.include?('programs') && entries.include?('data') # TODO: capture the version via the following # /sapdb/programs/bin/sdbverify -V @inst_classes << 'db-livecache-client' inst_data[:client] = true end # Detect the presence of a database instance databases = {} entries.each do |entry| next unless sid?(entry) # TODO: capture the version via the following # /sapdb/$inst/db/pgm/kernel -V @inst_classes << 'db-livecache' databases[entry] = true end inst_data[:class] = if databases.empty? 'db-livecache-client' else 'db-livecache' end inst_data[:databases] = databases unless databases.empty? @sid_data[sid][:instances][:livecache] = inst_data end |
.check_profiles(sid, insttype, instnum) ⇒ Array[String]
Identifies the profile files corresponding to the current instance
profile file
244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/puppet/sap/facts.rb', line 244 def self.check_profiles(sid, insttype, instnum) files = [] dir = File.join(SAP_DIR, sid, '/SYS/profile') return files unless Dir.exist?(dir) entries = list_dir(dir) entries.each do |entry| next unless entry.match?(%r{_#{insttype}#{instnum}_}) files.push(File.join(dir, entry.strip)) end # rubocop:disable Style/RedundantReturn return files # rubocop:enable Style/RedundantReturn end |
.check_sap_instances ⇒ Array[String]
Constructs a listing of all local instances via the contents of the /usr/sap directory.
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/puppet/sap/facts.rb', line 167 def self.check_sap_instances entries = list_dir(SAP_DIR) entries.each do |entry| add_sid(entry.strip) if sid?(entry) end @sid_data.each do |sid, data| data[:instances] = check_sap_sid(sid) end end |
.check_sap_sid(sid) ⇒ Object
Determine the local instance details for a given SAP SID Returns a hash containing the following detail for each instance number
-
‘type` - SAP instance type name, e.g. ’ERS’
-
‘profiles` - Array of Absolute Paths to the profile files for this
return [Hash[String, Hash]] Keyed by instance number
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/puppet/sap/facts.rb', line 184 def self.check_sap_sid(sid) instances = {} sid_dir = File.join(SAP_DIR, sid) entries = list_dir(sid_dir) entries.each do |instdir| inst_data = {} # If the entry doesn't match the format skip it unless %r!^(?<insttype>[A-Z]+)(?<instnum>[0-9]{2})$! =~ instdir next end # Capture the raw instance type inst_data[:type] = insttype.strip # Determine the component category of this instance inst_data[:class] = case inst_data[:type] when %r{^D} dual_dir = File.join(sid_dir, instdir, 'j2ee') if Dir.exist?(dual_dir) 'as-dual' else 'as-abap' end when %r{^J} 'as-java' when %r{ASCS} 'cs-abap' when %r{^SCS} 'cs-java' when %r{^W} 'webdisp' when %r{^G} 'gateway' when %r{ERS} 'ers' end @inst_classes << inst_data[:class] # Retrieve the profile data inst_data[:profiles] = check_profiles(sid, insttype.strip, instnum.strip) # Record the instance entry instances[instnum.strip] = inst_data end # rubocop:disable Style/RedundantReturn return instances # rubocop:enable Style/RedundantReturn end |
.check_scmopt ⇒ Object
Check for the presence of an SCM optimizer install
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/puppet/sap/facts.rb', line 138 def self.check_scmopt dir = SCMOPT_DIR # Capture the SID sid = get_file_sid(dir) return if sid.nil? # Record the class presence inst_class = 'scmopt' @inst_classes << inst_class # Capture the instance details add_sid(sid) inst_data = {} inst_data[:type] = 'scmopt' inst_data[:class] = inst_class entries = list_dir(dir) optimizers = [] entries.each do |entry| next unless entry.match?(%r{svr$}) optimizers.push(entry.strip) end inst_data[:optimizers] = optimizers @sid_data[sid][:instances][:scmopt] = inst_data end |
.get_file_sid(file) ⇒ String
Determine SID from file owner. This works for owners which match the pattern ^[a-z0-9]3
271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/puppet/sap/facts.rb', line 271 def self.get_file_sid(file) return nil unless File.exist?(file) uid = File.stat(file).uid sid = Etc.getpwuid(uid).name[0, 3].upcase if sid?(sid) sid else nil end end |
.initialize ⇒ Object
Bastardized initialization method which triggers all of the data extractions for this fact.
58 59 60 61 62 63 |
# File 'lib/puppet/sap/facts.rb', line 58 def self.initialize check_sap_instances check_db2 check_livecache check_scmopt end |
.inst_classes ⇒ Array[String]
Returns a sorted unique array listing the SAP component classes present on this node
287 288 289 |
# File 'lib/puppet/sap/facts.rb', line 287 def self.inst_classes @inst_classes.uniq end |
.list_dir(dir) ⇒ Array[String]
Lists the contents of the specified directory if it exists
262 263 264 265 |
# File 'lib/puppet/sap/facts.rb', line 262 def self.list_dir(dir) return [] unless Dir.exist?(dir) Dir.entries(dir) end |
.sid?(str) ⇒ Boolean
Constant Patterns
52 53 54 |
# File 'lib/puppet/sap/facts.rb', line 52 def self.sid?(str) str =~ %r{[A-Z0-9]{3}} end |
.sid_data ⇒ Hash[String, Hash]
Returns the hash of SID data reflected by this node.
that SID
295 296 297 |
# File 'lib/puppet/sap/facts.rb', line 295 def self.sid_data @sid_data end |