knife-cereal 0.1.0

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/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ pkg/*
2
+
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 2.0.0
3
+ script: bundle exec rake spec
4
+ notifications:
5
+ email: thefellowship@rallydev.com
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in knife-cereal.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,96 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ knife-cereal (0.1.0)
5
+ chef (~> 11.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ chef (11.10.4)
11
+ chef-zero (~> 1.7, >= 1.7.2)
12
+ diff-lcs (~> 1.2, >= 1.2.4)
13
+ erubis (~> 2.7)
14
+ highline (~> 1.6, >= 1.6.9)
15
+ json (>= 1.4.4, <= 1.8.1)
16
+ mime-types (~> 1.16)
17
+ mixlib-authentication (~> 1.3)
18
+ mixlib-cli (~> 1.4)
19
+ mixlib-config (~> 2.0)
20
+ mixlib-log (~> 1.3)
21
+ mixlib-shellout (~> 1.3)
22
+ net-ssh (~> 2.6)
23
+ net-ssh-multi (~> 1.1)
24
+ ohai (~> 6.0)
25
+ pry (~> 0.9)
26
+ puma (~> 1.6)
27
+ rest-client (>= 1.0.4, < 1.7.0)
28
+ yajl-ruby (~> 1.1)
29
+ chef-zero (1.7.3)
30
+ hashie (~> 2.0)
31
+ json
32
+ mixlib-log (~> 1.3)
33
+ moneta (< 0.7.0)
34
+ rack
35
+ coderay (1.1.0)
36
+ diff-lcs (1.2.5)
37
+ erubis (2.7.0)
38
+ hashie (2.0.5)
39
+ highline (1.6.21)
40
+ ipaddress (0.8.0)
41
+ json (1.8.1)
42
+ method_source (0.8.2)
43
+ mime-types (1.25.1)
44
+ mixlib-authentication (1.3.0)
45
+ mixlib-log
46
+ mixlib-cli (1.4.0)
47
+ mixlib-config (2.1.0)
48
+ mixlib-log (1.6.0)
49
+ mixlib-shellout (1.3.0)
50
+ moneta (0.6.0)
51
+ net-ssh (2.8.0)
52
+ net-ssh-gateway (1.2.0)
53
+ net-ssh (>= 2.6.5)
54
+ net-ssh-multi (1.2.0)
55
+ net-ssh (>= 2.6.5)
56
+ net-ssh-gateway (>= 1.2.0)
57
+ ohai (6.20.0)
58
+ ipaddress
59
+ mixlib-cli
60
+ mixlib-config
61
+ mixlib-log
62
+ mixlib-shellout
63
+ systemu (~> 2.5.2)
64
+ yajl-ruby
65
+ pry (0.9.12.6)
66
+ coderay (~> 1.0)
67
+ method_source (~> 0.8)
68
+ slop (~> 3.4)
69
+ puma (1.6.3)
70
+ rack (~> 1.2)
71
+ rack (1.5.2)
72
+ rake (10.1.1)
73
+ rest-client (1.6.7)
74
+ mime-types (>= 1.16)
75
+ rspec (2.13.0)
76
+ rspec-core (~> 2.13.0)
77
+ rspec-expectations (~> 2.13.0)
78
+ rspec-mocks (~> 2.13.0)
79
+ rspec-core (2.13.1)
80
+ rspec-expectations (2.13.0)
81
+ diff-lcs (>= 1.1.3, < 2.0)
82
+ rspec-mocks (2.13.1)
83
+ slop (3.5.0)
84
+ systemu (2.5.2)
85
+ version (1.0.0)
86
+ yajl-ruby (1.2.0)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ bundler (~> 1.3)
93
+ knife-cereal!
94
+ rake (~> 10.0)
95
+ rspec (~> 2.13.0)
96
+ version (~> 1.0.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Rally Dev Pair
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ [![Build Status](https://travis-ci.org/RallySoftware-cookbooks/knife-cereal.svg)](https://travis-ci.org/RallySoftware-cookbooks/knife-cereal)
2
+
3
+ # knife-cereal
4
+
5
+ This knife plugin allows you to run a command on a set of nodes serially. It
6
+ will stop after the first failure.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'knife-cereal'
13
+
14
+ And then execute:
15
+
16
+ $ bundle install
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install knife-cereal
21
+
22
+ ## Example Usage
23
+
24
+ ```
25
+ knife cereal 'chef_environment:my_environment AND recipe:my_cookbook' 'sudo chef-client' -G deploy@gateway_host -x chef
26
+ ```
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ require 'rake/version_task'
4
+
5
+ Rake::VersionTask.new
6
+
7
+ RSpec::Core::RakeTask.new(:spec) do |spec|
8
+ spec.pattern = FileList['spec/**/*_spec.rb']
9
+ end
10
+
11
+ task 'version:bump' do
12
+ sh 'git push origin HEAD:master'
13
+ end
14
+
15
+ desc <<-DESC
16
+ Continuous integration task. This task will run all the specs.
17
+ If the specs pass then it will build the gem and publish it to Rally's internal gem
18
+ repository. To finish up it tags the release in git and bumps the version number.
19
+ The CI server should ignore the VERSION file to prevent an infinite build loop
20
+ DESC
21
+ task :ci => [:spec, :release, 'version:bump']
22
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'knife-cereal/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "knife-cereal"
7
+ gem.version = Cereal::VERSION
8
+ gem.authors = ["Eli Klein", "Jeff Smith" ]
9
+ gem.email = ["eklein@rallydev.com"]
10
+ gem.homepage = %q{https://github.com/RallySoftware-cookbooks/knife-cereal}
11
+ gem.summary = %q{Super cereal knife plugin}
12
+ gem.description = %q{This gem allows you to run any command on nodes serially and will stop after the first failure.}
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ gem.require_paths = ["lib"]
18
+
19
+ # specify any dependencies here; for example:
20
+ gem.add_development_dependency("rspec", "~> 2.13.0")
21
+ gem.add_development_dependency("bundler", "~>1.3")
22
+ gem.add_development_dependency("version", "~> 1.0.0")
23
+ gem.add_development_dependency("rake", "~>10.0")
24
+
25
+ gem.add_dependency("chef", "~>11.0")
26
+ end
@@ -0,0 +1,82 @@
1
+ require 'chef/knife'
2
+
3
+ class Chef
4
+ class Knife
5
+ class Cereal < Knife
6
+ banner "knife cereal QUERY (ssh options)"
7
+
8
+ deps do
9
+ require 'chef/search/query'
10
+ require 'chef/knife/ssh'
11
+ require 'net/ssh'
12
+ require 'net/ssh/multi'
13
+ require 'net/http'
14
+ require 'json'
15
+ end
16
+
17
+ attr_reader :query
18
+ attr_reader :command
19
+
20
+ option :ssh_user,
21
+ :short => "-x USERNAME",
22
+ :long => "--ssh-user USERNAME",
23
+ :description => "The ssh username"
24
+
25
+ option :ssh_password,
26
+ :short => "-P PASSWORD",
27
+ :long => "--ssh-password PASSWORD",
28
+ :description => "The ssh password"
29
+
30
+ option :ssh_port,
31
+ :short => "-p PORT",
32
+ :long => "--ssh-port PORT",
33
+ :description => "The ssh port"
34
+
35
+ option :ssh_gateway,
36
+ :short => "-G GATEWAY",
37
+ :long => "--ssh-gateway GATEWAY",
38
+ :description => "The ssh gateway"
39
+
40
+ def run
41
+ parse_args!
42
+ begin
43
+ query_nodes = Chef::Search::Query.new
44
+ query_nodes.search('node', query) do |node|
45
+ cereal(node, command)
46
+ end
47
+ rescue Exception => e
48
+ ui.fatal "Node failed to cereal: #{e.message}"
49
+ ui.fatal e.backtrace.join("\n")
50
+ exit 1
51
+ end
52
+ end
53
+
54
+ def cereal(node, command)
55
+ ui.msg "Running [#{command}] on node: [#{node.name}]"
56
+ chef_client_command(node.name, command).run
57
+ end
58
+
59
+ def chef_client_command(node_name, command)
60
+ knife_ssh = Chef::Knife::Ssh.new
61
+ knife_ssh.config[:manual] = true
62
+ knife_ssh.name_args[0] = node_name
63
+ knife_ssh.name_args[1] = command
64
+ knife_ssh.config[:ssh_user] = config[:ssh_user]
65
+ knife_ssh.config[:ssh_password] = config[:ssh_password]
66
+ knife_ssh.config[:ssh_port] = config[:ssh_port]
67
+ knife_ssh.config[:ssh_gateway] = config[:ssh_gateway]
68
+ knife_ssh
69
+ end
70
+
71
+ def parse_args!
72
+ @query = @name_args[0]
73
+ @command = @name_args[1]
74
+
75
+ if @query.nil? || @command.nil?
76
+ ui.fatal "You need to specify the query and the command."
77
+ exit 1
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,3 @@
1
+ module Cereal
2
+ VERSION = File.open(File.expand_path('../../../VERSION', __FILE__)).read
3
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ class Chef
4
+ class Knife
5
+ describe Chef::Knife::Cereal do
6
+ before(:each) do
7
+ @knife = Cereal.new
8
+ end
9
+
10
+ describe "#parse_args!" do
11
+ it "should fail if a query is not provided" do
12
+ @knife.name_args = []
13
+ expect { @knife.parse_args! }.to raise_error
14
+ end
15
+
16
+ it "should fail if a command is not provided" do
17
+ @knife.name_args = [ 'chef_environment:foo' ]
18
+ expect { @knife.parse_args! }.to raise_error
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ begin
2
+ Bundler.setup(:default, :development)
3
+ rescue Bundler::BundlerError => e
4
+ $stderr.puts e.message
5
+ $stderr.puts "Run `bundle install` to install missing gems"
6
+ exit e.status_code
7
+ end
8
+ require 'rspec'
9
+
10
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
11
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
12
+
13
+ require 'chef/knife/cereal'
14
+
15
+ # Requires supporting files with custom matchers and macros, etc,
16
+ # in ./support/ and its subdirectories.
17
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-cereal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eli Klein
9
+ - Jeff Smith
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-03-20 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 2.13.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 2.13.0
31
+ - !ruby/object:Gem::Dependency
32
+ name: bundler
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '1.3'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '1.3'
47
+ - !ruby/object:Gem::Dependency
48
+ name: version
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 1.0.0
63
+ - !ruby/object:Gem::Dependency
64
+ name: rake
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: '10.0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: '10.0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: chef
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: '11.0'
87
+ type: :runtime
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '11.0'
95
+ description: This gem allows you to run any command on nodes serially and will stop
96
+ after the first failure.
97
+ email:
98
+ - eklein@rallydev.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - .gitignore
104
+ - .travis.yml
105
+ - Gemfile
106
+ - Gemfile.lock
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - VERSION
111
+ - knife-cereal.gemspec
112
+ - lib/chef/knife/cereal.rb
113
+ - lib/knife-cereal/version.rb
114
+ - spec/chef/knife/converge_spec.rb
115
+ - spec/spec_helper.rb
116
+ homepage: https://github.com/RallySoftware-cookbooks/knife-cereal
117
+ licenses: []
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ segments:
129
+ - 0
130
+ hash: -3787540514649438820
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ segments:
138
+ - 0
139
+ hash: -3787540514649438820
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 1.8.24
143
+ signing_key:
144
+ specification_version: 3
145
+ summary: Super cereal knife plugin
146
+ test_files:
147
+ - spec/chef/knife/converge_spec.rb
148
+ - spec/spec_helper.rb