hubcap 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -7
- data/lib/hubcap/group.rb +47 -19
- data/lib/hubcap/server.rb +1 -4
- data/lib/hubcap/version.rb +1 -1
- data/test/data/readme.rb +5 -3
- data/test/unit/test_group.rb +31 -8
- data/test/unit/test_server.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -51,19 +51,20 @@ application('readme', :recipes => 'deploy') {
|
|
51
51
|
cap_set('repository', 'git@github.com:joseph/readme.git')
|
52
52
|
|
53
53
|
# Declare that all servers will have the 'baseline' puppet class.
|
54
|
-
|
54
|
+
puppet_role('baseline')
|
55
55
|
|
56
56
|
group('staging') {
|
57
|
-
# Puppet
|
57
|
+
# Puppet will have a $::exception_subject_prefix variable on these servers.
|
58
58
|
param('exception_subject_prefix' => '[STAGING] ')
|
59
59
|
# For simple staging, just one server that does everything.
|
60
|
-
server('readme.stage') {
|
61
|
-
|
60
|
+
server('readme.stage', :address => '0.0.0.0') {
|
61
|
+
cap_role(:web, :app, :db)
|
62
|
+
puppet_role('proxy', 'app', 'db')
|
62
63
|
}
|
63
64
|
}
|
64
65
|
|
65
66
|
group('production') {
|
66
|
-
# Puppet
|
67
|
+
# Puppet will have these top-scope variables on all these servers.
|
67
68
|
param(
|
68
69
|
'exception_subject_prefix' => '[PRODUCTION] ',
|
69
70
|
'env' => {
|
@@ -75,7 +76,8 @@ application('readme', :recipes => 'deploy') {
|
|
75
76
|
|
76
77
|
group('proxy') {
|
77
78
|
# Servers will have the :web role and the 'proxy' puppet class.
|
78
|
-
|
79
|
+
cap_role(:web)
|
80
|
+
puppet_role('proxy')
|
79
81
|
server('proxy-1', :address => '10.10.10.5')
|
80
82
|
}
|
81
83
|
|
@@ -153,7 +155,7 @@ The Hubcap DSL is very simple. This is the basic set of statements:
|
|
153
155
|
* `role` - Add a role to the list of Capistrano roles for servers within
|
154
156
|
this group. By default, these roles are supplied as classes to apply to the
|
155
157
|
host in Puppet. You can specify that a role is Capistrano-only with
|
156
|
-
|
158
|
+
`cap_role()`, or Puppet-only with `puppet_role()`. This is additive:
|
157
159
|
if you have multiple role declarations in your tree, all of them apply.
|
158
160
|
|
159
161
|
* `param` - Add to a hash of 'parameters' that will be supplied to Puppet
|
data/lib/hubcap/group.rb
CHANGED
@@ -18,7 +18,7 @@ class Hubcap::Group
|
|
18
18
|
end
|
19
19
|
@cap_attributes = {}
|
20
20
|
@cap_roles = []
|
21
|
-
@puppet_roles =
|
21
|
+
@puppet_roles = {}
|
22
22
|
@params = {}
|
23
23
|
@hosts = {}
|
24
24
|
@children = []
|
@@ -142,15 +142,44 @@ class Hubcap::Group
|
|
142
142
|
# or:
|
143
143
|
# role(:cap => [:app, :db], :puppet => 'relishapp')
|
144
144
|
#
|
145
|
+
# def role(*args)
|
146
|
+
# if args.length == 1 && args.first.kind_of?(Hash)
|
147
|
+
# h = args.first
|
148
|
+
# @cap_roles += [h[:cap]].flatten if h.has_key?(:cap)
|
149
|
+
# @puppet_roles += [h[:puppet]].flatten if h.has_key?(:puppet)
|
150
|
+
# else
|
151
|
+
# @cap_roles += args
|
152
|
+
# @puppet_roles += args
|
153
|
+
# end
|
154
|
+
# end
|
155
|
+
|
156
|
+
|
145
157
|
def role(*args)
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
158
|
+
cap_role(*args)
|
159
|
+
puppet_role(*args)
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
def cap_role(*args)
|
164
|
+
inv = args.select { |a| !a.kind_of?(String) && !a.kind_of?(Symbol) }
|
165
|
+
raise "Capistrano role must be string or symbol: #{inv}" if inv.any?
|
166
|
+
@cap_roles += args
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
def puppet_role(*args)
|
171
|
+
args.each { |a|
|
172
|
+
if a.kind_of?(String) || a.kind_of?(Symbol)
|
173
|
+
update_with_stringified_keys(@puppet_roles, { a => nil })
|
174
|
+
elsif a.kind_of?(Hash)
|
175
|
+
inv = []
|
176
|
+
a.each_pair { |k, v| inv << v unless v.kind_of?(Hash) }
|
177
|
+
raise "Puppet role parameters must be a hash: #{inv}" if inv.any?
|
178
|
+
update_with_stringified_keys(@puppet_roles, a)
|
179
|
+
else
|
180
|
+
raise "Puppet role must be a string, symbol or hash: #{a}"
|
181
|
+
end
|
182
|
+
}
|
154
183
|
end
|
155
184
|
|
156
185
|
|
@@ -171,15 +200,7 @@ class Hubcap::Group
|
|
171
200
|
raise(Hubcap::InvalidParamKeyType, k.inspect)
|
172
201
|
end
|
173
202
|
}
|
174
|
-
|
175
|
-
recurse = lambda { |dest, src|
|
176
|
-
src.each_pair { |k, v|
|
177
|
-
v = recurse.call({}, v) if v.is_a?(Hash)
|
178
|
-
dest.update(k.to_s => v)
|
179
|
-
}
|
180
|
-
dest
|
181
|
-
}
|
182
|
-
recurse.call(@params, hash)
|
203
|
+
update_with_stringified_keys(@params, hash)
|
183
204
|
end
|
184
205
|
|
185
206
|
|
@@ -215,7 +236,7 @@ class Hubcap::Group
|
|
215
236
|
|
216
237
|
|
217
238
|
def puppet_roles
|
218
|
-
@parent ? @parent.puppet_roles
|
239
|
+
@parent ? @parent.puppet_roles.merge(@puppet_roles) : @puppet_roles
|
219
240
|
end
|
220
241
|
|
221
242
|
|
@@ -300,6 +321,13 @@ class Hubcap::Group
|
|
300
321
|
end
|
301
322
|
|
302
323
|
|
324
|
+
def update_with_stringified_keys(dest, src)
|
325
|
+
src.each_pair { |k, v|
|
326
|
+
v = update_with_stringified_keys({}, v) if v.is_a?(Hash)
|
327
|
+
dest.update(k.to_s => v)
|
328
|
+
}
|
329
|
+
dest
|
330
|
+
end
|
303
331
|
|
304
332
|
|
305
333
|
class Hubcap::GroupWithoutParent < StandardError; end
|
data/lib/hubcap/server.rb
CHANGED
data/lib/hubcap/version.rb
CHANGED
data/test/data/readme.rb
CHANGED
@@ -4,14 +4,15 @@ application('readme', :recipes => 'deploy') {
|
|
4
4
|
cap_set('repository', 'git@github.com:joseph/readme.git')
|
5
5
|
|
6
6
|
# Declare that all servers will have the 'baseline' puppet class.
|
7
|
-
|
7
|
+
puppet_role('baseline')
|
8
8
|
|
9
9
|
group('staging') {
|
10
10
|
# Puppet will have a $::exception_subject_prefix variable on these servers.
|
11
11
|
param('exception_subject_prefix' => '[STAGING] ')
|
12
12
|
# For simple staging, just one server that does everything.
|
13
13
|
server('readme.stage', :address => '0.0.0.0') {
|
14
|
-
|
14
|
+
cap_role(:web, :app, :db)
|
15
|
+
puppet_role('proxy', 'app', 'db')
|
15
16
|
}
|
16
17
|
}
|
17
18
|
|
@@ -28,7 +29,8 @@ application('readme', :recipes => 'deploy') {
|
|
28
29
|
|
29
30
|
group('proxy') {
|
30
31
|
# Servers will have the :web role and the 'proxy' puppet class.
|
31
|
-
|
32
|
+
cap_role(:web)
|
33
|
+
puppet_role('proxy')
|
32
34
|
server('proxy-1', :address => '10.10.10.5')
|
33
35
|
}
|
34
36
|
|
data/test/unit/test_group.rb
CHANGED
@@ -119,7 +119,7 @@ class Hubcap::TestGroup < Test::Unit::TestCase
|
|
119
119
|
server('test')
|
120
120
|
}
|
121
121
|
assert_equal([:baseline], hub.servers.first.cap_roles)
|
122
|
-
assert_equal(
|
122
|
+
assert_equal({ 'baseline' => nil }, hub.servers.first.puppet_roles)
|
123
123
|
|
124
124
|
# Multiple roles in a single declaration
|
125
125
|
hub = Hubcap.hub {
|
@@ -127,7 +127,10 @@ class Hubcap::TestGroup < Test::Unit::TestCase
|
|
127
127
|
server('test')
|
128
128
|
}
|
129
129
|
assert_equal([:baseline, :app], hub.servers.first.cap_roles)
|
130
|
-
assert_equal(
|
130
|
+
assert_equal(
|
131
|
+
{ 'baseline' => nil, 'app' => nil },
|
132
|
+
hub.servers.first.puppet_roles
|
133
|
+
)
|
131
134
|
|
132
135
|
# Multiple declarations are additive
|
133
136
|
hub = Hubcap.hub {
|
@@ -135,26 +138,46 @@ class Hubcap::TestGroup < Test::Unit::TestCase
|
|
135
138
|
server('test') { role(:db) }
|
136
139
|
}
|
137
140
|
assert_equal([:baseline, :db], hub.servers.first.cap_roles)
|
138
|
-
assert_equal(
|
141
|
+
assert_equal(
|
142
|
+
{ 'baseline' => nil, 'db' => nil },
|
143
|
+
hub.servers.first.puppet_roles
|
144
|
+
)
|
139
145
|
|
140
146
|
# Separate cap and puppet roles
|
141
147
|
hub = Hubcap.hub {
|
142
|
-
|
148
|
+
cap_role(:app)
|
149
|
+
puppet_role('testapp')
|
143
150
|
server('test')
|
144
151
|
}
|
145
152
|
assert_equal([:app], hub.servers.first.cap_roles)
|
146
|
-
assert_equal(
|
153
|
+
assert_equal({ 'testapp' => nil }, hub.servers.first.puppet_roles)
|
147
154
|
|
148
155
|
# Separate cap/puppet roles can be defined with an array
|
149
156
|
# Also shows that multiple role declarations are additive
|
150
157
|
hub = Hubcap.hub {
|
151
|
-
|
158
|
+
cap_role(:app, :db)
|
152
159
|
server('test') { role(:baseline) }
|
153
160
|
}
|
154
161
|
assert_equal([:app, :db], hub.cap_roles)
|
155
|
-
assert_equal(
|
162
|
+
assert_equal({}, hub.puppet_roles)
|
156
163
|
assert_equal([:app, :db, :baseline], hub.servers.first.cap_roles)
|
157
|
-
assert_equal(
|
164
|
+
assert_equal({ 'baseline' => nil }, hub.servers.first.puppet_roles)
|
165
|
+
|
166
|
+
# Puppet roles can be passed parameters in a hash.
|
167
|
+
hub = Hubcap.hub {
|
168
|
+
puppet_role(:foo, :bar, { :garply => { :grault => 'x' } }, :garp)
|
169
|
+
server('test') { role(:baseline) }
|
170
|
+
}
|
171
|
+
assert_equal(
|
172
|
+
{
|
173
|
+
'foo' => nil,
|
174
|
+
'bar' => nil,
|
175
|
+
'garply' => { 'grault' => 'x' },
|
176
|
+
'garp' => nil,
|
177
|
+
'baseline' => nil
|
178
|
+
},
|
179
|
+
hub.servers.first.puppet_roles
|
180
|
+
)
|
158
181
|
end
|
159
182
|
|
160
183
|
|
data/test/unit/test_server.rb
CHANGED
@@ -60,7 +60,7 @@ class Hubcap::TestServer < Test::Unit::TestCase
|
|
60
60
|
}
|
61
61
|
}
|
62
62
|
hash = YAML.load(hub.servers.first.yaml)
|
63
|
-
assert_equal(
|
63
|
+
assert_equal({ 'baseline' => nil, 'test::server' => nil }, hash['classes'])
|
64
64
|
assert_equal(['classes', 'parameters'], hash.keys.sort)
|
65
65
|
assert_equal(['bar', 'foo'], hash['parameters'].keys.sort)
|
66
66
|
assert_equal([1, 2], hash['parameters'].values.sort)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 6
|
9
|
+
version: 0.0.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joseph Pearson
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-
|
17
|
+
date: 2012-11-01 00:00:00 +11:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|