puppet_facts 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ 2014-08-07 Release 0.2.1
2
+
3
+ Bugfixes:
4
+ - Rename opensuse- to sles- in PE3.3.
5
+
6
+ 2014-08-07 Release 0.2.0
7
+
8
+ Features:
9
+ - Add `on_pe_supported_platforms` to take an argument of target platforms
10
+ - Add `on_pe_unsupported_platforms` to perform the inverse
11
+ - Add ability to only check PE versions that match metadata requirements
@@ -1,4 +1,7 @@
1
1
  require 'json'
2
+ require 'puppet'
3
+ # From puppet
4
+ require 'semver'
2
5
 
3
6
  module PuppetFacts
4
7
 
@@ -15,17 +18,45 @@ module PuppetFacts
15
18
  PuppetFacts.pe_platforms[pe_version]
16
19
  end
17
20
 
18
- def on_pe_supported_platforms
19
- # This should filter based on set_pe_supported_platforms
21
+ def on_pe_supported_platforms(targets=nil)
22
+ targets = Array(targets) if targets
23
+
24
+ # TODO This should filter based on set_pe_supported_platforms
20
25
  facts = PuppetFacts.pe_platform_facts
21
26
  sup_facts = Hash.new
22
- #TODO how do we compare against this?
23
- # "name": "pe",
24
- # "version_requirement": "3.2.x"
25
- # "version_requirement": ">= 3.2.0 < 3.4.0"
26
27
  facts.each do |pe_ver,platforms|
27
- sup_facts[pe_ver] = platforms.select do |platform, facts|
28
- PuppetFacts.meta_supported_platforms.include?(platform)
28
+ pe_semver = "#{pe_ver.sub(/^PE/,'')}.0"
29
+ if SemVer[PuppetFacts.get_pe_requirement] === SemVer.new(pe_semver)
30
+ sup_facts[pe_ver] = platforms.select do |platform, facts|
31
+ if targets
32
+ PuppetFacts.meta_supported_platforms.include?(platform) && targets.include?(platform)
33
+ else
34
+ PuppetFacts.meta_supported_platforms.include?(platform)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ sup_facts
40
+ end
41
+
42
+ # We need the inverse, this is kind of ugly. I don't want to cram it into the
43
+ # other method however.
44
+ def on_pe_unsupported_platforms(targets=nil)
45
+ targets = Array(targets) if targets
46
+
47
+ # TODO This should filter based on set_pe_supported_platforms
48
+ facts = PuppetFacts.pe_platform_facts
49
+ sup_facts = Hash.new
50
+ facts.each do |pe_ver,platforms|
51
+ pe_semver = "#{pe_ver.sub(/^PE/,'')}.0"
52
+ if SemVer[PuppetFacts.get_pe_requirement] === SemVer.new(pe_semver)
53
+ sup_facts[pe_ver] = platforms.select do |platform, facts|
54
+ if targets
55
+ ! PuppetFacts.meta_supported_platforms.include?(platform) && ! targets.include?(platform)
56
+ else
57
+ ! PuppetFacts.meta_supported_platforms.include?(platform)
58
+ end
59
+ end
29
60
  end
30
61
  end
31
62
  sup_facts
@@ -44,15 +75,20 @@ module PuppetFacts
44
75
  def self.pe_versions
45
76
  @pe_versions ||= get_pe_versions
46
77
  end
78
+
79
+ # @api private
47
80
  def self.get_pe_versions
48
81
  @pe_dirs.collect do |dir|
49
82
  File.basename(dir)
50
83
  end
51
84
  end
52
85
 
86
+ # @api private
53
87
  def self.pe_platforms
54
88
  @pe_platforms ||= get_pe_platforms
55
89
  end
90
+
91
+ # @api private
56
92
  def self.get_pe_platforms
57
93
  @pe_dirs.inject({}) do |memo,pe_dir|
58
94
  pe_version = File.basename(pe_dir)
@@ -66,18 +102,24 @@ module PuppetFacts
66
102
  end
67
103
  end
68
104
 
105
+ # @api private
69
106
  def self.pe_facts_paths
70
107
  @pe_facts_paths ||= get_pe_facts_paths
71
108
  end
109
+
110
+ # @api private
72
111
  def self.get_pe_facts_paths
73
112
  @pe_dirs.collect do |dir|
74
113
  Dir[File.join(dir,"*")]
75
114
  end.flatten
76
115
  end
77
116
 
117
+ # @api private
78
118
  def self.pe_platform_facts
79
119
  @pe_platform_facts ||= get_pe_platform_facts
80
120
  end
121
+
122
+ # @api private
81
123
  def self.get_pe_platform_facts
82
124
  pe_facts_paths.inject({}) do |memo,file|
83
125
  pe_platform = File.basename(file.gsub(/\.facts/, ''))
@@ -92,10 +134,12 @@ module PuppetFacts
92
134
  end
93
135
  end
94
136
 
137
+ # @api private
95
138
  def self.meta_supported_platforms
96
139
  @meta_supported_platforms ||= get_meta_supported_platforms
97
140
  end
98
141
 
142
+ # @api private
99
143
  def self.meta_to_facts(input)
100
144
  meta_to_facts = {
101
145
  'RedHat' => 'redhat',
@@ -118,12 +162,10 @@ module PuppetFacts
118
162
  end
119
163
  end
120
164
 
165
+ # @api private
121
166
  def self.get_meta_supported_platforms
122
- if ! File.file?('metadata.json')
123
- fail StandardError, "Can't find metadata.json... dunno why"
124
- end
125
- metadata = JSON.parse(File.read('metadata.json'))
126
- if metadata.nil? or metadata['operatingsystem_support'].nil?
167
+ metadata = get_metadata
168
+ if metadata['operatingsystem_support'].nil?
127
169
  fail StandardError, "Unknown operatingsystem support"
128
170
  end
129
171
  os_sup = metadata['operatingsystem_support']
@@ -140,4 +182,31 @@ module PuppetFacts
140
182
  end
141
183
  end.flatten
142
184
  end
185
+
186
+ # @api private
187
+ def self.get_metadata
188
+ if ! File.file?('metadata.json')
189
+ fail StandardError, "Can't find metadata.json... dunno why"
190
+ end
191
+ metadata = JSON.parse(File.read('metadata.json'))
192
+ if metadata.nil?
193
+ fail StandardError, "Metadata is empty"
194
+ end
195
+ metadata
196
+ end
197
+
198
+ # @api private
199
+ def self.get_pe_requirement
200
+ metadata = get_metadata
201
+ if metadata['requirements'].nil?
202
+ fail StandardError, 'No requirements in metadata'
203
+ end
204
+ pe_requirement = metadata['requirements'].select do |x|
205
+ x['name'] == 'pe'
206
+ end
207
+ if pe_requirement.empty?
208
+ fail StandardError, 'No PE requirement found in metadata'
209
+ end
210
+ pe_requirement.first['version_requirement']
211
+ end
143
212
  end
@@ -1,5 +1,5 @@
1
1
  module PuppetFacts
2
2
  module Version
3
- STRING = '0.1.0'
3
+ STRING = '0.2.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet_facts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-28 00:00:00.000000000 Z
12
+ date: 2014-08-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Contains facts from many PE and POSS systems
15
15
  email:
@@ -19,6 +19,7 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - 3.6/ubuntu-1404-x86_64.facts
22
+ - CHANGELOG.md
22
23
  - PE2.8/centos-5-i386.facts
23
24
  - PE2.8/centos-5-x86_64.facts
24
25
  - PE2.8/centos-6-i386.facts
@@ -129,8 +130,6 @@ files:
129
130
  - PE3.3/debian-6-x86_64.facts
130
131
  - PE3.3/debian-7-i386.facts
131
132
  - PE3.3/debian-7-x86_64.facts
132
- - PE3.3/opensuse-11-i386.facts
133
- - PE3.3/opensuse-11-x86_64.facts
134
133
  - PE3.3/oracle-5-i386.facts
135
134
  - PE3.3/oracle-5-x86_64.facts
136
135
  - PE3.3/oracle-6-i386.facts
@@ -144,6 +143,8 @@ files:
144
143
  - PE3.3/scientific-5-x86_64.facts
145
144
  - PE3.3/scientific-6-i386.facts
146
145
  - PE3.3/scientific-6-x86_64.facts
146
+ - PE3.3/sles-11-i386.facts
147
+ - PE3.3/sles-11-x86_64.facts
147
148
  - PE3.3/ubuntu-1004-i386.facts
148
149
  - PE3.3/ubuntu-1004-x86_64.facts
149
150
  - PE3.3/ubuntu-1204-i386.facts