buratino 0.0.1

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,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Morion Black
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,29 @@
1
+ # Buratino
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'buratino'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install buratino
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/bin/buratino ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems"
3
+ require "buratino"
4
+
5
+ Buratino::Runner.run
data/buratino.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/buratino/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["InViZz"]
6
+ gem.email = ["morion.estariol@gmail.com"]
7
+ gem.description = %q{Write a gem description}
8
+ gem.summary = %q{Write a gem summary}
9
+ gem.homepage = "https://github.com/InViZz/buratino"
10
+
11
+ gem.executables = "buratino"
12
+ gem.files = [".gitignore", "LICENSE", "README.md", "buratino.gemspec", "lib/buratino.rb", "lib/buratino/version.rb", "lib/buratino/configure.rb", "lib/buratino/hg.rb", "lib/buratino/dirs.rb"]
13
+ gem.name = "buratino"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = Buratino::VERSION
16
+ gem.add_runtime_dependency 'mercurial-ruby'
17
+ gem.add_runtime_dependency 'puppet'
18
+ gem.add_runtime_dependency 'facter'
19
+ end
@@ -0,0 +1,47 @@
1
+ require "optparse"
2
+
3
+ module Buratino
4
+
5
+ class Configure
6
+
7
+ attr_reader :options
8
+
9
+ def initialize( configfile='/usr/local/etc/buratino.yaml' )
10
+ puts "DEBUG BURATINO::CONFIGURE::NEW"
11
+ @config = YAML.load_file( configfile )
12
+ @options = Hash.new
13
+ @options['puppet'] = @config['puppet_url']
14
+ @options['destination'] = @config['destination']
15
+ @options['reports_dir'] = @config['reports_dir']
16
+ @options['interval'] = @config['interval']
17
+ @options['angel'] = false
18
+
19
+ # Different Modes: clone, update
20
+ @options['mode'] = @config['mode']
21
+
22
+ end
23
+
24
+ def parse
25
+ puts "DEBUG BURATINO::CONFIGURE::PARSE"
26
+ OptionParser.new do |opt|
27
+ opt.separator ""
28
+ opt.separator "Usage: buratino [--angel] -p <puppet repostory> -r <reports repository> -m <mode> -i <interval>"
29
+ opt.separator ""
30
+ opt.separator "Options:"
31
+ opt.separator "-------------"
32
+ opt.on('-p', '--puppet PUPPET-REPOS', 'Puppet repository') { |val| @options['puppet'] = val }
33
+ opt.on('-a', '--angel', 'Angel mode - no-daemonize') { @options['angel'] = true }
34
+ opt.on('-r', '--reports REPORTS-REPOS', 'Reports repository') { |val| @options['reports'] = val }
35
+ opt.on('-m', '--mode MODE', 'Mode: clone|update') { |val| @options['mode'] = val }
36
+ opt.on('-i', '--interval', 'Interval in seconds') { |val| @options['interval'] = val }
37
+ opt.separator ""
38
+ opt.separator "All options can be set in config file"
39
+ opt.on_tail('-h', '--help') { puts opt; exit }
40
+
41
+ opt.parse!
42
+ end
43
+
44
+ self.options
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,45 @@
1
+ require "fileutils"
2
+ require "facter"
3
+
4
+ module Buratino
5
+
6
+ module Dirs
7
+
8
+ def self.check(config)
9
+ puts "DEBUG BURATINO::DIRS::CHECK"
10
+ self.clean(config)
11
+ @hostname = Facter.fqdn
12
+ Buratino::Hg.reports_dir(config)
13
+ Dir.mkdir("#{config['reports_dir']}/#{@hostname}") until File.exist? "#{config['reports_dir']}/#{@hostname}"
14
+
15
+ end
16
+
17
+ def self.reports(config)
18
+ puts "DEBUG BURATINO::DIRS::REPORTS"
19
+ reports = ["last_run_report.yaml", "last_run_summary.yaml", "state.yaml"]
20
+ reports.each do |report|
21
+ FileUtils.cp("/var/lib/puppet/state/#{report}", "#{config['reports_dir']}/#{@hostname}")
22
+ end
23
+
24
+ File.open("#{config['reports_dir']}/#{@hostname}/facts.yaml", 'w') do |file|
25
+ file.write(Facter.to_hash.to_yaml)
26
+ end
27
+
28
+ Buratino::Hg.send_reports(config)
29
+ end
30
+
31
+ def self.clean(config)
32
+ puts "DEBUG BURATINO::DIRS::CLEAN"
33
+ case config['mode']
34
+ when 'clone'
35
+ FileUtils.rm_r(config['destination'], :force => true) while File.exist? config['destination']
36
+ FileUtils.rm_r(config['reports_dir'], :force => true) while File.exist? config['reports_dir']
37
+
38
+ when 'update'
39
+ puts "No cleans in update mode"
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,58 @@
1
+ require "mercurial-ruby"
2
+ require "facter"
3
+
4
+ module Buratino
5
+ module Hg
6
+
7
+ def self.process(config)
8
+ puts "DEBUG BURATINO::HG::PROCESS"
9
+ @cmd_options = {}
10
+
11
+ case config['mode']
12
+ when 'clone'
13
+ Mercurial::Repository.clone( config['puppet'] , config['destination'], @cmd_options)
14
+ when 'update'
15
+ puppet_repos = Mercurial::Repository.open( config['destination'] )
16
+ puppet_repos.pull( 'default', '--update')
17
+
18
+ else
19
+ puts "Wrong mode!!!"
20
+
21
+ end
22
+
23
+ # In future:
24
+ # puppet = Pupapi.new <- Puppet Api
25
+ # puppet.apply( :module_path => '#{@destination}/modules', :debug => true, :verbose => true, :manifest => '#{@destination}/manifests/site.pp')
26
+
27
+ # Ugly(((
28
+ puts "DEBUG BURATINO::HG::PUPPET_APPLY"
29
+ puppet = `#{Gem.bindir}/puppet apply --modulepath=#{config['destination']}/modules #{config['destination']}/manifests/site.pp`
30
+ end
31
+
32
+ def self.reports_dir(config)
33
+ puts "DEBUG BURATINO::HG::REPORTS_DIR"
34
+ @cmd_options = {}
35
+
36
+ case config['mode']
37
+ when 'clone'
38
+ Mercurial::Repository.clone( config['reports'] , config['reports_dir'], @cmd_options)
39
+ when 'update'
40
+ reports_repos = Mercurial::Repository.open( config['reports_dir'] )
41
+ reports_repos.pull( 'default', '--update')
42
+
43
+ else
44
+ puts "Wrong mode!!!"
45
+
46
+ end
47
+ end
48
+
49
+ def self.send_reports(config)
50
+ puts "DEBUG BURATINO::HG::SEND_REPORTS"
51
+ message = "New report from #{Facter.fqdn}"
52
+ Mercurial::Shell.run("add", :append_hg => true, :in => config['reports_dir'])
53
+ Mercurial::Shell.run(["commit -m ?", message], :append_hg => true, :in => config['reports_dir'])
54
+ Mercurial::Shell.run("push", :append_hg => true, :in => config['reports_dir'])
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module Buratino
2
+ VERSION = "0.0.1"
3
+ end
data/lib/buratino.rb ADDED
@@ -0,0 +1,29 @@
1
+ #require "rubygems"
2
+ require "buratino/version"
3
+ require 'buratino/configure'
4
+ require 'buratino/dirs'
5
+ require 'buratino/hg'
6
+
7
+ module Buratino
8
+ module Runner
9
+
10
+ def self.run
11
+ puts "DEBUG BURATINO::RUNNER::RUN"
12
+
13
+ @config = Buratino::Configure.new.parse
14
+
15
+ while true do
16
+ puts "DEBUG BURATINO::RUNNER::RUN::NEW_ITERATION"
17
+ Buratino::Dirs.check(@config)
18
+ Buratino::Hg.process(@config)
19
+ Buratino::Dirs.reports(@config)
20
+ puts "DEBUG BURATINO::RUNNER::RUN::END_ITERATION"
21
+ break if @config['angel']
22
+ sleep @config['interval'].to_i
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buratino
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - InViZz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mercurial-ruby
16
+ requirement: &2151841360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2151841360
25
+ - !ruby/object:Gem::Dependency
26
+ name: puppet
27
+ requirement: &2151840040 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2151840040
36
+ - !ruby/object:Gem::Dependency
37
+ name: facter
38
+ requirement: &2151838700 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2151838700
47
+ description: Write a gem description
48
+ email:
49
+ - morion.estariol@gmail.com
50
+ executables:
51
+ - buratino
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - LICENSE
57
+ - README.md
58
+ - buratino.gemspec
59
+ - lib/buratino.rb
60
+ - lib/buratino/version.rb
61
+ - lib/buratino/configure.rb
62
+ - lib/buratino/hg.rb
63
+ - lib/buratino/dirs.rb
64
+ - bin/buratino
65
+ homepage: https://github.com/InViZz/buratino
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.17
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Write a gem summary
89
+ test_files: []