Module: PuppetFacts

Defined in:
lib/puppet_facts.rb,
lib/puppet_facts/version.rb

Defined Under Namespace

Modules: Version

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_meta_supported_platformsObject

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.



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/puppet_facts.rb', line 166

def self.get_meta_supported_platforms
   = 
  if ['operatingsystem_support'].nil?
    fail StandardError, "Unknown operatingsystem support"
  end
  os_sup = ['operatingsystem_support']

  os_sup.collect do |os_rel|
    os = meta_to_facts(os_rel['operatingsystem'])
    #os = meta_to_facts[os_sup['operatingsystem']]
    os_rel['operatingsystemrelease'].collect do |release|
      rel = meta_to_facts(release)
      [
        "#{os}-#{rel}-i386",
        "#{os}-#{rel}-x86_64"
      ]
    end
  end.flatten
end

.get_metadataObject

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.



187
188
189
190
191
192
193
194
195
196
# File 'lib/puppet_facts.rb', line 187

def self.
  if ! File.file?('metadata.json')
    fail StandardError, "Can't find metadata.json... dunno why"
  end
   = JSON.parse(File.read('metadata.json'))
  if .nil?
    fail StandardError, "Metadata is empty"
  end
  
end

.get_pe_facts_pathsObject

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.



111
112
113
114
115
# File 'lib/puppet_facts.rb', line 111

def self.get_pe_facts_paths
  @pe_dirs.collect do |dir|
    Dir[File.join(dir,"*")]
  end.flatten
end

.get_pe_platform_factsObject

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.



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/puppet_facts.rb', line 123

def self.get_pe_platform_facts
  pe_facts_paths.inject({}) do |memo,file|
    pe_platform = File.basename(file.gsub(/\.facts/, ''))
    pe_version = File.basename(File.dirname(file))
    memo[pe_version] = Hash.new unless memo[pe_version]
    memo[pe_version][pe_platform] = Hash.new
    File.read(file).each_line do |line|
      key, value = line.split(' => ')
      memo[pe_version][pe_platform][key.to_sym] = value.chomp unless value.nil?
    end
    memo
  end
end

.get_pe_platformsObject

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.



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/puppet_facts.rb', line 92

def self.get_pe_platforms
  @pe_dirs.inject({}) do |memo,pe_dir|
    pe_version = File.basename(pe_dir)
    if Dir[File.join(@proj_root,pe_version,"*")].empty?
      fail(StandardError, "Puppet facts missing for #{pe_version}")
    end
    memo[pe_version] = Dir[File.join(@proj_root,pe_version,"*")].collect do |facts|
      File.basename(facts.gsub(/\.facts/, ''))
    end
    memo
  end
end

.get_pe_requirementObject

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.



199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/puppet_facts.rb', line 199

def self.get_pe_requirement
   = 
  if ['requirements'].nil?
    fail StandardError, 'No requirements in metadata'
  end
  pe_requirement = ['requirements'].select do |x|
    x['name'] == 'pe'
  end
  if pe_requirement.empty?
    fail StandardError, 'No PE requirement found in metadata'
  end
  pe_requirement.first['version_requirement']
end

.get_pe_versionsObject

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.



80
81
82
83
84
# File 'lib/puppet_facts.rb', line 80

def self.get_pe_versions
  @pe_dirs.collect do |dir|
    File.basename(dir)
  end
end

.meta_supported_platformsObject

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.



138
139
140
# File 'lib/puppet_facts.rb', line 138

def self.meta_supported_platforms
  @meta_supported_platforms ||= get_meta_supported_platforms
end

.meta_to_facts(input) ⇒ 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.



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/puppet_facts.rb', line 143

def self.meta_to_facts(input)
  meta_to_facts = {
    'RedHat' => 'redhat',
    'CentOS' => 'centos',
    'Ubuntu' => 'ubuntu',
    'OracleLinux' => 'oracle',
    'SLES' => 'sles',
    'Scientific' => 'scientific',
    'Debian' => 'debian',
    '14.04' => '1404',
    '12.04' => '1204',
    '10.04' => '1004',
    '11 SP1' => '11',
  }
  ans = meta_to_facts[input]
  if ans
    ans
  else
    input
  end
end

.pe_facts_pathsObject

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.



106
107
108
# File 'lib/puppet_facts.rb', line 106

def self.pe_facts_paths
  @pe_facts_paths ||= get_pe_facts_paths
end

.pe_platform_factsObject

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.



118
119
120
# File 'lib/puppet_facts.rb', line 118

def self.pe_platform_facts
  @pe_platform_facts ||= get_pe_platform_facts
end

.pe_platformsObject

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.



87
88
89
# File 'lib/puppet_facts.rb', line 87

def self.pe_platforms
  @pe_platforms ||= get_pe_platforms
end

.pe_versionsObject

Returns array of PE versions



75
76
77
# File 'lib/puppet_facts.rb', line 75

def self.pe_versions
  @pe_versions ||= get_pe_versions
end

Instance Method Details

#available_pe_platforms(pe_version) ⇒ Object

Returns array of PE platforms for given PE version



17
18
19
# File 'lib/puppet_facts.rb', line 17

def available_pe_platforms(pe_version)
  PuppetFacts.pe_platforms[pe_version]
end

#available_pe_versionsObject



12
13
14
# File 'lib/puppet_facts.rb', line 12

def available_pe_versions
  PuppetFacts.pe_versions
end

#on_pe_supported_platforms(targets = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/puppet_facts.rb', line 21

def on_pe_supported_platforms(targets=nil)
  targets = Array(targets) if targets

  # TODO This should filter based on set_pe_supported_platforms
  facts = PuppetFacts.pe_platform_facts
  sup_facts = Hash.new
  facts.each do |pe_ver,platforms|
    pe_semver = "#{pe_ver.sub(/^PE/,'')}.0"
    if SemVer[PuppetFacts.get_pe_requirement] === SemVer.new(pe_semver)
      sup_facts[pe_ver] = platforms.select do |platform, facts|
        if targets
          PuppetFacts.meta_supported_platforms.include?(platform) && targets.include?(platform)
        else
          PuppetFacts.meta_supported_platforms.include?(platform)
        end
      end
    end
  end
  sup_facts
end

#on_pe_unsupported_platforms(targets = nil) ⇒ Object

We need the inverse, this is kind of ugly. I don’t want to cram it into the other method however.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/puppet_facts.rb', line 44

def on_pe_unsupported_platforms(targets=nil)
  targets = Array(targets) if targets

  # TODO This should filter based on set_pe_supported_platforms
  facts = PuppetFacts.pe_platform_facts
  sup_facts = Hash.new
  facts.each do |pe_ver,platforms|
    pe_semver = "#{pe_ver.sub(/^PE/,'')}.0"
    if SemVer[PuppetFacts.get_pe_requirement] === SemVer.new(pe_semver)
      sup_facts[pe_ver] = platforms.select do |platform, facts|
        if targets
          ! PuppetFacts.meta_supported_platforms.include?(platform) && ! targets.include?(platform)
        else
          ! PuppetFacts.meta_supported_platforms.include?(platform)
        end
      end
    end
  end
  sup_facts
end

#set_pe_supported_platforms(metadata_format_hash) ⇒ Object



8
9
10
# File 'lib/puppet_facts.rb', line 8

def set_pe_supported_platforms()
  PuppetFacts.pe_supported_platforms
end