hubcap 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/hubcap/application.rb +0 -5
- data/lib/hubcap/group.rb +6 -23
- data/lib/hubcap/hub.rb +3 -5
- data/lib/hubcap/recipes/servers.rb +63 -9
- data/lib/hubcap/recipes/ssh.rb +15 -0
- data/lib/hubcap/server.rb +1 -0
- data/lib/hubcap/version.rb +1 -1
- data/test/data/example.rb +6 -6
- data/test/data/readme.rb +1 -1
- data/test/unit/test_hub.rb +20 -8
- metadata +42 -27
data/lib/hubcap/application.rb
CHANGED
data/lib/hubcap/group.rb
CHANGED
@@ -235,7 +235,11 @@ class Hubcap::Group
|
|
235
235
|
def resolv(*hnames)
|
236
236
|
if hnames.size == 1
|
237
237
|
result = lookup(hnames.first)
|
238
|
-
|
238
|
+
begin
|
239
|
+
result.match(IP_PATTERN) ? result : Resolv.getaddress(result)
|
240
|
+
rescue Resolv::ResolvError => e
|
241
|
+
raise(Hubcap::ServerAddressUnknown, hnames.first)
|
242
|
+
end
|
239
243
|
else
|
240
244
|
hnames.collect { |hname| resolv(hname) }
|
241
245
|
end
|
@@ -281,28 +285,6 @@ class Hubcap::Group
|
|
281
285
|
end
|
282
286
|
|
283
287
|
|
284
|
-
# Returns a formatted string of all the key details for this group, and
|
285
|
-
# recurses into each child.
|
286
|
-
#
|
287
|
-
def tree(indent = " ")
|
288
|
-
outs = [self.class.name.split('::').last.upcase, "Name: #{@name}"]
|
289
|
-
outs << "Atts: #{@cap_attributes.inspect}" if @cap_attributes.any?
|
290
|
-
if @cap_roles == @puppet_roles
|
291
|
-
outs << "Role: #{@cap_roles.inspect}" if @cap_roles.any?
|
292
|
-
else
|
293
|
-
cr = @cap_roles.any? ? 'Cap - '+@cap_roles.inspect : nil
|
294
|
-
pr = @puppet_roles.any? ? 'Puppet - '+@puppet_roles.inspect : nil
|
295
|
-
outs << "Role: #{[cr,pr].compact.join(' ')}" if cr || pr
|
296
|
-
end
|
297
|
-
outs << "Pram: #{@params.inspect}" if @params.any?
|
298
|
-
extend_tree(outs) if respond_to?(:extend_tree)
|
299
|
-
if @children.any?
|
300
|
-
@children.each { |child| outs << child.tree(indent+" ") }
|
301
|
-
end
|
302
|
-
outs.join("\n#{indent}")
|
303
|
-
end
|
304
|
-
|
305
|
-
|
306
288
|
private
|
307
289
|
|
308
290
|
def add_child(category, child)
|
@@ -323,5 +305,6 @@ class Hubcap::Group
|
|
323
305
|
class Hubcap::GroupWithoutParent < StandardError; end
|
324
306
|
class Hubcap::InvalidParamKeyType < StandardError; end
|
325
307
|
class Hubcap::HostCircularReference < StandardError; end
|
308
|
+
class Hubcap::ServerAddressUnknown < StandardError; end
|
326
309
|
|
327
310
|
end
|
data/lib/hubcap/hub.rb
CHANGED
@@ -28,11 +28,6 @@ class Hubcap::Hub < Hubcap::Group
|
|
28
28
|
end
|
29
29
|
|
30
30
|
|
31
|
-
def extend_tree(outs)
|
32
|
-
outs << "Sets: #{@cap_sets.inspect}"
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
31
|
# Does a few things:
|
37
32
|
#
|
38
33
|
# * Sets the :hubcap variable in the Capistrano instance.
|
@@ -52,11 +47,14 @@ class Hubcap::Hub < Hubcap::Group
|
|
52
47
|
|
53
48
|
cap.instance_eval {
|
54
49
|
require('hubcap/recipes/servers')
|
50
|
+
require('hubcap/recipes/ssh')
|
55
51
|
require('hubcap/recipes/puppet')
|
56
52
|
}
|
57
53
|
|
58
54
|
# Declare the servers.
|
59
55
|
servers.each { |svr|
|
56
|
+
# Raises an error if we cannot resolve the resulting address with DNS.
|
57
|
+
resolv(svr.address) unless svr.address.match(Hubcap::Group::IP_PATTERN)
|
60
58
|
opts = {
|
61
59
|
:name => svr.name,
|
62
60
|
:full_name => svr.history.join('.')
|
@@ -5,24 +5,78 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
5
5
|
desc <<-DESC
|
6
6
|
Lists all the servers that match the filter used when Hubcap was loaded.
|
7
7
|
DESC
|
8
|
+
task(:default) do
|
9
|
+
outs = hubcap.servers.collect { |s|
|
10
|
+
out = ["#{s.name}#{"(#{s.address})" if s.name != s.address}"]
|
11
|
+
if app = s.application_parent
|
12
|
+
out << " Appli: #{app.name}"
|
13
|
+
end
|
14
|
+
out << [" Attrs: "+s.cap_attributes.inspect] if s.cap_attributes.any?
|
15
|
+
if s.cap_roles == s.puppet_roles
|
16
|
+
out << " Roles: #{s.cap_roles}"
|
17
|
+
else
|
18
|
+
cr = s.cap_roles.any? ? 'Cap - '+s.cap_roles.inspect : nil
|
19
|
+
pr = s.puppet_roles.any? ? 'Puppet - '+s.puppet_roles.inspect : nil
|
20
|
+
out << " Roles: #{[cr,pr].compact.join(" | ")}" if cr || pr
|
21
|
+
end
|
22
|
+
out << " Parms: #{s.params.inspect}" if s.params.any?
|
23
|
+
out.join("\n")
|
24
|
+
}
|
25
|
+
puts(outs.join("\n\n"))
|
26
|
+
end
|
27
|
+
|
28
|
+
|
8
29
|
task(:list) do
|
9
|
-
|
30
|
+
outs = hubcap.servers.collect { |s|
|
31
|
+
out = []
|
32
|
+
out << s.history.join('.')
|
33
|
+
out << s.address
|
34
|
+
out << "App[#{s.application_parent.name}]" if s.application_parent
|
35
|
+
if s.cap_roles == s.puppet_roles
|
36
|
+
out << "Role#{s.cap_roles}"
|
37
|
+
else
|
38
|
+
out << "Cap#{s.cap_roles}" if s.cap_roles.any?
|
39
|
+
out << "Pup#{s.puppet_roles}" if s.puppet_roles.any?
|
40
|
+
end
|
41
|
+
out.join(', ')
|
42
|
+
}
|
43
|
+
puts(outs.join("\n"))
|
10
44
|
end
|
11
45
|
|
46
|
+
|
12
47
|
desc <<-DESC
|
13
48
|
Show the entire Hubcap configuration tree for the given filter.
|
14
49
|
DESC
|
15
50
|
task(:tree) do
|
16
|
-
|
51
|
+
tree = lambda { |obj, indent|
|
52
|
+
outs = [obj.class.name.split('::').last.upcase+': '+obj.name]
|
53
|
+
atts = obj.instance_variable_get(:@cap_attributes)
|
54
|
+
croles = obj.instance_variable_get(:@cap_roles)
|
55
|
+
proles = obj.instance_variable_get(:@puppet_roles)
|
56
|
+
prams = obj.instance_variable_get(:@params)
|
57
|
+
outs << "Atts: #{atts.inspect}" if atts.any?
|
58
|
+
if croles == proles
|
59
|
+
outs << "Role: #{croles.inspect}" if croles.any?
|
60
|
+
else
|
61
|
+
cr = croles.any? ? 'Cap - '+croles.inspect : nil
|
62
|
+
pr = proles.any? ? 'Puppet - '+proles.inspect : nil
|
63
|
+
outs << "Role: #{[cr,pr].compact.join(' ')}" if cr || pr
|
64
|
+
end
|
65
|
+
outs << "Parm: #{prams.inspect}" if prams.any?
|
66
|
+
if obj.is_a?(Hubcap::Hub)
|
67
|
+
outs << "Sets: #{obj.instance_variable_get(:@cap_sets).inspect}"
|
68
|
+
elsif obj.is_a?(Hubcap::Application)
|
69
|
+
recipes = obj.instance_variable_get(:@recipe_paths)
|
70
|
+
outs << "Load: #{recipes.inspect}" if recipes.any?
|
71
|
+
end
|
72
|
+
if obj.children.any?
|
73
|
+
obj.children.each { |child| outs << tree.call(child, indent+" ") }
|
74
|
+
end
|
75
|
+
outs.join("\n#{indent}")
|
76
|
+
}
|
77
|
+
puts(tree.call(hubcap, ' '))
|
17
78
|
end
|
18
79
|
|
19
80
|
end
|
20
81
|
|
21
|
-
|
22
|
-
task(:ssh) do
|
23
|
-
host = hubcap.servers.first.address
|
24
|
-
puts("SSH connect to: #{user}@#{host}")
|
25
|
-
system("ssh -A #{user}@#{host}")
|
26
|
-
end
|
27
|
-
|
28
82
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
|
3
|
+
namespace(:ssh) do
|
4
|
+
|
5
|
+
desc("Shells out to SSH for the first server that matches the filter.")
|
6
|
+
task(:default) do
|
7
|
+
host = hubcap.servers.first.address
|
8
|
+
puts("SSH connect to: #{user}@#{host}")
|
9
|
+
system("ssh -A #{user}@#{host}")
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
data/lib/hubcap/server.rb
CHANGED
data/lib/hubcap/version.rb
CHANGED
data/test/data/example.rb
CHANGED
@@ -52,16 +52,16 @@ application('example', :recipes => 'deploy') {
|
|
52
52
|
group('app') {
|
53
53
|
role(:app)
|
54
54
|
param('env' => prod_env.merge('FORCE_SSL' => '1'))
|
55
|
-
server('
|
56
|
-
server('
|
57
|
-
server('
|
55
|
+
server('example.com')
|
56
|
+
server('example.org')
|
57
|
+
server('example.net')
|
58
58
|
}
|
59
59
|
group('db') {
|
60
60
|
role(:db)
|
61
|
-
server('
|
62
|
-
server('
|
61
|
+
server('example.com')
|
62
|
+
server('example.net')
|
63
63
|
}
|
64
|
-
server('
|
64
|
+
server('example.com') {
|
65
65
|
role(:queue)
|
66
66
|
}
|
67
67
|
}
|
data/test/data/readme.rb
CHANGED
@@ -10,7 +10,7 @@ application('readme', :recipes => 'deploy') {
|
|
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
|
-
server('readme.stage') {
|
13
|
+
server('readme.stage', :address => '0.0.0.0') {
|
14
14
|
role(:cap => [:web, :app, :db], :puppet => ['proxy', 'app', 'db'])
|
15
15
|
}
|
16
16
|
}
|
data/test/unit/test_hub.rb
CHANGED
@@ -21,7 +21,7 @@ class Hubcap::TestHub < Test::Unit::TestCase
|
|
21
21
|
application('a') {
|
22
22
|
group('g') {
|
23
23
|
role(:baseline)
|
24
|
-
server('s') { role(:everything) }
|
24
|
+
server('s', :address => '0.0.0.0') { role(:everything) }
|
25
25
|
}
|
26
26
|
}
|
27
27
|
}
|
@@ -34,8 +34,8 @@ class Hubcap::TestHub < Test::Unit::TestCase
|
|
34
34
|
assert_not_nil(cap.find_task('servers:list'))
|
35
35
|
assert_not_nil(cap.find_task('puppet:check'))
|
36
36
|
assert_nil(cap.find_task('deploy:setup'))
|
37
|
-
assert_equal('
|
38
|
-
assert_equal('
|
37
|
+
assert_equal('0.0.0.0', cap.roles[:baseline].servers.first.host)
|
38
|
+
assert_equal('0.0.0.0', cap.roles[:everything].servers.first.host)
|
39
39
|
end
|
40
40
|
|
41
41
|
|
@@ -45,7 +45,7 @@ class Hubcap::TestHub < Test::Unit::TestCase
|
|
45
45
|
group('g') {
|
46
46
|
cap_set(:branch, 'deploy')
|
47
47
|
role(:baseline)
|
48
|
-
server('s') { role(:everything) }
|
48
|
+
server('s', :address => '0.0.0.0') { role(:everything) }
|
49
49
|
}
|
50
50
|
}
|
51
51
|
}
|
@@ -62,8 +62,8 @@ class Hubcap::TestHub < Test::Unit::TestCase
|
|
62
62
|
def test_configure_capistrano_in_application_mode_with_two_applications
|
63
63
|
hub = Hubcap.hub {
|
64
64
|
role(:baseline)
|
65
|
-
application('a1') { server('s1') }
|
66
|
-
application('a2') { server('s2') }
|
65
|
+
application('a1') { server('s1', :address => '1.1.1.1') }
|
66
|
+
application('a2') { server('s2', :address => '2.2.2.2') }
|
67
67
|
}
|
68
68
|
|
69
69
|
cap = Capistrano::Configuration.new
|
@@ -75,7 +75,9 @@ class Hubcap::TestHub < Test::Unit::TestCase
|
|
75
75
|
|
76
76
|
|
77
77
|
def test_configure_capistrano_in_application_mode_with_no_applications
|
78
|
-
hub = Hubcap.hub {
|
78
|
+
hub = Hubcap.hub {
|
79
|
+
server('s', :address => '0.0.0.0') { role(:baseline) }
|
80
|
+
}
|
79
81
|
|
80
82
|
cap = Capistrano::Configuration.new
|
81
83
|
cap.set(:hubcap_agnostic, false)
|
@@ -88,7 +90,7 @@ class Hubcap::TestHub < Test::Unit::TestCase
|
|
88
90
|
def test_configure_capistrano_in_application_mode_with_no_applications
|
89
91
|
hub = Hubcap.hub {
|
90
92
|
cap_set(:foo => 'bar')
|
91
|
-
server('
|
93
|
+
server('s', :address => '0.0.0.0') {
|
92
94
|
cap_set(:foo => 'baz')
|
93
95
|
role(:baseline)
|
94
96
|
}
|
@@ -101,4 +103,14 @@ class Hubcap::TestHub < Test::Unit::TestCase
|
|
101
103
|
}
|
102
104
|
end
|
103
105
|
|
106
|
+
|
107
|
+
def test_server_address_resolution
|
108
|
+
hub = Hubcap.hub {
|
109
|
+
server('s')
|
110
|
+
}
|
111
|
+
assert_raises(Hubcap::ServerAddressUnknown) {
|
112
|
+
hub.configure_capistrano(Capistrano::Configuration.new)
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
104
116
|
end
|
metadata
CHANGED
@@ -1,25 +1,33 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubcap
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
version: 0.0.5
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Joseph Pearson
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
16
|
+
|
17
|
+
date: 2012-10-01 00:00:00 +10:00
|
18
|
+
default_executable:
|
13
19
|
dependencies: []
|
14
|
-
|
15
|
-
|
16
|
-
email:
|
20
|
+
|
21
|
+
description: Create a hub for your server configuration. Use it with Capistrano, Puppet and others.
|
22
|
+
email:
|
17
23
|
- joseph@booki.sh
|
18
|
-
executables:
|
24
|
+
executables:
|
19
25
|
- hubcap
|
20
26
|
extensions: []
|
27
|
+
|
21
28
|
extra_rdoc_files: []
|
22
|
-
|
29
|
+
|
30
|
+
files:
|
23
31
|
- .gitignore
|
24
32
|
- Capfile.example
|
25
33
|
- README.md
|
@@ -33,6 +41,7 @@ files:
|
|
33
41
|
- lib/hubcap/hub.rb
|
34
42
|
- lib/hubcap/recipes/puppet.rb
|
35
43
|
- lib/hubcap/recipes/servers.rb
|
44
|
+
- lib/hubcap/recipes/ssh.rb
|
36
45
|
- lib/hubcap/server.rb
|
37
46
|
- lib/hubcap/version.rb
|
38
47
|
- test/data/example.rb
|
@@ -45,31 +54,37 @@ files:
|
|
45
54
|
- test/unit/test_hub.rb
|
46
55
|
- test/unit/test_hubcap.rb
|
47
56
|
- test/unit/test_server.rb
|
48
|
-
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: ""
|
49
59
|
licenses: []
|
60
|
+
|
50
61
|
post_install_message:
|
51
62
|
rdoc_options: []
|
52
|
-
|
63
|
+
|
64
|
+
require_paths:
|
53
65
|
- lib
|
54
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
requirements:
|
63
|
-
- -
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
66
80
|
requirements: []
|
81
|
+
|
67
82
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.
|
83
|
+
rubygems_version: 1.3.6
|
69
84
|
signing_key:
|
70
85
|
specification_version: 3
|
71
86
|
summary: Hubcap Capistrano/Puppet extension
|
72
|
-
test_files:
|
87
|
+
test_files:
|
73
88
|
- test/data/example.rb
|
74
89
|
- test/data/parts/foo_param.rb
|
75
90
|
- test/data/readme.rb
|