hubcap 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .screenrc
@@ -0,0 +1,11 @@
1
+ require 'capistrano'
2
+
3
+ class Capistrano::ServerDefinition
4
+
5
+ alias base_to_s to_s
6
+
7
+ def to_s
8
+ @to_s ||= options[:full_name] || base_to_s
9
+ end
10
+
11
+ end
data/lib/hubcap/group.rb CHANGED
@@ -18,6 +18,7 @@ class Hubcap::Group
18
18
  @cap_roles = []
19
19
  @puppet_roles = []
20
20
  @params = {}
21
+ @hosts = {}
21
22
  @children = []
22
23
  instance_eval(&blk) if blk && processable?
23
24
  end
@@ -180,6 +181,27 @@ class Hubcap::Group
180
181
  end
181
182
 
182
183
 
184
+ # Defines hostnames that point to IP addresses. Eg,
185
+ #
186
+ # host('staging-1' => '192.168.1.20')
187
+ #
188
+ # This is solely used as a look-up table for resolv(). If the hostname can't
189
+ # be found in this list, resolv() will fall back to a normal DNS look-up.
190
+ # It's a neat way to define your infrastructure with names, rather than
191
+ # hard-coding IPs, without needing a shared DNS server for everyone
192
+ # (and without having to wait for DNS to propagate). Think of it as a
193
+ # built-in /etc/hosts file.
194
+ #
195
+ # You can define multiple hostname/ip pairs in a single call.
196
+ #
197
+ # A group inherits a clone of its parent's hosts. So if you want to change
198
+ # the IP of a hostname just for a child-group, you can (but: caveat emptor).
199
+ #
200
+ def host(hash)
201
+ @hosts = hash
202
+ end
203
+
204
+
183
205
  def cap_attributes
184
206
  @parent ? @parent.cap_attributes.merge(@cap_attributes) : @cap_attributes
185
207
  end
@@ -200,6 +222,23 @@ class Hubcap::Group
200
222
  end
201
223
 
202
224
 
225
+ def hosts
226
+ @parent ? @parent.hosts.merge(@hosts) : @hosts
227
+ end
228
+
229
+
230
+ # Takes a name and returns an IP address. It looks at the @hosts table first,
231
+ # then falls back to a normal DNS look-up.
232
+ #
233
+ def resolv(*hnames)
234
+ if hnames.size == 1
235
+ hosts[hnames.first] || Resolv.getaddress(hnames.first)
236
+ else
237
+ hnames.collect { |hname| resolv(hname) }
238
+ end
239
+ end
240
+
241
+
203
242
  # Instantiate an application as a child of this group.
204
243
  #
205
244
  def application(name, options = {}, &blk)
@@ -258,14 +297,6 @@ class Hubcap::Group
258
297
  end
259
298
 
260
299
 
261
- def resolv(*names)
262
- require 'resolv'
263
- if names.size == 1
264
- Resolv.getaddress(names.first)
265
- else
266
- names.collect { |name| Resolv.getaddress(name) }
267
- end
268
- end
269
300
 
270
301
 
271
302
  class Hubcap::GroupWithoutParent < StandardError; end
data/lib/hubcap/hub.rb CHANGED
@@ -56,8 +56,12 @@ class Hubcap::Hub < Hubcap::Group
56
56
  }
57
57
 
58
58
  # Declare the servers.
59
- servers.each { |s|
60
- cap.server(s.address, *(s.cap_roles + [s.cap_attributes]))
59
+ servers.each { |svr|
60
+ opts = {
61
+ :name => svr.name,
62
+ :full_name => svr.history.join('.')
63
+ }.merge(svr.cap_attributes)
64
+ cap.server(svr.address, *(svr.cap_roles + [opts]))
61
65
  }
62
66
 
63
67
  configure_application_mode(cap) unless capistrano_is_agnostic?(cap)
@@ -55,7 +55,7 @@ Capistrano::Configuration.instance(:must_exist).load do
55
55
  'echo "Ruby 1.9 verified";',
56
56
  'else',
57
57
  "#{apt_cmd} update;",
58
- "#{apt_cmd} install ruby1.9.1 git-core;",
58
+ "#{apt_cmd} install ruby1.9.1 ruby1.9.1-dev git-core;",
59
59
  'fi'
60
60
  ].join(' '))
61
61
 
@@ -88,8 +88,8 @@ Capistrano::Configuration.instance(:must_exist).load do
88
88
  DESC
89
89
  task(:update) do
90
90
  handle_data = lambda { |channel, stream, text|
91
- host = channel[:host]
92
- logger.info "[#{host} :: #{stream}] #{text}"
91
+ host = channel[:server]
92
+ logger.info "[#{stream} :: #{host}] #{text}"
93
93
  out = case text
94
94
  when /\bpassword.*:/i, /passphrase/i # Git password or SSH passphrase.
95
95
  "#{puppet_git_password}\n"
@@ -1,5 +1,5 @@
1
1
  module Hubcap
2
2
 
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
 
5
5
  end
data/lib/hubcap.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'yaml'
2
+ require 'resolv'
2
3
 
3
4
  module Hubcap
4
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hubcap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-26 00:00:00.000000000 Z
12
+ date: 2012-09-27 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Create a hub for your server configuration. Use it with Capistrano, Puppet
15
15
  and others.
@@ -20,6 +20,7 @@ executables:
20
20
  extensions: []
21
21
  extra_rdoc_files: []
22
22
  files:
23
+ - .gitignore
23
24
  - Capfile.example
24
25
  - README.md
25
26
  - Rakefile
@@ -27,6 +28,7 @@ files:
27
28
  - hubcap.gemspec
28
29
  - lib/hubcap.rb
29
30
  - lib/hubcap/application.rb
31
+ - lib/hubcap/ext/full_server_names.rb
30
32
  - lib/hubcap/group.rb
31
33
  - lib/hubcap/hub.rb
32
34
  - lib/hubcap/recipes/puppet.rb