Class: Chef::Platform
- Extended by:
- Mixin::ParamsValidate
- Defined in:
- lib/chef/platform.rb
Class Attribute Summary collapse
-
.platforms ⇒ Object
Returns the value of attribute platforms.
Class Method Summary collapse
- .find(name, version) ⇒ Object
- .find_platform_and_version(node) ⇒ Object
- .find_provider(platform, version, resource_type) ⇒ Object
- .find_provider_for_node(node, resource_type) ⇒ Object
- .provider_for_node(node, resource_type) ⇒ Object
- .set(args) ⇒ Object
Methods included from Mixin::ParamsValidate
Class Attribute Details
.platforms ⇒ Object
Returns the value of attribute platforms.
121 122 123 |
# File 'lib/chef/platform.rb', line 121 def platforms @platforms end |
Class Method Details
.find(name, version) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/chef/platform.rb', line 125 def find(name, version) provider_map = @platforms[:default].clone name_sym = name if name.kind_of?(String) name.downcase! name.gsub!(/\s/, "_") name_sym = name.to_sym end if @platforms.has_key?(name_sym) if @platforms[name_sym].has_key?(version) Chef::Log.debug("Platform #{name.to_s} version #{version} found") if @platforms[name_sym].has_key?(:default) provider_map.merge!(@platforms[name_sym][:default]) end provider_map.merge!(@platforms[name_sym][version]) elsif @platforms[name_sym].has_key?(:default) provider_map.merge!(@platforms[name_sym][:default]) end else Chef::Log.debug("Platform #{name} not found, using all defaults. (Unsupported platform?)") end provider_map end |
.find_platform_and_version(node) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/chef/platform.rb', line 168 def find_platform_and_version(node) platform = nil version = nil if node[:platform] platform = node[:platform] elsif node.attribute?("os") platform = node[:os] end raise ArgumentError, "Cannot find a platform for #{node}" unless platform if node[:platform_version] version = node[:platform_version] elsif node[:os_version] version = node[:os_version] elsif node[:os_release] version = node[:os_release] end raise ArgumentError, "Cannot find a version for #{node}" unless version return platform, version end |
.find_provider(platform, version, resource_type) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/chef/platform.rb', line 151 def find_provider(platform, version, resource_type) pmap = Chef::Platform.find(platform, version) rtkey = resource_type if resource_type.kind_of?(Chef::Resource) return resource_type.provider if resource_type.provider rtkey = resource_type.resource_name.to_sym end if pmap.has_key?(rtkey) pmap[rtkey] else raise( ArgumentError, "Cannot find a provider for #{resource_type} on #{platform} version #{version}" ) end end |
.find_provider_for_node(node, resource_type) ⇒ Object
197 198 199 200 |
# File 'lib/chef/platform.rb', line 197 def find_provider_for_node(node, resource_type) platform, version = find_platform_and_version(node) provider = find_provider(platform, version, resource_type) end |
.provider_for_node(node, resource_type) ⇒ Object
193 194 195 |
# File 'lib/chef/platform.rb', line 193 def provider_for_node(node, resource_type) find_provider_for_node(node, resource_type).new(node, resource_type) end |
.set(args) ⇒ Object
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 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/chef/platform.rb', line 202 def set(args) validate( args, { :platform => { :kind_of => Symbol, :required => false, }, :version => { :kind_of => String, :required => false, }, :resource => { :kind_of => Symbol, }, :provider => { :kind_of => [ String, Symbol, Class ], } } ) if args.has_key?(:platform) if args.has_key?(:version) if @platforms.has_key?(args[:platform]) if @platforms[args[:platform]].has_key?(args[:version]) @platforms[args[:platform]][args[:version]][args[:resource].to_sym] = args[:provider] else @platforms[args[:platform]][args[:version]] = { args[:resource].to_sym => args[:provider] } end else @platforms[args[:platform]] = { args[:version] => { args[:resource].to_sym => args[:provider] } } end else if @platforms.has_key?(args[:platform]) if @platforms[args[:platform]].has_key?(:default) @platforms[args[:platform]][:default][args[:resource].to_sym] = args[:provider] else @platforms[args[:platform]] = { :default => { args[:resource].to_sym => args[:provider] } } end else @platforms[args[:platform]] = { :default => { args[:resource].to_sym => args[:provider] } } end end else if @platforms.has_key?(:default) @platforms[:default][args[:resource].to_sym] = args[:provider] else @platforms[:default] = { args[:resource].to_sym => args[:provider] } end end end |