ironfan 3.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.gitignore +51 -0
  2. data/.rspec +3 -0
  3. data/CHANGELOG.md +130 -0
  4. data/Gemfile +26 -0
  5. data/LICENSE.md +201 -0
  6. data/README.md +328 -0
  7. data/Rakefile +104 -0
  8. data/TODO.md +16 -0
  9. data/VERSION +1 -0
  10. data/chefignore +41 -0
  11. data/cluster_chef-knife.gemspec +123 -0
  12. data/cluster_chef.gemspec +111 -0
  13. data/config/client.rb +59 -0
  14. data/config/proxy.pac +12 -0
  15. data/config/ubuntu10.04-ironfan.erb +157 -0
  16. data/config/ubuntu11.10-ironfan.erb +145 -0
  17. data/ironfan.gemspec +121 -0
  18. data/lib/chef/knife/bootstrap/ubuntu10.04-ironfan.erb +157 -0
  19. data/lib/chef/knife/bootstrap/ubuntu11.10-ironfan.erb +145 -0
  20. data/lib/chef/knife/cluster_bootstrap.rb +74 -0
  21. data/lib/chef/knife/cluster_kick.rb +94 -0
  22. data/lib/chef/knife/cluster_kill.rb +73 -0
  23. data/lib/chef/knife/cluster_launch.rb +164 -0
  24. data/lib/chef/knife/cluster_list.rb +50 -0
  25. data/lib/chef/knife/cluster_proxy.rb +126 -0
  26. data/lib/chef/knife/cluster_show.rb +61 -0
  27. data/lib/chef/knife/cluster_ssh.rb +141 -0
  28. data/lib/chef/knife/cluster_start.rb +40 -0
  29. data/lib/chef/knife/cluster_stop.rb +43 -0
  30. data/lib/chef/knife/cluster_sync.rb +77 -0
  31. data/lib/chef/knife/generic_command.rb +66 -0
  32. data/lib/chef/knife/knife_common.rb +195 -0
  33. data/lib/ironfan.rb +143 -0
  34. data/lib/ironfan/chef_layer.rb +299 -0
  35. data/lib/ironfan/cloud.rb +412 -0
  36. data/lib/ironfan/cluster.rb +118 -0
  37. data/lib/ironfan/compute.rb +153 -0
  38. data/lib/ironfan/deprecated.rb +33 -0
  39. data/lib/ironfan/discovery.rb +177 -0
  40. data/lib/ironfan/dsl_object.rb +124 -0
  41. data/lib/ironfan/facet.rb +144 -0
  42. data/lib/ironfan/fog_layer.rb +150 -0
  43. data/lib/ironfan/private_key.rb +130 -0
  44. data/lib/ironfan/role_implications.rb +58 -0
  45. data/lib/ironfan/security_group.rb +119 -0
  46. data/lib/ironfan/server.rb +281 -0
  47. data/lib/ironfan/server_slice.rb +260 -0
  48. data/lib/ironfan/volume.rb +157 -0
  49. data/spec/ironfan/cluster_spec.rb +13 -0
  50. data/spec/ironfan/facet_spec.rb +69 -0
  51. data/spec/ironfan/server_slice_spec.rb +19 -0
  52. data/spec/ironfan/server_spec.rb +112 -0
  53. data/spec/ironfan_spec.rb +193 -0
  54. data/spec/spec_helper.rb +50 -0
  55. data/spec/spec_helper/dummy_chef.rb +25 -0
  56. data/spec/test_config.rb +20 -0
  57. data/tasks/chef_config.rake +38 -0
  58. data/tasks/jeweler_use_alt_branch.rake +53 -0
  59. metadata +217 -0
data/Rakefile ADDED
@@ -0,0 +1,104 @@
1
+ #
2
+ # Rakefile for Cluster Chef Knife plugins
3
+ #
4
+ # Author:: Adam Jacob (<adam@opscode.com>)
5
+ # Copyright:: Copyright (c) 2008 Opscode, Inc.
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ DEPRECATED_NAME = "!! This gem has been renamed 'ironfan' (from cluster_chef). \n It will not be updated after Feb. 2012. \n Sorry for the inconvenience."
22
+
23
+ require 'rubygems' unless defined?(Gem)
24
+ require 'bundler'
25
+ begin
26
+ Bundler.setup(:default, :development)
27
+ rescue Bundler::BundlerError => e
28
+ $stderr.puts e.message
29
+ $stderr.puts "Run `bundle install` to install missing gems"
30
+ exit e.status_code
31
+ end
32
+ require 'json'
33
+ require 'jeweler'
34
+ require 'rspec/core/rake_task'
35
+ require 'yard'
36
+
37
+ # Load constants from rake config file.
38
+ $LOAD_PATH.unshift('tasks')
39
+ Dir[File.join('tasks', '*.rake')].sort.each{|f| load(f) }
40
+
41
+ # ---------------------------------------------------------------------------
42
+ #
43
+ # Jeweler -- release ironfan as a gem
44
+ #
45
+
46
+ gems_to_release = ENV['GEMS_TO_RELEASE'] ? ENV['GEMS_TO_RELEASE'].split : %w[ ironfan ]
47
+ gems_to_release.each do |gem_name|
48
+ Jeweler::Tasks.new do |gem|
49
+ gem.name = gem_name
50
+ gem.homepage = "http://infochimps.com/labs"
51
+ gem.license = NEW_COOKBOOK_LICENSE.to_s
52
+ gem.summary = %Q{#{gem_name} allows you to orchestrate not just systems but clusters of machines. It includes a powerful layer on top of knife and a collection of cloud cookbooks.}
53
+ gem.description = %Q{#{gem_name} allows you to orchestrate not just systems but clusters of machines. It includes a powerful layer on top of knife and a collection of cloud cookbooks.}
54
+ gem.email = SSL_EMAIL_ADDRESS
55
+ gem.authors = ["Infochimps"]
56
+
57
+ ignores = File.readlines(".gitignore").grep(/^[^#]\S+/).map{|s| s.chomp }
58
+ dotfiles = [".gemtest", ".gitignore", ".rspec", ".yardopts"]
59
+ gem.files = dotfiles + Dir["**/*"].
60
+ reject{|f| f =~ %r{^cookbooks/} }.
61
+ reject{|f| File.directory?(f) }.
62
+ reject{|f| ignores.any?{|i| File.fnmatch(i, f) || File.fnmatch(i+'/*', f) || File.fnmatch(i+'/**/*', f) } }
63
+ gem.test_files = gem.files.grep(/^spec\//)
64
+ gem.require_paths = ['lib']
65
+
66
+ if gem.name == 'cluster_chef'
67
+ gem.files.reject!{|f| f =~ %r{^(cluster_chef-knife.gemspec|lib/chef/knife/)} }
68
+ gem.add_runtime_dependency 'cluster_chef-knife', "= #{File.read('VERSION').strip}"
69
+ gem.post_install_message = DEPRECATED_NAME
70
+ elsif gem.name == 'cluster_chef-knife'
71
+ gem.files.reject!{|f| f =~ %r{^(cluster_chef.gemspec|lib/cluster_chef)} }
72
+ gem.post_install_message = DEPRECATED_NAME
73
+ elsif gem.name == 'ironfan'
74
+ true # pass
75
+ else
76
+ raise "Don't know what to include for gem #{gem.name}"
77
+ end
78
+ end
79
+ Jeweler::RubygemsDotOrgTasks.new
80
+ end
81
+
82
+ # ---------------------------------------------------------------------------
83
+ #
84
+ # RSpec -- testing
85
+ #
86
+ RSpec::Core::RakeTask.new(:spec) do |spec|
87
+ spec.pattern = FileList['spec/**/*_spec.rb']
88
+ end
89
+
90
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
91
+ spec.pattern = 'spec/**/*_spec.rb'
92
+ spec.rcov = true
93
+ spec.rcov_opts = %w[ --exclude .rvm --no-comments --text-summary ]
94
+ end
95
+
96
+ # ---------------------------------------------------------------------------
97
+ #
98
+ # Yard -- documentation
99
+ #
100
+ YARD::Rake::YardocTask.new
101
+
102
+ # ---------------------------------------------------------------------------
103
+
104
+ task :default => :spec
data/TODO.md ADDED
@@ -0,0 +1,16 @@
1
+ ### From Nathan
2
+ - syntactic sugar for ```server(0).fullname('blah')```
3
+
4
+ ### Knife commands
5
+
6
+ * knife cluster kick fails if service isn't running
7
+ * make clear directions for installing `ironfan` and its initial use.
8
+ * knife cluster launch should fail differently if you give it a facet that doesn't exist
9
+
10
+
11
+
12
+ ### ssh_user, ssh_identity_file, keypair, template should be set by cluster except when they shouldn't
13
+
14
+ ### Organization-specific homebase files
15
+
16
+ The current organization of the homebase needs to better scope organization-specific customizations
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 3.1.0.rc1
data/chefignore ADDED
@@ -0,0 +1,41 @@
1
+ # Put files/directories that should be ignored in this file.
2
+ # Lines that start with '# ' are comments.
3
+
4
+ ## OS
5
+ .DS_Store
6
+ Icon?
7
+ nohup.out
8
+
9
+ ## EDITORS
10
+ \#*
11
+ .#*
12
+ *~
13
+ *.sw[a-z]
14
+ *.bak
15
+ REVISION
16
+ TAGS*
17
+ tmtags
18
+ *_flymake.*
19
+ *_flymake
20
+ *.tmproj
21
+ .project
22
+ .settings
23
+ mkmf.log
24
+
25
+ ## COMPILED
26
+ a.out
27
+ *.o
28
+ *.pyc
29
+ *.so
30
+
31
+ ## OTHER SCM
32
+ */.bzr/*
33
+ */.hg/*
34
+ */.svn/*
35
+
36
+ ## Don't send rspecs up in cookbook
37
+ .watchr
38
+ .rspec
39
+ spec/*
40
+ spec/fixtures/*
41
+
@@ -0,0 +1,123 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "cluster_chef-knife"
8
+ s.version = "3.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Infochimps"]
12
+ s.date = "2012-02-18"
13
+ s.description = "cluster_chef-knife allows you to orchestrate not just systems but clusters of machines. It includes a powerful layer on top of knife and a collection of cloud cookbooks."
14
+ s.email = "coders@infochimps.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.md",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ ".rspec",
22
+ "CHANGELOG.md",
23
+ "Gemfile",
24
+ "LICENSE.md",
25
+ "README.md",
26
+ "Rakefile",
27
+ "TODO.md",
28
+ "VERSION",
29
+ "chefignore",
30
+ "cluster_chef-knife.gemspec",
31
+ "config/client.rb",
32
+ "config/proxy.pac",
33
+ "config/ubuntu10.04-ironfan.erb",
34
+ "config/ubuntu11.10-ironfan.erb",
35
+ "ironfan.gemspec",
36
+ "lib/chef/knife/bootstrap/ubuntu10.04-ironfan.erb",
37
+ "lib/chef/knife/bootstrap/ubuntu11.10-ironfan.erb",
38
+ "lib/chef/knife/cluster_bootstrap.rb",
39
+ "lib/chef/knife/cluster_kick.rb",
40
+ "lib/chef/knife/cluster_kill.rb",
41
+ "lib/chef/knife/cluster_launch.rb",
42
+ "lib/chef/knife/cluster_list.rb",
43
+ "lib/chef/knife/cluster_proxy.rb",
44
+ "lib/chef/knife/cluster_show.rb",
45
+ "lib/chef/knife/cluster_ssh.rb",
46
+ "lib/chef/knife/cluster_start.rb",
47
+ "lib/chef/knife/cluster_stop.rb",
48
+ "lib/chef/knife/cluster_sync.rb",
49
+ "lib/chef/knife/generic_command.rb",
50
+ "lib/chef/knife/knife_common.rb",
51
+ "lib/ironfan.rb",
52
+ "lib/ironfan/chef_layer.rb",
53
+ "lib/ironfan/cloud.rb",
54
+ "lib/ironfan/cluster.rb",
55
+ "lib/ironfan/compute.rb",
56
+ "lib/ironfan/deprecated.rb",
57
+ "lib/ironfan/discovery.rb",
58
+ "lib/ironfan/dsl_object.rb",
59
+ "lib/ironfan/facet.rb",
60
+ "lib/ironfan/fog_layer.rb",
61
+ "lib/ironfan/private_key.rb",
62
+ "lib/ironfan/role_implications.rb",
63
+ "lib/ironfan/security_group.rb",
64
+ "lib/ironfan/server.rb",
65
+ "lib/ironfan/server_slice.rb",
66
+ "lib/ironfan/volume.rb",
67
+ "rspec.watchr",
68
+ "spec/ironfan/cluster_spec.rb",
69
+ "spec/ironfan/facet_spec.rb",
70
+ "spec/ironfan/server_slice_spec.rb",
71
+ "spec/ironfan/server_spec.rb",
72
+ "spec/ironfan_spec.rb",
73
+ "spec/spec_helper.rb",
74
+ "spec/spec_helper/dummy_chef.rb",
75
+ "spec/test_config.rb",
76
+ "tasks/chef_config.rake",
77
+ "tasks/jeweler_use_alt_branch.rake"
78
+ ]
79
+ s.homepage = "http://infochimps.com/labs"
80
+ s.licenses = ["apachev2"]
81
+ s.post_install_message = "!! This gem has been renamed 'ironfan' (from cluster_chef). \n It will not be updated after Feb. 2012. \n Sorry for the inconvenience."
82
+ s.require_paths = ["lib"]
83
+ s.rubygems_version = "1.8.15"
84
+ s.summary = "cluster_chef-knife allows you to orchestrate not just systems but clusters of machines. It includes a powerful layer on top of knife and a collection of cloud cookbooks."
85
+ s.test_files = ["spec/ironfan/cluster_spec.rb", "spec/ironfan/facet_spec.rb", "spec/ironfan/server_slice_spec.rb", "spec/ironfan/server_spec.rb", "spec/ironfan_spec.rb", "spec/spec_helper/dummy_chef.rb", "spec/spec_helper.rb", "spec/test_config.rb"]
86
+
87
+ if s.respond_to? :specification_version then
88
+ s.specification_version = 3
89
+
90
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
91
+ s.add_runtime_dependency(%q<chef>, ["~> 0.10.4"])
92
+ s.add_runtime_dependency(%q<fog>, ["~> 1.1.1"])
93
+ s.add_runtime_dependency(%q<formatador>, ["~> 0.2.1"])
94
+ s.add_runtime_dependency(%q<gorillib>, ["~> 0.1.7"])
95
+ s.add_development_dependency(%q<bundler>, ["~> 1"])
96
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6"])
97
+ s.add_development_dependency(%q<rspec>, ["~> 2.5"])
98
+ s.add_development_dependency(%q<yard>, ["~> 0.6"])
99
+ s.add_development_dependency(%q<configliere>, ["~> 0.4.8"])
100
+ else
101
+ s.add_dependency(%q<chef>, ["~> 0.10.4"])
102
+ s.add_dependency(%q<fog>, ["~> 1.1.1"])
103
+ s.add_dependency(%q<formatador>, ["~> 0.2.1"])
104
+ s.add_dependency(%q<gorillib>, ["~> 0.1.7"])
105
+ s.add_dependency(%q<bundler>, ["~> 1"])
106
+ s.add_dependency(%q<jeweler>, ["~> 1.6"])
107
+ s.add_dependency(%q<rspec>, ["~> 2.5"])
108
+ s.add_dependency(%q<yard>, ["~> 0.6"])
109
+ s.add_dependency(%q<configliere>, ["~> 0.4.8"])
110
+ end
111
+ else
112
+ s.add_dependency(%q<chef>, ["~> 0.10.4"])
113
+ s.add_dependency(%q<fog>, ["~> 1.1.1"])
114
+ s.add_dependency(%q<formatador>, ["~> 0.2.1"])
115
+ s.add_dependency(%q<gorillib>, ["~> 0.1.7"])
116
+ s.add_dependency(%q<bundler>, ["~> 1"])
117
+ s.add_dependency(%q<jeweler>, ["~> 1.6"])
118
+ s.add_dependency(%q<rspec>, ["~> 2.5"])
119
+ s.add_dependency(%q<yard>, ["~> 0.6"])
120
+ s.add_dependency(%q<configliere>, ["~> 0.4.8"])
121
+ end
122
+ end
123
+
@@ -0,0 +1,111 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "cluster_chef"
8
+ s.version = "3.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Infochimps"]
12
+ s.date = "2012-02-18"
13
+ s.description = "cluster_chef allows you to orchestrate not just systems but clusters of machines. It includes a powerful layer on top of knife and a collection of cloud cookbooks."
14
+ s.email = "coders@infochimps.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.md",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ ".rspec",
22
+ "CHANGELOG.md",
23
+ "Gemfile",
24
+ "LICENSE.md",
25
+ "README.md",
26
+ "Rakefile",
27
+ "TODO.md",
28
+ "VERSION",
29
+ "chefignore",
30
+ "cluster_chef.gemspec",
31
+ "config/client.rb",
32
+ "config/proxy.pac",
33
+ "config/ubuntu10.04-ironfan.erb",
34
+ "config/ubuntu11.10-ironfan.erb",
35
+ "ironfan.gemspec",
36
+ "lib/ironfan.rb",
37
+ "lib/ironfan/chef_layer.rb",
38
+ "lib/ironfan/cloud.rb",
39
+ "lib/ironfan/cluster.rb",
40
+ "lib/ironfan/compute.rb",
41
+ "lib/ironfan/deprecated.rb",
42
+ "lib/ironfan/discovery.rb",
43
+ "lib/ironfan/dsl_object.rb",
44
+ "lib/ironfan/facet.rb",
45
+ "lib/ironfan/fog_layer.rb",
46
+ "lib/ironfan/private_key.rb",
47
+ "lib/ironfan/role_implications.rb",
48
+ "lib/ironfan/security_group.rb",
49
+ "lib/ironfan/server.rb",
50
+ "lib/ironfan/server_slice.rb",
51
+ "lib/ironfan/volume.rb",
52
+ "rspec.watchr",
53
+ "spec/ironfan/cluster_spec.rb",
54
+ "spec/ironfan/facet_spec.rb",
55
+ "spec/ironfan/server_slice_spec.rb",
56
+ "spec/ironfan/server_spec.rb",
57
+ "spec/ironfan_spec.rb",
58
+ "spec/spec_helper.rb",
59
+ "spec/spec_helper/dummy_chef.rb",
60
+ "spec/test_config.rb",
61
+ "tasks/chef_config.rake",
62
+ "tasks/jeweler_use_alt_branch.rake"
63
+ ]
64
+ s.homepage = "http://infochimps.com/labs"
65
+ s.licenses = ["apachev2"]
66
+ s.post_install_message = "!! This gem has been renamed 'ironfan' (from cluster_chef). \n It will not be updated after Feb. 2012. \n Sorry for the inconvenience."
67
+ s.require_paths = ["lib"]
68
+ s.rubygems_version = "1.8.15"
69
+ s.summary = "cluster_chef allows you to orchestrate not just systems but clusters of machines. It includes a powerful layer on top of knife and a collection of cloud cookbooks."
70
+ s.test_files = ["spec/ironfan/cluster_spec.rb", "spec/ironfan/facet_spec.rb", "spec/ironfan/server_slice_spec.rb", "spec/ironfan/server_spec.rb", "spec/ironfan_spec.rb", "spec/spec_helper/dummy_chef.rb", "spec/spec_helper.rb", "spec/test_config.rb"]
71
+
72
+ if s.respond_to? :specification_version then
73
+ s.specification_version = 3
74
+
75
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
76
+ s.add_runtime_dependency(%q<chef>, ["~> 0.10.4"])
77
+ s.add_runtime_dependency(%q<fog>, ["~> 1.1.1"])
78
+ s.add_runtime_dependency(%q<formatador>, ["~> 0.2.1"])
79
+ s.add_runtime_dependency(%q<gorillib>, ["~> 0.1.7"])
80
+ s.add_development_dependency(%q<bundler>, ["~> 1"])
81
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6"])
82
+ s.add_development_dependency(%q<rspec>, ["~> 2.5"])
83
+ s.add_development_dependency(%q<yard>, ["~> 0.6"])
84
+ s.add_development_dependency(%q<configliere>, ["~> 0.4.8"])
85
+ s.add_runtime_dependency(%q<cluster_chef-knife>, ["= 3.1.0"])
86
+ else
87
+ s.add_dependency(%q<chef>, ["~> 0.10.4"])
88
+ s.add_dependency(%q<fog>, ["~> 1.1.1"])
89
+ s.add_dependency(%q<formatador>, ["~> 0.2.1"])
90
+ s.add_dependency(%q<gorillib>, ["~> 0.1.7"])
91
+ s.add_dependency(%q<bundler>, ["~> 1"])
92
+ s.add_dependency(%q<jeweler>, ["~> 1.6"])
93
+ s.add_dependency(%q<rspec>, ["~> 2.5"])
94
+ s.add_dependency(%q<yard>, ["~> 0.6"])
95
+ s.add_dependency(%q<configliere>, ["~> 0.4.8"])
96
+ s.add_dependency(%q<cluster_chef-knife>, ["= 3.1.0"])
97
+ end
98
+ else
99
+ s.add_dependency(%q<chef>, ["~> 0.10.4"])
100
+ s.add_dependency(%q<fog>, ["~> 1.1.1"])
101
+ s.add_dependency(%q<formatador>, ["~> 0.2.1"])
102
+ s.add_dependency(%q<gorillib>, ["~> 0.1.7"])
103
+ s.add_dependency(%q<bundler>, ["~> 1"])
104
+ s.add_dependency(%q<jeweler>, ["~> 1.6"])
105
+ s.add_dependency(%q<rspec>, ["~> 2.5"])
106
+ s.add_dependency(%q<yard>, ["~> 0.6"])
107
+ s.add_dependency(%q<configliere>, ["~> 0.4.8"])
108
+ s.add_dependency(%q<cluster_chef-knife>, ["= 3.1.0"])
109
+ end
110
+ end
111
+
data/config/client.rb ADDED
@@ -0,0 +1,59 @@
1
+ require "ohai"
2
+ require "json"
3
+
4
+ #
5
+ # Load configuration
6
+ #
7
+
8
+ def merge_safely hsh
9
+ hsh.merge!( yield ) rescue Mash.new
10
+ end
11
+
12
+ def create_file_if_empty(filename, str)
13
+ unless File.exists?(filename)
14
+ puts "Populating #{filename}" ;
15
+ File.open(filename, "w", 0600){|f| f.puts(str) }
16
+ end
17
+ end
18
+
19
+ def present?(config, key)
20
+ not config[key].to_s.empty?
21
+ end
22
+
23
+ # Start with a set of defaults
24
+ chef_config = Mash.new
25
+
26
+ # Extract client configuration from EC2 user-data
27
+ OHAI_INFO = Ohai::System.new
28
+ OHAI_INFO.all_plugins
29
+ merge_safely(chef_config){ JSON.parse(OHAI_INFO[:ec2][:userdata]) }
30
+
31
+ #
32
+ # Configure chef run
33
+ #
34
+
35
+ log_level :info
36
+ log_location STDOUT
37
+ node_name chef_config["node_name"] if chef_config["node_name"]
38
+ chef_server_url chef_config["chef_server"] if chef_config["chef_server"]
39
+ validation_client_name chef_config["validation_client_name"] if chef_config["validation_client_name"]
40
+ validation_key "/etc/chef/validation.pem"
41
+ client_key "/etc/chef/client.pem"
42
+ node_attrs_file "/etc/chef/first-boot.json"
43
+
44
+ # If the client file is missing, write the validation key out so chef-client can register
45
+ unless File.exists?(client_key)
46
+ if present?(chef_config, "client_key") then create_file_if_empty(client_key, chef_config["client_key"])
47
+ elsif present?(chef_config, "validation_key") then create_file_if_empty(validation_key, chef_config["validation_key"])
48
+ else warn "Yikes -- I have no client key or validation key!!"
49
+ end
50
+ end
51
+
52
+ reduced_chef_config = chef_config.reject{|k,v| k.to_s =~ /(_key|run_list)$/ }
53
+ unless File.exists?(node_attrs_file)
54
+ create_file_if_empty(node_attrs_file, JSON.pretty_generate(reduced_chef_config))
55
+ end
56
+ json_attribs node_attrs_file
57
+
58
+ Chef::Log.debug(JSON.generate(chef_config))
59
+ Chef::Log.info("=> chef client #{node_name} on #{chef_server_url} in cluster +#{chef_config["cluster_name"]}+")