cluster_chef 3.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +51 -0
  2. data/.rspec +3 -0
  3. data/CHANGELOG.md +63 -0
  4. data/Gemfile +18 -0
  5. data/LICENSE +201 -0
  6. data/README.md +332 -0
  7. data/Rakefile +92 -0
  8. data/TODO.md +8 -0
  9. data/VERSION +1 -0
  10. data/chefignore +41 -0
  11. data/cluster_chef.gemspec +115 -0
  12. data/clusters/website_demo.rb +65 -0
  13. data/config/client.rb +59 -0
  14. data/lib/cluster_chef/chef_layer.rb +297 -0
  15. data/lib/cluster_chef/cloud.rb +409 -0
  16. data/lib/cluster_chef/cluster.rb +118 -0
  17. data/lib/cluster_chef/compute.rb +144 -0
  18. data/lib/cluster_chef/cookbook_munger/README.md.erb +47 -0
  19. data/lib/cluster_chef/cookbook_munger/licenses.yaml +16 -0
  20. data/lib/cluster_chef/cookbook_munger/metadata.rb.erb +23 -0
  21. data/lib/cluster_chef/cookbook_munger.rb +588 -0
  22. data/lib/cluster_chef/deprecated.rb +33 -0
  23. data/lib/cluster_chef/discovery.rb +158 -0
  24. data/lib/cluster_chef/dsl_object.rb +123 -0
  25. data/lib/cluster_chef/facet.rb +144 -0
  26. data/lib/cluster_chef/fog_layer.rb +134 -0
  27. data/lib/cluster_chef/private_key.rb +110 -0
  28. data/lib/cluster_chef/role_implications.rb +49 -0
  29. data/lib/cluster_chef/security_group.rb +103 -0
  30. data/lib/cluster_chef/server.rb +265 -0
  31. data/lib/cluster_chef/server_slice.rb +259 -0
  32. data/lib/cluster_chef/volume.rb +93 -0
  33. data/lib/cluster_chef.rb +137 -0
  34. data/notes/aws_console_screenshot.jpg +0 -0
  35. data/rspec.watchr +29 -0
  36. data/spec/cluster_chef/cluster_spec.rb +13 -0
  37. data/spec/cluster_chef/facet_spec.rb +70 -0
  38. data/spec/cluster_chef/server_slice_spec.rb +19 -0
  39. data/spec/cluster_chef/server_spec.rb +112 -0
  40. data/spec/cluster_chef_spec.rb +193 -0
  41. data/spec/spec_helper/dummy_chef.rb +25 -0
  42. data/spec/spec_helper.rb +50 -0
  43. data/spec/test_config.rb +20 -0
  44. data/tasks/chef_config.rb +38 -0
  45. data/tasks/jeweler_use_alt_branch.rb +47 -0
  46. metadata +227 -0
@@ -0,0 +1,144 @@
1
+ module ClusterChef
2
+ #
3
+ # Base class allowing us to layer settings for facet over cluster
4
+ #
5
+ class ComputeBuilder < ClusterChef::DslObject
6
+ attr_reader :cloud, :volumes, :chef_roles
7
+ has_keys :name, :bogosity, :environment
8
+ @@role_implications ||= Mash.new
9
+ @@run_list_rank ||= 0
10
+
11
+ def initialize(builder_name, attrs={})
12
+ super(attrs)
13
+ set :name, builder_name
14
+ @run_list_info = attrs[:run_list] || Mash.new
15
+ @volumes = Mash.new
16
+ end
17
+
18
+ # set the bogosity to a descriptive reason. Anything truthy implies bogusness
19
+ def bogus?
20
+ !! self.bogosity
21
+ end
22
+
23
+ # Magic method to produce cloud instance:
24
+ # * returns the cloud instance, creating it if necessary.
25
+ # * executes the block in the cloud's object context
26
+ #
27
+ # @example
28
+ # cloud do
29
+ # image_name 'maverick'
30
+ # security_group :nagios
31
+ # end
32
+ #
33
+ # # defines ec2-specific behavior
34
+ # cloud(:ec2) do
35
+ # public_ip '1.2.3.4'
36
+ # region 'us-east-1d'
37
+ # end
38
+ #
39
+ def cloud(cloud_provider=nil, attrs={}, &block)
40
+ raise "Only have ec2 so far" if cloud_provider && (cloud_provider != :ec2)
41
+ @cloud ||= ClusterChef::Cloud::Ec2.new(self)
42
+ @cloud.configure(attrs, &block)
43
+ @cloud
44
+ end
45
+
46
+ # sugar for cloud(:ec2)
47
+ def ec2(attrs={}, &block)
48
+ cloud(:ec2, attrs, &block)
49
+ end
50
+
51
+ # Magic method to describe a volume
52
+ # * returns the named volume, creating it if necessary.
53
+ # * executes the block (if any) in the volume's context
54
+ #
55
+ # @example
56
+ # # a 1 GB volume at '/data' from the given snapshot
57
+ # volume(:data) do
58
+ # size 1
59
+ # mount_point '/data'
60
+ # snapshot_id 'snap-12345'
61
+ # end
62
+ #
63
+ # @param volume_name [String] an arbitrary handle -- you can use the device
64
+ # name, or a descriptive symbol.
65
+ # @param attrs [Hash] a hash of attributes to pass down.
66
+ #
67
+ def volume(volume_name, attrs={}, &block)
68
+ volumes[volume_name] ||= ClusterChef::Volume.new(:parent => self, :name => volume_name)
69
+ volumes[volume_name].configure(attrs, &block)
70
+ volumes[volume_name]
71
+ end
72
+
73
+ def root_volume(attrs={}, &block)
74
+ volume(:root, attrs, &block)
75
+ end
76
+
77
+ #
78
+ # Adds the given role to the run list, and invokes any role_implications it
79
+ # implies (for instance, defining and applying the 'ssh' security group if
80
+ # the 'ssh' role is applied.)
81
+ #
82
+ # You can specify placement of `:first`, `:normal` (or nil) or `:last`; the
83
+ # final runlist is assembled as
84
+ #
85
+ # * run_list :first items -- cluster, then facet, then server
86
+ # * run_list :normal items -- cluster, then facet, then server
87
+ # * run_list :last items -- cluster, then facet, then server
88
+ #
89
+ # (see ClusterChef::Server#combined_run_list for full details though)
90
+ #
91
+ def role(role_name, placement=nil)
92
+ add_to_run_list("role[#{role_name}]", placement)
93
+ self.instance_eval(&@@role_implications[role_name]) if @@role_implications[role_name]
94
+ end
95
+
96
+ # Add the given recipe to the run list. You can specify placement of
97
+ # `:first`, `:normal` (or nil) or `:last`; the final runlist is assembled as
98
+ #
99
+ # * run_list :first items -- cluster, then facet, then server
100
+ # * run_list :normal items -- cluster, then facet, then server
101
+ # * run_list :last items -- cluster, then facet, then server
102
+ #
103
+ # (see ClusterChef::Server#combined_run_list for full details though)
104
+ #
105
+ def recipe(name, placement=nil)
106
+ add_to_run_list(name, placement)
107
+ end
108
+
109
+ # Roles and recipes for this element only.
110
+ #
111
+ # See ClusterChef::Server#combined_run_list for run_list order resolution
112
+ def run_list
113
+ groups = run_list_groups
114
+ [ groups[:first], groups[:normal], groups[:last] ].flatten.compact.uniq
115
+ end
116
+
117
+ # run list elements grouped into :first, :normal and :last
118
+ def run_list_groups
119
+ @run_list_info.keys.sort_by{|item| @run_list_info[:rank] }.group_by{|item| @run_list_info[item][:placement] }
120
+ end
121
+
122
+ #
123
+ # Some roles imply aspects of the machine that have to exist at creation.
124
+ # For instance, on an ec2 machine you may wish the 'ssh' role to imply a
125
+ # security group explicity opening port 22.
126
+ #
127
+ # @param [String] role_name -- the role that triggers the block
128
+ # @yield block will be instance_eval'd in the object that calls 'role'
129
+ #
130
+ def self.role_implication(name, &block)
131
+ @@role_implications[name] = block
132
+ end
133
+
134
+ protected
135
+
136
+ def add_to_run_list(item, placement)
137
+ raise "run_list placement must be one of :first, :normal, :last or nil (also means :normal)" unless [:first, :last, nil].include?(placement)
138
+ @@run_list_rank += 1
139
+ placement ||= :normal
140
+ @run_list_info[item] ||= { :rank => @@run_list_rank, :placement => placement }
141
+ end
142
+
143
+ end
144
+ end
@@ -0,0 +1,47 @@
1
+ # <%= name %> chef cookbook
2
+
3
+ <%= description %>
4
+
5
+ ## Overview
6
+
7
+ <%= long_description.present? ? long_description : description %>
8
+
9
+ ## Attributes
10
+
11
+ <%- all_attributes.attrs.each do |attrib| %>
12
+ * <%= "%-35s" % ('`'+attrib.bracketed_name+'`') %> - <%= attrib.display_name %><%- if attrib.default.is_a?(String) || attrib.default.is_a?(Symbol) %> (default: <%= attrib.default.inspect %>)<%- end %>
13
+ <%- if attrib.description.present? && (attrib.description != attrib.display_name) %>
14
+ - <%= attrib.description.gsub(/\n/, "\n ") %>
15
+ <%- end %>
16
+ <%- end %>
17
+ <%- if components[:recipes].present? %>
18
+
19
+ ## Recipes
20
+
21
+ <%- components[:recipes].each do |recipe| %>
22
+ * <%= "%-26s" % ('`'+recipe.name+'`') %> - <%= recipe.desc %>
23
+ <%- end %>
24
+ <%- end %>
25
+ <%- if all_resources.present? %>
26
+
27
+ ## Resources / Providers
28
+
29
+ <%- end %>
30
+ ## Integration
31
+
32
+ Supports platforms: <%= all_supports.to_sentence %>
33
+
34
+ <%- if all_depends.present? %>
35
+ Cookbook dependencies:
36
+ <%- all_depends.each do |nm, dep| -%>
37
+ * <%= dep.gsub(/"/, '') %>
38
+ <%- end -%><%- end -%>
39
+
40
+ ## License and Author
41
+
42
+ Author:: <%= maintainer %> (<<%= maintainer_email %>>)
43
+ Copyright:: <%= copyright_text %>
44
+
45
+ <%= short_license_text %>
46
+
47
+ > readme generated by [cluster_chef](http://github.com/infochimps/cluster_chef)'s cookbook_munger
@@ -0,0 +1,16 @@
1
+
2
+
3
+ :apachev2:
4
+ :name: "Apache 2.0"
5
+ :short: |-
6
+ Licensed under the Apache License, Version 2.0 (the "License");
7
+ you may not use this file except in compliance with the License.
8
+ You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS,
14
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ See the License for the specific language governing permissions and
16
+ limitations under the License.
@@ -0,0 +1,23 @@
1
+ maintainer <%= maintainer.inspect %>
2
+ maintainer_email <%= maintainer_email.inspect %>
3
+ license <%= license.inspect %>
4
+ long_description <%= long_desc_gen %>
5
+ version <%= version.inspect %>
6
+
7
+ description <%= description.inspect %>
8
+
9
+ <%- all_depends.each do |nm, dep| -%>
10
+ depends <%= dep %>
11
+ <%- end -%>
12
+
13
+ <%- all_recipes.each do |recipe_name, recipe| -%>
14
+ recipe <%= "%-37s" % "\"#{name}::#{recipe_name}\"," %> <%= recipe.desc.inspect %>
15
+ <%- end -%>
16
+
17
+ %w[ <%= all_supports.join(" ") %> ].each do |os|
18
+ supports os
19
+ end
20
+ <%- all_attributes.attrs.each do |attrib| %>
21
+
22
+ <%= attrib.pretty_str %>
23
+ <%- end %>