66# Licensed under the Apache License, Version 2.0 (the "License");
77# you may not use this file except in compliance with the License.
88# You may obtain a copy of the License at
9- #
9+ #
1010# http://www.apache.org/licenses/LICENSE-2.0
11- #
11+ #
1212# Unless required by applicable law or agreed to in writing, software
1313# distributed under the License is distributed on an "AS IS" BASIS,
1414# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2525
2626class Chef
2727 class Platform
28-
28+
2929 @platforms = {
3030 :mac_os_x => {
3131 :default => {
@@ -97,27 +97,28 @@ class Platform
9797 :http_request => Chef ::Provider ::HttpRequest ,
9898 :route => Chef ::Provider ::Route ,
9999 :ifconfig => Chef ::Provider ::Ifconfig ,
100- :ruby_block => Chef ::Provider ::RubyBlock
100+ :ruby_block => Chef ::Provider ::RubyBlock ,
101+ :erl_call => Chef ::Provider ::ErlCall
101102 }
102103 }
103104
104105 class << self
105106 attr_accessor :platforms
106-
107+
107108 include Chef ::Mixin ::ParamsValidate
108-
109+
109110 def find ( name , version )
110111 provider_map = @platforms [ :default ] . clone
111-
112+
112113 name_sym = name
113114 if name . kind_of? ( String )
114115 name . downcase!
115116 name . gsub! ( /\s / , "_" )
116117 name_sym = name . to_sym
117118 end
118-
119+
119120 if @platforms . has_key? ( name_sym )
120- if @platforms [ name_sym ] . has_key? ( version )
121+ if @platforms [ name_sym ] . has_key? ( version )
121122 Chef ::Log . debug ( "Platform #{ name . to_s } version #{ version } found" )
122123 if @platforms [ name_sym ] . has_key? ( :default )
123124 provider_map . merge! ( @platforms [ name_sym ] [ :default ] )
@@ -131,7 +132,7 @@ def find(name, version)
131132 end
132133 provider_map
133134 end
134-
135+
135136 def find_provider ( platform , version , resource_type )
136137 pmap = Chef ::Platform . find ( platform , version )
137138 rtkey = resource_type
@@ -144,46 +145,46 @@ def find_provider(platform, version, resource_type)
144145 else
145146 Chef ::Log . error ( "#{ rtkey . inspect } #{ pmap . inspect } " )
146147 raise (
147- ArgumentError ,
148+ ArgumentError ,
148149 "Cannot find a provider for #{ resource_type } on #{ platform } version #{ version } "
149150 )
150151 end
151152 end
152-
153+
153154 def find_platform_and_version ( node )
154155 platform = nil
155156 version = nil
156-
157+
157158 if node [ :platform ]
158159 platform = node [ :platform ]
159160 elsif node . attribute? ( "os" )
160161 platform = node [ :os ]
161162 end
162-
163+
163164 raise ArgumentError , "Cannot find a platform for #{ node } " unless platform
164-
165+
165166 if node [ :platform_version ]
166167 version = node [ :platform_version ]
167168 elsif node [ :os_version ]
168169 version = node [ :os_version ]
169170 elsif node [ :os_release ]
170171 version = node [ :os_release ]
171172 end
172-
173+
173174 raise ArgumentError , "Cannot find a version for #{ node } " unless version
174-
175+
175176 return platform , version
176177 end
177-
178+
178179 def provider_for_node ( node , resource_type )
179180 find_provider_for_node ( node , resource_type ) . new ( node , resource_type )
180181 end
181182
182183 def find_provider_for_node ( node , resource_type )
183- platform , version = find_platform_and_version ( node )
184+ platform , version = find_platform_and_version ( node )
184185 provider = find_provider ( platform , version , resource_type )
185186 end
186-
187+
187188 def set ( args )
188189 validate (
189190 args ,
@@ -204,14 +205,14 @@ def set(args)
204205 }
205206 }
206207 )
207- if args . has_key? ( :platform )
208+ if args . has_key? ( :platform )
208209 if args . has_key? ( :version )
209210 if @platforms . has_key? ( args [ :platform ] )
210211 if @platforms [ args [ :platform ] ] . has_key? ( args [ :version ] )
211212 @platforms [ args [ :platform ] ] [ args [ :version ] ] [ args [ :resource ] . to_sym ] = args [ :provider ]
212213 else
213214 @platforms [ args [ :platform ] ] [ args [ :version ] ] = {
214- args [ :resource ] . to_sym => args [ :provider ]
215+ args [ :resource ] . to_sym => args [ :provider ]
215216 }
216217 end
217218 else
@@ -222,7 +223,7 @@ def set(args)
222223 }
223224 end
224225 else
225- if @platforms . has_key? ( args [ :platform ] )
226+ if @platforms . has_key? ( args [ :platform ] )
226227 if @platforms [ args [ :platform ] ] . has_key? ( :default )
227228 @platforms [ args [ :platform ] ] [ :default ] [ args [ :resource ] . to_sym ] = args [ :provider ]
228229 else
@@ -246,8 +247,8 @@ def set(args)
246247 end
247248 end
248249 end
249-
250- end
251-
250+
251+ end
252+
252253 end
253254end
0 commit comments