Class: Chef::Platform

Inherits:
Object
  • Object
show all
Extended by:
Mixin::ParamsValidate
Defined in:
lib/chef/platform.rb

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Mixin::ParamsValidate

set_or_return, validate

Class Attribute Details

.platformsObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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
# File 'lib/chef/platform.rb', line 41

def platforms
  @platforms ||= {
    :mac_os_x => {
      :default => {
        :package => Chef::Provider::Package::Macports,
        :user => Chef::Provider::User::Dscl,
        :group => Chef::Provider::Group::Dscl
      }
    },
    :freebsd => {
      :default => {
        :group   => Chef::Provider::Group::Pw,
        :package => Chef::Provider::Package::Freebsd,
        :service => Chef::Provider::Service::Freebsd,
        :user    => Chef::Provider::User::Pw,
        :cron    => Chef::Provider::Cron
      }
    },
    :ubuntu   => {
      :default => {
        :package => Chef::Provider::Package::Apt,
        :service => Chef::Provider::Service::Debian,
        :cron => Chef::Provider::Cron,
        :mdadm => Chef::Provider::Mdadm
      }
    },
    :debian => {
      :default => {
        :package => Chef::Provider::Package::Apt,
        :service => Chef::Provider::Service::Debian,
        :cron => Chef::Provider::Cron,
        :mdadm => Chef::Provider::Mdadm
      },
      "6.0" => {
        :service => Chef::Provider::Service::Insserv
      }
    },
    :xenserver   => {
      :default => {
        :service => Chef::Provider::Service::Redhat,
        :cron => Chef::Provider::Cron,
        :package => Chef::Provider::Package::Yum,
        :mdadm => Chef::Provider::Mdadm
      }
    },
    :centos   => {
      :default => {
        :service => Chef::Provider::Service::Redhat,
        :cron => Chef::Provider::Cron,
        :package => Chef::Provider::Package::Yum,
        :mdadm => Chef::Provider::Mdadm
      }
    },
    :amazon   => {
      :default => {
        :service => Chef::Provider::Service::Redhat,
        :cron => Chef::Provider::Cron,
        :package => Chef::Provider::Package::Yum,
        :mdadm => Chef::Provider::Mdadm
      }
    },
    :scientific => {
      :default => {
        :service => Chef::Provider::Service::Redhat,
        :cron => Chef::Provider::Cron,
        :package => Chef::Provider::Package::Yum,
        :mdadm => Chef::Provider::Mdadm
      }
    },
    :fedora   => {
      :default => {
        :service => Chef::Provider::Service::Redhat,
        :cron => Chef::Provider::Cron,
        :package => Chef::Provider::Package::Yum,
        :mdadm => Chef::Provider::Mdadm
      }
    },
    :suse     => {
      :default => {
        :service => Chef::Provider::Service::Redhat,
        :cron => Chef::Provider::Cron,
        :package => Chef::Provider::Package::Zypper
      }
    },
    :redhat   => {
      :default => {
        :service => Chef::Provider::Service::Redhat,
        :cron => Chef::Provider::Cron,
        :package => Chef::Provider::Package::Yum,
        :mdadm => Chef::Provider::Mdadm
      }
    },
    :gentoo   => {
      :default => {
        :package => Chef::Provider::Package::Portage,
        :service => Chef::Provider::Service::Gentoo,
        :cron => Chef::Provider::Cron,
        :mdadm => Chef::Provider::Mdadm
      }
    },
    :arch   => {
      :default => {
        :package => Chef::Provider::Package::Pacman,
        :service => Chef::Provider::Service::Arch,
        :cron => Chef::Provider::Cron,
        :mdadm => Chef::Provider::Mdadm
      }
    },
    :mswin => {
      :default => {
        :env =>  Chef::Provider::Env::Windows,
        :service => Chef::Provider::Service::Windows,
        :user => Chef::Provider::User::Windows,
        :group => Chef::Provider::Group::Windows,
        :mount => Chef::Provider::Mount::Windows
      }
    },
    :mingw32 => {
      :default => {
        :env =>  Chef::Provider::Env::Windows,
        :service => Chef::Provider::Service::Windows,
        :user => Chef::Provider::User::Windows,
        :group => Chef::Provider::Group::Windows,
        :mount => Chef::Provider::Mount::Windows
      }
    },
    :windows => {
      :default => {
        :env =>  Chef::Provider::Env::Windows,
        :service => Chef::Provider::Service::Windows,
        :user => Chef::Provider::User::Windows,
        :group => Chef::Provider::Group::Windows,
        :mount => Chef::Provider::Mount::Windows
      }
    },
    :solaris  => {},
    :solaris2 => {
      :default => {
        :service => Chef::Provider::Service::Solaris,
        :package => Chef::Provider::Package::Solaris,
        :cron => Chef::Provider::Cron::Solaris,
        :group => Chef::Provider::Group::Usermod
      }
    },
    :default  => {
      :file => Chef::Provider::File,
      :directory => Chef::Provider::Directory,
      :link => Chef::Provider::Link,
      :template => Chef::Provider::Template,
      :remote_directory => Chef::Provider::RemoteDirectory,
      :execute => Chef::Provider::Execute,
      :mount => Chef::Provider::Mount::Mount,
      :script => Chef::Provider::Script,
      :service => Chef::Provider::Service::Init,
      :perl => Chef::Provider::Script,
      :python => Chef::Provider::Script,
      :ruby => Chef::Provider::Script,
      :bash => Chef::Provider::Script,
      :csh => Chef::Provider::Script,
      :user => Chef::Provider::User::Useradd,
      :group => Chef::Provider::Group::Gpasswd,
      :http_request => Chef::Provider::HttpRequest,
      :route => Chef::Provider::Route,
      :ifconfig => Chef::Provider::Ifconfig,
      :ruby_block => Chef::Provider::RubyBlock,
      :erl_call => Chef::Provider::ErlCall,
      :log => Chef::Provider::Log::ChefLog
    }
  }
end

Class Method Details

.find(name, version) ⇒ Object



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/chef/platform.rb', line 214

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

Raises:

  • (ArgumentError)


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 240

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

Raises:

  • (ArgumentError)


344
345
346
347
348
349
350
351
352
353
# File 'lib/chef/platform.rb', line 344

def find_provider(platform, version, resource_type)
  pmap = Chef::Platform.find(platform, version)
  provider_klass = explicit_provider(platform, version, resource_type) ||
                   platform_provider(platform, version, resource_type) ||
                   resource_matching_provider(platform, version, resource_type)

  raise ArgumentError, "Cannot find a provider for #{resource_type} on #{platform} version #{version}" if provider_klass.nil?

  provider_klass
end

.find_provider_for_node(node, resource_type) ⇒ Object



276
277
278
279
# File 'lib/chef/platform.rb', line 276

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

Raises:

  • (NotImplementedError)


271
272
273
274
# File 'lib/chef/platform.rb', line 271

def provider_for_node(node, resource_type)
  raise NotImplementedError, "#{self.class.name} no longer supports #provider_for_node"
  find_provider_for_node(node, resource_type).new(node, resource_type)
end

.provider_for_resource(resource) ⇒ Object

Raises:

  • (ArgumentError)


265
266
267
268
269
# File 'lib/chef/platform.rb', line 265

def provider_for_resource(resource)
  node = resource.run_context && resource.run_context.node
  raise ArgumentError, "Cannot find the provider for a resource with no run context set" unless node
  find_provider_for_node(node, resource).new(resource, resource.run_context)
end

.set(args) ⇒ Object



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/chef/platform.rb', line 281

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