spatula 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/spatula/cook.rb CHANGED
@@ -2,15 +2,10 @@ module Spatula
2
2
  # TODO: Set REMOTE_CHEF_PATH using value for file_cache_path
3
3
  REMOTE_CHEF_PATH = "/tmp/chef-solo" # Where to find upstream cookbooks
4
4
 
5
- class Cook
6
- def self.run(*args)
7
- new(*args).run
8
- end
9
-
10
- def initialize(server, node, port=22)
11
- @server = server
5
+ class Cook < SshCommand
6
+ def initialize(server, node, port=nil, login=nil, identity=nil)
7
+ super(server, port, login, identity)
12
8
  @node = node
13
- @port = port
14
9
  end
15
10
 
16
11
  def run
@@ -18,11 +13,12 @@ module Spatula
18
13
  ok = sh "ruby -c #{recipe} >/dev/null 2>&1"
19
14
  raise "Syntax error in #{recipe}" if not ok
20
15
  end
16
+
21
17
  if @server =~ /^local$/i
22
18
  sh chef_cmd
23
19
  else
24
- sh "rsync -rlP --rsh=\"ssh -p#@port\" --delete --exclude '.*' ./ #@server:#{REMOTE_CHEF_PATH}"
25
- sh "ssh -t -p #@port -A #@server \"cd #{REMOTE_CHEF_PATH}; #{chef_cmd} \""
20
+ sh "rsync -rlP --rsh=\"ssh #{ssh_opts}\" --delete --exclude '.*' ./ #@server:#{REMOTE_CHEF_PATH}"
21
+ ssh "cd #{REMOTE_CHEF_PATH}; #{chef_cmd}"
26
22
  end
27
23
  end
28
24
 
@@ -30,9 +26,5 @@ module Spatula
30
26
  def chef_cmd
31
27
  "sudo chef-solo -c config/solo.rb -j config/#@node.json"
32
28
  end
33
-
34
- def sh(command)
35
- system command
36
- end
37
29
  end
38
30
  end
@@ -1,26 +1,6 @@
1
1
  # Prepare :server: for chef solo to run on it
2
2
  module Spatula
3
- class Prepare
4
- def self.run(*args)
5
- new(*args).run
6
- end
7
-
8
- def initialize(server, port=nil, login=nil, identity=nil)
9
- @server = server
10
- @port = port
11
- @port_switch = port ? " -p #{port}" : ''
12
- @login_switch = login ? "-l #{login}" : ''
13
- @identity_switch = identity ? %Q|-i "#{identity}"| : ''
14
- end
15
-
16
- def ssh(command)
17
- sh ssh_command(command)
18
- end
19
-
20
- def ssh_command(command)
21
- %Q|ssh -t#@port_switch #@login_switch #@identity_switch #@server "#{command.gsub('"', '\\"')}"|
22
- end
23
-
3
+ class Prepare < SshCommand
24
4
  def run
25
5
  send "run_for_#{os}"
26
6
  end
@@ -43,10 +23,5 @@ module Spatula
43
23
 
44
24
  ssh "sudo gem install rdoc chef ohai --no-ri --no-rdoc --source http://gems.opscode.com --source http://gems.rubyforge.org"
45
25
  end
46
-
47
- private
48
- def sh(command)
49
- system command
50
- end
51
26
  end
52
27
  end
@@ -0,0 +1,32 @@
1
+ module Spatula
2
+ class SshCommand
3
+ def self.run(*args)
4
+ new(*args).run
5
+ end
6
+
7
+ def initialize(server, port=nil, login=nil, identity=nil)
8
+ @server = server
9
+ @port = port
10
+ @port_switch = port ? " -p #{port}" : ''
11
+ @login_switch = login ? "-l #{login}" : ''
12
+ @identity_switch = identity ? %Q|-i "#{identity}"| : ''
13
+ end
14
+
15
+ def ssh(command)
16
+ sh ssh_command(command)
17
+ end
18
+
19
+ def ssh_command(command)
20
+ %Q|ssh -t#{ssh_opts} #@server "#{command.gsub('"', '\\"')}"|
21
+ end
22
+
23
+ def ssh_opts
24
+ "#@port_switch #@login_switch #@identity_switch"
25
+ end
26
+
27
+ private
28
+ def sh(command)
29
+ system command
30
+ end
31
+ end
32
+ end
data/lib/spatula.rb CHANGED
@@ -25,7 +25,7 @@ module Spatula
25
25
  # Use ENV['HOME'] as the base here
26
26
  tarball_dir = "#{ENV['HOME']}/.spatula/cookbook_tarballs"
27
27
  FileUtils.mkdir_p(tarball_dir)
28
- system "curl #{file} -o #{tarball_dir}"
28
+ system "curl #{file} -o #{tarball_dir}/#{filename}"
29
29
  system "tar xzvf #{tarball_dir}/#{filename} -C cookbooks"
30
30
  end
31
31
 
@@ -36,9 +36,11 @@ module Spatula
36
36
  end
37
37
 
38
38
  desc "cook SERVER NODE", "Cook SERVER with the specification in config/NODE.js. Use local as the server to cook this box."
39
- method_options :port => 22
39
+ method_options :port => nil
40
+ method_options :login => nil
41
+ method_options :identity => nil
40
42
  def cook(server, node)
41
- Cook.run(server, node, options[:port])
43
+ Cook.run(server, node, options[:port], options[:login], options[:identity])
42
44
  end
43
45
 
44
46
  desc "prepare SERVER", "Install software/libs required by chef on SERVER"
@@ -73,6 +75,7 @@ if __FILE__ == $0
73
75
  $: << File.dirname(__FILE__)
74
76
  end
75
77
 
78
+ require 'spatula/ssh_command'
76
79
  require 'spatula/search'
77
80
  require 'spatula/prepare'
78
81
  require 'spatula/cook'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- version: 0.0.5
8
+ - 6
9
+ version: 0.0.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Trotter Cashion
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-18 00:00:00 -04:00
17
+ date: 2010-04-11 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -32,6 +32,7 @@ files:
32
32
  - lib/spatula/cook.rb
33
33
  - lib/spatula/prepare.rb
34
34
  - lib/spatula/search.rb
35
+ - lib/spatula/ssh_command.rb
35
36
  - lib/spatula.rb
36
37
  has_rdoc: true
37
38
  homepage: http://trottercashion.com