champu 0.0.1 → 0.0.2

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.
@@ -1,2 +0,0 @@
1
- == Champu
2
-
@@ -16,7 +16,7 @@ class Champu
16
16
  @config ||= Champu::Config
17
17
  end
18
18
  def step(title)
19
- temp_step= Champu::Step.new(config,title)
19
+ temp_step= Champu::Step.new(title)
20
20
  yield(temp_step)
21
21
  temp_step
22
22
  end
@@ -10,38 +10,53 @@ require 'champu/monkeypatches/knife_ssh'
10
10
  class Champu
11
11
  class Step
12
12
 
13
- attr_reader :title,:config
14
- def nodes
15
- @nodes
16
- end
17
-
18
- def initialize(config,title)
13
+ attr_reader :title
14
+
15
+ def initialize(title)
19
16
  @title=title
20
- @config=config
21
17
  Chef::Config[:color]=true
18
+ @config={}
22
19
  end
20
+
23
21
  def ui
24
22
  @ui ||= Chef::Knife::UI.new(STDOUT,STDERR,STDIN,Champu::Config)
25
23
  end
24
+
25
+ def nodes
26
+ @nodes
27
+ end
28
+
29
+ def config(opts={})
30
+ @config.merge!(opts) unless opts.empty?
31
+ @config
32
+ end
33
+
34
+ def config_value(key)
35
+ @config.key?(key) ? @config[key] : Champu::Config[key]
36
+ end
37
+
26
38
  def search(term)
27
- Chef::Config[:knife][:ssh_attribute] = Champu::Config[:ssh_attribute]
28
- Chef::Config[:knife][:ssh_user]=Champu::Config[:ssh_user]
39
+ Chef::Config[:knife][:ssh_attribute] = config_value(:ssh_attribute)
40
+ Chef::Config[:knife][:ssh_user]= config_value :ssh_user
29
41
  @nodes=Chef::Search::Query.new.search(:node,term).first
30
42
  end
43
+
31
44
  def execute(command)
45
+ Chef::Config[:knife][:ssh_attribute] = config_value :ssh_attribute
46
+ Chef::Config[:knife][:ssh_user]= config_value :ssh_user
32
47
  ui.msg(ui.color("Executing command:",:magenta) + ui.color(command,:yellow))
33
48
  c=Chef::Knife::Ssh.new
34
49
  c.configure_attribute
35
50
  c.configure_user
36
51
  c.configure_identity_file
37
- c.config[:attribute]="ec2.public_ipv4"
52
+ c.config[:attribute]= config_value :ssh_attribute
38
53
  c.action_nodes(nodes)
39
54
 
40
55
  longest=0
41
56
  nodes.collect{|n|c.format_for_display(n)[c.config[:attribute]]}.each do |item|
42
- hostspec = "ec2-user@#{item}"
57
+ hostspec = "#{config_value(:ssh_user)}@#{item}"
43
58
  session_opts = {}
44
- session_opts[:keys] = Champu::Config[:identity_file]
59
+ session_opts[:keys] = config_value :identity_file
45
60
  session_opts[:keys_only] = true
46
61
  session_opts[:logger] = Chef::Log.logger
47
62
  session_opts[:paranoid] = false
@@ -1,3 +1,3 @@
1
1
  class Champu
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -35,13 +35,19 @@ describe Champu do
35
35
  end
36
36
  it "should allow user to execute a command for a step" do
37
37
  q=double('query')
38
- q.stub(:search).with(:node,"some criteria").and_return([Array.new])
38
+ q.stub(:search).with(:node,"some criteria").and_return([Chef::Node.new])
39
39
  Chef::Search::Query.stub(:new).with(no_args()).and_return(q)
40
40
  Chef::Knife::Ssh.stub(:ssh_command).with("some command")
41
- step=Champu::Step.new(nil,"title")
41
+ step=Champu::Step.new("title")
42
42
  step.search("some criteria")
43
43
  step.execute("some command")
44
44
  end
45
+ it "should allow user to specify step specific ssh config" do
46
+ opts={:user=>'user',:identity_file=>'xx.pem'}
47
+ step=Champu::Step.new("title")
48
+ step.config(opts)
49
+ step.config.should == opts
50
+ end
45
51
  it "should allow user to set the type of the step" do
46
52
  pending
47
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: champu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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-07-15 00:00:00.000000000 Z
12
+ date: 2012-07-16 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A simple orchestration/workflow dsl on top of knife ssh
15
15
  email: dey.ranjib@gmail.com