classify_cluster 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/README +5 -0
- data/Rakefile +2 -0
- data/bin/classify +23 -0
- data/classify_cluster.gemspec +23 -0
- data/lib/classify_cluster/base.rb +7 -0
- data/lib/classify_cluster/configurator.rb +103 -0
- data/lib/classify_cluster/version.rb +3 -0
- data/lib/classify_cluster/writers/capistrano.rb +16 -0
- data/lib/classify_cluster/writers/puppet.rb +39 -0
- data/lib/classify_cluster/writers.rb +2 -0
- data/lib/classify_cluster.rb +5 -0
- metadata +111 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README
ADDED
data/Rakefile
ADDED
data/bin/classify
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "classify_cluster"
|
4
|
+
require "classify_cluster/version"
|
5
|
+
require "commander/import"
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
program :name, "Classify Cluster"
|
9
|
+
program :version, ClassifyCluster::VERSION
|
10
|
+
program :description, 'Generates configurations for different aspects of the cluster based off of one configuration.'
|
11
|
+
default_command :puppet
|
12
|
+
|
13
|
+
command :puppet do |c|
|
14
|
+
c.syntax = 'classify puppet <clustername> [options]'
|
15
|
+
c.description = 'Returns on STDOUT YAML dump of the clusters puppet config'
|
16
|
+
c.option '--config STRING', String, 'Location to config file.'
|
17
|
+
c.option '--export STRING', String, 'Location to output puppet cluster config'
|
18
|
+
c.action do |args, options|
|
19
|
+
options.default :config => ClassifyCluster::Base.default_config_file, :export => ENV['HOME']
|
20
|
+
ClassifyCluster::Writers::Puppet.export!(options.export, :cluster => args[0], :config_file => options.config)
|
21
|
+
say("Success!")
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "classify_cluster/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "classify_cluster"
|
7
|
+
s.version = ClassifyCluster::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Sean Cashin"]
|
10
|
+
s.email = ["sean@socialcast.com"]
|
11
|
+
s.homepage = "http://rubygems.org/gems/classify_cluster"
|
12
|
+
s.summary = %q{Contains several binaries for generating capistrano and puppet configurations}
|
13
|
+
s.description = %q{Reading from a YAML file will allow for consistent configuration between capistrano and puppet}
|
14
|
+
s.add_dependency(%q<commander>, ["= 4.0.3"])
|
15
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.5"])
|
16
|
+
|
17
|
+
s.rubyforge_project = "classify_cluster"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module ClassifyCluster
|
2
|
+
module Configurator
|
3
|
+
class Configuration
|
4
|
+
attr_reader :clusters
|
5
|
+
def initialize(config_path)
|
6
|
+
@clusters = {}
|
7
|
+
eval File.open(config_path).read
|
8
|
+
end
|
9
|
+
|
10
|
+
def cluster(cluster_name, &block)
|
11
|
+
@clusters[cluster_name] = ClassifyCluster::Configurator::Cluster.new(cluster_name, &block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
class Cluster
|
15
|
+
attr_reader :nodes, :name
|
16
|
+
def initialize(*args, &block)
|
17
|
+
@nodes = {}
|
18
|
+
@name = args.first
|
19
|
+
block.call self
|
20
|
+
end
|
21
|
+
def name(value=nil)
|
22
|
+
return @name unless value
|
23
|
+
@name = value
|
24
|
+
end
|
25
|
+
def node(node_name, &block)
|
26
|
+
@nodes[node_name] = ClassifyCluster::Configurator::Node.new(node_name, &block)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
class Node
|
30
|
+
attr_reader :fqdn, :variables, :resources, :classes, :public_ip, :private_ip, :roles, :default
|
31
|
+
def initialize(*args, &block)
|
32
|
+
@variables = {}
|
33
|
+
@resources = []
|
34
|
+
@classes = []
|
35
|
+
@roles = []
|
36
|
+
@fqdn = (args.first.to_s == 'default' ? '' : args.first)
|
37
|
+
@default = args.first.to_s == 'default'
|
38
|
+
block.call self
|
39
|
+
end
|
40
|
+
def default?
|
41
|
+
return @default
|
42
|
+
end
|
43
|
+
def fqdn(value=nil)
|
44
|
+
return @fqdn unless value
|
45
|
+
@fqdn = value
|
46
|
+
end
|
47
|
+
def public_ip(value = nil)
|
48
|
+
return @public_ip unless value
|
49
|
+
@public_ip = value
|
50
|
+
end
|
51
|
+
def private_ip(value = nil)
|
52
|
+
return @private_ip unless value
|
53
|
+
@private_ip = value
|
54
|
+
end
|
55
|
+
def role(&block)
|
56
|
+
@roles << ClassifyCluster::Configurator::Role.new(&block)
|
57
|
+
end
|
58
|
+
def variable(name, value)
|
59
|
+
@variables[name] = value
|
60
|
+
end
|
61
|
+
def resource(&block)
|
62
|
+
@resources << ClassifyCluster::Configurator::Resource.new(&block)
|
63
|
+
end
|
64
|
+
def klass(name)
|
65
|
+
@classes << name
|
66
|
+
end
|
67
|
+
end
|
68
|
+
class Resource
|
69
|
+
attr_reader :type, :name, :options
|
70
|
+
def initialize(*args, &block)
|
71
|
+
@options = {}
|
72
|
+
block.call self
|
73
|
+
end
|
74
|
+
def type(value = nil)
|
75
|
+
return @type unless value
|
76
|
+
@type = value
|
77
|
+
end
|
78
|
+
def name(value = nil)
|
79
|
+
return @name unless value
|
80
|
+
@name = value
|
81
|
+
end
|
82
|
+
def options(value = nil)
|
83
|
+
return @options unless value
|
84
|
+
@options = value
|
85
|
+
end
|
86
|
+
end
|
87
|
+
class Role
|
88
|
+
attr_reader :type, :options
|
89
|
+
def initialize(*args, &block)
|
90
|
+
@options = {}
|
91
|
+
block.call self
|
92
|
+
end
|
93
|
+
def type(value = nil)
|
94
|
+
return @type unless value
|
95
|
+
@type = value
|
96
|
+
end
|
97
|
+
def options(value = nil)
|
98
|
+
return @options unless value
|
99
|
+
@options = value
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ClassifyCluster
|
2
|
+
module Writers
|
3
|
+
class Capistrano
|
4
|
+
def self.export!(capistrano_configurator, cluster, config_file=ClassifyCluster::Base.default_config_file)
|
5
|
+
config = ClassifyCluster::Configurator::Configuration.new(config_file).clusters[cluster]
|
6
|
+
config.nodes.each_pair do |name, node|
|
7
|
+
roles = node.roles
|
8
|
+
next if roles.empty?
|
9
|
+
roles.each do |role|
|
10
|
+
capistrano_configurator.role(role.type, node.public_ip, role.options)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module ClassifyCluster
|
2
|
+
module Writers
|
3
|
+
class Puppet
|
4
|
+
def self.export!(export_to_folder, options={})
|
5
|
+
options.reverse_merge! :config_file => ClassifyCluster::Base.default_config_file
|
6
|
+
config = ClassifyCluster::Configurator::Configuration.new(options[:config_file])
|
7
|
+
config.clusters.each_pair do |name, cluster|
|
8
|
+
next if options[:cluster] && !(options[:cluster] == cluster.name.to_s)
|
9
|
+
File.open(File.join(export_to_folder, "#{cluster.name}.pp"), 'w') do |file|
|
10
|
+
cluster.nodes.each_pair do |fqdn, node|
|
11
|
+
file.write(output(%Q%node "#{node.default? ? 'default' : node.fqdn}" {%))
|
12
|
+
node.variables.each_pair do |key, value|
|
13
|
+
file.write(output("$#{key}=#{value.inspect}", :indent => 1))
|
14
|
+
end
|
15
|
+
node.resources.each do |resource|
|
16
|
+
file.write(output("#{resource.type} { #{resource.name.inspect}:", :indent => 1))
|
17
|
+
count = 0
|
18
|
+
resource.options.each_pair do |key, value|
|
19
|
+
file.write(output("#{key} => #{value.inspect}#{"," if count >= resource.options.size}", :indent => 2))
|
20
|
+
count += 1
|
21
|
+
end
|
22
|
+
file.write(output("}", :indent => 1))
|
23
|
+
end
|
24
|
+
node.classes.each do |klass|
|
25
|
+
file.write(output("include #{klass}", :indent => 1))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
file.write(output("}"))
|
29
|
+
end
|
30
|
+
end; nil
|
31
|
+
end
|
32
|
+
private
|
33
|
+
def self.output(string, options={})
|
34
|
+
options.reverse_merge! :indent => 0
|
35
|
+
%Q%#{("\s" * 2) * options[:indent]}#{string}\n%
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: classify_cluster
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Sean Cashin
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-22 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: commander
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 57
|
30
|
+
segments:
|
31
|
+
- 4
|
32
|
+
- 0
|
33
|
+
- 3
|
34
|
+
version: 4.0.3
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: activesupport
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 9
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 3
|
49
|
+
- 5
|
50
|
+
version: 2.3.5
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
description: Reading from a YAML file will allow for consistent configuration between capistrano and puppet
|
54
|
+
email:
|
55
|
+
- sean@socialcast.com
|
56
|
+
executables:
|
57
|
+
- classify
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files: []
|
61
|
+
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- README
|
66
|
+
- Rakefile
|
67
|
+
- bin/classify
|
68
|
+
- classify_cluster.gemspec
|
69
|
+
- lib/classify_cluster.rb
|
70
|
+
- lib/classify_cluster/base.rb
|
71
|
+
- lib/classify_cluster/configurator.rb
|
72
|
+
- lib/classify_cluster/version.rb
|
73
|
+
- lib/classify_cluster/writers.rb
|
74
|
+
- lib/classify_cluster/writers/capistrano.rb
|
75
|
+
- lib/classify_cluster/writers/puppet.rb
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: http://rubygems.org/gems/classify_cluster
|
78
|
+
licenses: []
|
79
|
+
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
requirements: []
|
104
|
+
|
105
|
+
rubyforge_project: classify_cluster
|
106
|
+
rubygems_version: 1.3.7
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: Contains several binaries for generating capistrano and puppet configurations
|
110
|
+
test_files: []
|
111
|
+
|