runpuppet 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "mocha"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.5.2"
13
+ gem "rcov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ mocha (0.9.12)
10
+ rake (0.9.2)
11
+ rcov (0.9.9)
12
+ shoulda (2.11.3)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler (~> 1.0.0)
19
+ jeweler (~> 1.5.2)
20
+ mocha
21
+ rcov
22
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Roman Heinrich
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,28 @@
1
+ = runpuppet
2
+
3
+
4
+ cat /etc/runpuppet.yml:
5
+ puppet_controller_url: http://user:pass@example.com
6
+ command:cd /etc/puppet/repo && git fetch && git checkout -f origin/@@branch@@ && puppet -v --debug --logdest console --modulepath /etc/puppet/repo/modules /etc/puppet/repo/manifests/site.pp
7
+ defaulf_branch: staging
8
+ local_ip: 192.168.10.10
9
+ lock_file: /tmp/runpuppet.lock
10
+
11
+
12
+ This is the companion for our puppet_controller, a light-weight web-service to coordinate local puppet runs on servers.
13
+
14
+ == Contributing to runpuppet
15
+
16
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
17
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
18
+ * Fork the project
19
+ * Start a feature/bugfix branch
20
+ * Commit and push until you are happy with your contribution
21
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
22
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
23
+
24
+ == Copyright
25
+
26
+ Copyright (c) 2011 Roman Heinrich. See LICENSE.txt for
27
+ further details.
28
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "runpuppet"
16
+ gem.homepage = "http://github.com/dawanda/runpuppet"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{The counterpart to puppet_controller}
19
+ gem.description = %Q{Is the local client to the puppet_controller}
20
+ gem.email = "roman.heinrich@gmail.com"
21
+ gem.authors = ["Roman Heinrich"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "runpuppet #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.1
data/bin/runpuppet ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'optparse'
4
+ $LOAD_PATH << "#{File.dirname(__FILE__)}/../lib"
5
+ require 'runpuppet'
6
+
7
+ options = {}
8
+
9
+ OptionParser.new do |opts|
10
+ opts.banner = <<BANNER
11
+ Runpuppet for puppet_controller
12
+
13
+ Usage:
14
+ runpuppet # runs forced puppetrun
15
+ runpuppet --try # runs only if told by puppet_controller
16
+ runpuppet --branch feature # run a non-default branch
17
+ Options:
18
+ BANNER
19
+
20
+ opts.on("-h", "--help","Show this.") { puts opts; exit }
21
+ opts.on('-v', '--version','Show Version'){ puts Runpuppet::VERSION; exit}
22
+ opts.on('--try','Runs only if selected on puppet_controller'){ options[:try] = false }
23
+ opts.on('--branch x', 'Run this branch') do |branch|
24
+ options[:branch] = branch
25
+ end
26
+ end.parse!
27
+
28
+
29
+ Runpuppet.run(options)
data/lib/runpuppet.rb ADDED
@@ -0,0 +1,102 @@
1
+ require 'open-uri'
2
+ require 'socket'
3
+
4
+ class Runpuppet
5
+ def self.with_lock(lock_file)
6
+ recently_locked = (File.exists?(lock_file) and File.mtime(lock_file) > Time.now - 15*60)
7
+
8
+ if recently_locked
9
+ puts "can not run, lockfile #{lock_file} exists"
10
+ else
11
+ begin
12
+ `touch #{lock_file}`
13
+ yield
14
+ ensure
15
+ `rm #{lock_file}`
16
+ end
17
+ end
18
+ end
19
+
20
+ # simplified copy of rake`s sh
21
+ def self.sh(cmd)
22
+ puts cmd
23
+ IO.popen(cmd) do |pipe|
24
+ while str = pipe.gets
25
+ puts str
26
+ end
27
+ end
28
+ $?.success?
29
+ end
30
+
31
+
32
+ def get(path)
33
+ path += (path.include?('?') ? '&' : '?')
34
+ path += "hostname=#{Socket.gethostname}&ip=#{Config.local_ip}"
35
+ open(Config.puppet_controller_url + path, Config.puppet_controller_auth) rescue puts "WARNING: no connection to puppet controller!"
36
+ end
37
+
38
+
39
+ def self.run(options={})
40
+ with_lock(Config.lock_file) do
41
+ time = Time.now.utc.strftime("%Y-%m-%d %H:%M:%S")
42
+
43
+ todo, branch = get("/puppet/run").read.split('-') rescue []
44
+ if todo == 'run' or !options[:try] # try allows not running
45
+ get '/puppet/status?status=started'
46
+ branch ||= Config.default_branch
47
+ cmd = Config.command.gsub('@@branch@@', branch)
48
+ puts "#{time}: run #{branch}"
49
+
50
+ if sh(cmd)
51
+ get '/puppet/status?status=finished'
52
+ else
53
+ get '/puppet/status?status=error'
54
+ exit 2
55
+ end
56
+ else
57
+ puts "#{time}: nothing to do"
58
+ end
59
+ end
60
+ end
61
+
62
+
63
+ class Config
64
+ def self.config
65
+ home = File.expand_path('~')
66
+ ["#{home}/.runpuppet.yml", '/etc/runpuppet.yml'].each do |file|
67
+ return YAML.load(File.read(file)) if File.exist?(file)
68
+ end
69
+ raise "No runpuppet.yml found in /etc or #{home}"
70
+ end
71
+
72
+ def self.puppet_controller_url
73
+ config['puppet_controller_url'].sub(%r{/$},'')
74
+ end
75
+
76
+ def self.puppet_controller_auth
77
+ extract_auth_from_url!(config['puppet_controller_url'])
78
+ end
79
+
80
+ def self.extract_auth_from_url!(url)
81
+ url.sub!(%r{//(.*?):(.*?)@}, '//')
82
+ auth = [$1, $2].compact
83
+ auth.empty? ? nil : auth
84
+ end
85
+
86
+ def self.lock_file
87
+ config['lock_file'] || '/tmp/runpuppet.lock'
88
+ end
89
+
90
+ def self.command
91
+ config['command'] || "cd /etc/puppet/repo && git fetch && git checkout -f origin/@@branch@@ && puppet -v --debug --logdest console --modulepath /etc/puppet/repo/modules /etc/puppet/repo/manifests/site.pp"
92
+ end
93
+
94
+ def self.default_branch
95
+ config['defaulf_branch'] || 'master'
96
+ end
97
+
98
+ def self.local_ip
99
+ %x(ifconfig)[/192.168.\d+.\d+/] || config['local_ip']
100
+ end
101
+ end
102
+ end
data/runpuppet.gemspec ADDED
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{runpuppet}
8
+ s.version = "0.5.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Roman Heinrich"]
12
+ s.date = %q{2011-07-01}
13
+ s.default_executable = %q{runpuppet}
14
+ s.description = %q{Is the local client to the puppet_controller}
15
+ s.email = %q{roman.heinrich@gmail.com}
16
+ s.executables = ["runpuppet"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/runpuppet",
30
+ "lib/runpuppet.rb",
31
+ "runpuppet.gemspec",
32
+ "test/helper.rb",
33
+ "test/test_runpuppet.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/dawanda/runpuppet}
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.6.2}
39
+ s.summary = %q{The counterpart to puppet_controller}
40
+ s.test_files = [
41
+ "test/helper.rb",
42
+ "test/test_runpuppet.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
50
+ s.add_development_dependency(%q<mocha>, [">= 0"])
51
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
53
+ s.add_development_dependency(%q<rcov>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<shoulda>, [">= 0"])
56
+ s.add_dependency(%q<mocha>, [">= 0"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
59
+ s.add_dependency(%q<rcov>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_dependency(%q<mocha>, [">= 0"])
64
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
66
+ s.add_dependency(%q<rcov>, [">= 0"])
67
+ end
68
+ end
69
+
data/test/helper.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+ require 'mocha'
13
+
14
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
16
+ require 'runpuppet'
17
+
18
+ class Test::Unit::TestCase
19
+ end
@@ -0,0 +1,11 @@
1
+ require 'helper'
2
+
3
+ class TestRunpuppet < Test::Unit::TestCase
4
+ context 'Config' do
5
+ should "parse the auth info from url" do
6
+ Runpuppet::Config.stubs(:config => {'puppet_controller_url' => 'http://user:pass@example.com'})
7
+ assert_equal "http://user:pass@example.com", Runpuppet::Config.puppet_controller_url
8
+ assert_equal ['user', 'pass'], Runpuppet::Config.puppet_controller_auth
9
+ end
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: runpuppet
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 1
10
+ version: 0.5.1
11
+ platform: ruby
12
+ authors:
13
+ - Roman Heinrich
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-01 00:00:00 +02:00
19
+ default_executable: runpuppet
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ name: shoulda
32
+ prerelease: false
33
+ type: :development
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ hash: 3
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ name: mocha
46
+ prerelease: false
47
+ type: :development
48
+ requirement: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ version_requirements: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ hash: 23
56
+ segments:
57
+ - 1
58
+ - 0
59
+ - 0
60
+ version: 1.0.0
61
+ name: bundler
62
+ prerelease: false
63
+ type: :development
64
+ requirement: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ version_requirements: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ hash: 7
72
+ segments:
73
+ - 1
74
+ - 5
75
+ - 2
76
+ version: 1.5.2
77
+ name: jeweler
78
+ prerelease: false
79
+ type: :development
80
+ requirement: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ version_requirements: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ name: rcov
92
+ prerelease: false
93
+ type: :development
94
+ requirement: *id005
95
+ description: Is the local client to the puppet_controller
96
+ email: roman.heinrich@gmail.com
97
+ executables:
98
+ - runpuppet
99
+ extensions: []
100
+
101
+ extra_rdoc_files:
102
+ - LICENSE.txt
103
+ - README.rdoc
104
+ files:
105
+ - .document
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.rdoc
110
+ - Rakefile
111
+ - VERSION
112
+ - bin/runpuppet
113
+ - lib/runpuppet.rb
114
+ - runpuppet.gemspec
115
+ - test/helper.rb
116
+ - test/test_runpuppet.rb
117
+ has_rdoc: true
118
+ homepage: http://github.com/dawanda/runpuppet
119
+ licenses:
120
+ - MIT
121
+ post_install_message:
122
+ rdoc_options: []
123
+
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ hash: 3
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ hash: 3
141
+ segments:
142
+ - 0
143
+ version: "0"
144
+ requirements: []
145
+
146
+ rubyforge_project:
147
+ rubygems_version: 1.6.2
148
+ signing_key:
149
+ specification_version: 3
150
+ summary: The counterpart to puppet_controller
151
+ test_files:
152
+ - test/helper.rb
153
+ - test/test_runpuppet.rb