classify_cluster 0.4.10 → 0.4.11

Sign up to get free protection for your applications and to get access to all the features.
data/bin/classify CHANGED
@@ -1,36 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "classify_cluster"
4
- require "classify_cluster/version"
5
- require "commander/import"
3
+ require 'rubygems'
4
+ require 'thor'
5
+ require File.join(File.dirname(__FILE__), '..', 'lib', "classify_cluster")
6
6
  require 'yaml'
7
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)
8
+ class Classify < Thor
9
+ default_task :puppet
10
+
11
+ desc 'puppet CLUSTER_NAME', 'Generates configurations for different aspects of the cluster based off of one configuration.'
12
+ method_option :config, :desc => 'Location to config file', :type => :string, :default => ClassifyCluster::Base.default_config_file
13
+ method_option :export, :desc => 'Location to output puppet cluster config', :type => :string, :default => ENV['HOME']
14
+ def puppet(cluster_name=nil)
15
+ ClassifyCluster::Writers::Puppet.export!(options.export, :cluster => cluster_name, :config_file => options.config)
21
16
  say("Success!")
22
17
  end
23
18
  end
24
19
 
25
- command :config do |c|
26
- c.syntax = 'classify config <clustername> [options]'
27
- c.description = 'Runs an interactive script to generate a cluster configuration'
28
- c.option '--export STRING', String, 'Location to output cluster configuration'
29
- c.option '--cluster STRING', String, 'Cluster being created'
30
- c.option '--defaults STRING', String, 'Location to load cluster defaults'
31
- c.option '--variables STRING', String, 'Location to load cluster variables'
32
- c.action do |args, options|
33
- options.default :export => ClassifyCluster::Base.default_config_file, :defaults => '', :variables => ''
34
- ClassifyCluster::Writers::Classify.export!(ClassifyCluster::Readers::Cli.start!(options.cluster, options.defaults, options.variables))
35
- end
36
- end
20
+ Classify.start(ARGV, :shell => Thor::Shell::Basic.new)
@@ -11,9 +11,9 @@ Gem::Specification.new do |s|
11
11
  s.homepage = "http://rubygems.org/gems/classify_cluster"
12
12
  s.summary = %q{Contains several binaries for generating capistrano and puppet configurations}
13
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<highline>, [">= 1.5.0"])
16
- s.add_dependency(%q<activesupport>, [">= 2.3.5"])
14
+ s.add_dependency(%q<thor>, ["~> 0.14.6"])
15
+ s.add_dependency(%q<i18n>, [">= 0"])
16
+ s.add_dependency(%q<activesupport>, [">= 3.0.0"])
17
17
 
18
18
  s.rubyforge_project = "classify_cluster"
19
19
 
@@ -1 +0,0 @@
1
- require 'classify_cluster/readers/cli'
@@ -1,3 +1,3 @@
1
1
  module ClassifyCluster
2
- VERSION = "0.4.10"
2
+ VERSION = "0.4.11"
3
3
  end
@@ -1,3 +1,2 @@
1
1
  require 'classify_cluster/writers/capistrano'
2
- require 'classify_cluster/writers/puppet'
3
- require 'classify_cluster/writers/classify'
2
+ require 'classify_cluster/writers/puppet'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classify_cluster
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 10
10
- version: 0.4.10
9
+ - 11
10
+ version: 0.4.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sean Cashin
@@ -19,23 +19,23 @@ date: 2011-12-08 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: commander
22
+ name: thor
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: 57
29
+ hash: 43
30
30
  segments:
31
- - 4
32
31
  - 0
33
- - 3
34
- version: 4.0.3
32
+ - 14
33
+ - 6
34
+ version: 0.14.6
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
38
- name: highline
38
+ name: i18n
39
39
  prerelease: false
40
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
41
  none: false
@@ -44,10 +44,8 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  hash: 3
46
46
  segments:
47
- - 1
48
- - 5
49
47
  - 0
50
- version: 1.5.0
48
+ version: "0"
51
49
  type: :runtime
52
50
  version_requirements: *id002
53
51
  - !ruby/object:Gem::Dependency
@@ -58,12 +56,12 @@ dependencies:
58
56
  requirements:
59
57
  - - ">="
60
58
  - !ruby/object:Gem::Version
61
- hash: 9
59
+ hash: 7
62
60
  segments:
63
- - 2
64
61
  - 3
65
- - 5
66
- version: 2.3.5
62
+ - 0
63
+ - 0
64
+ version: 3.0.0
67
65
  type: :runtime
68
66
  version_requirements: *id003
69
67
  description: Reading from a YAML file will allow for consistent configuration between capistrano and puppet
@@ -95,11 +93,9 @@ files:
95
93
  - lib/classify_cluster/configurator/resource.rb
96
94
  - lib/classify_cluster/configurator/role.rb
97
95
  - lib/classify_cluster/readers.rb
98
- - lib/classify_cluster/readers/cli.rb
99
96
  - lib/classify_cluster/version.rb
100
97
  - lib/classify_cluster/writers.rb
101
98
  - lib/classify_cluster/writers/capistrano.rb
102
- - lib/classify_cluster/writers/classify.rb
103
99
  - lib/classify_cluster/writers/puppet.rb
104
100
  has_rdoc: true
105
101
  homepage: http://rubygems.org/gems/classify_cluster
@@ -1,114 +0,0 @@
1
- require 'highline/import'
2
-
3
- module ClassifyCluster
4
- module Readers
5
- class Cli
6
- def self.start!(cluster_name, defaults_path='', variables_path='')
7
- say("Welcome to classify cluster cli configurator!")
8
-
9
- defaults={}
10
- variables={}
11
- File.open(defaults_path, 'r') do |file|
12
- defaults = eval(file.read)
13
- end if File.exists?(defaults_path)
14
-
15
- File.open(variables_path, 'r') do |file|
16
- variables = eval(file.read)
17
- end if File.exists?(variables_path)
18
- say "Configure cluster wide"
19
- cluster_config = gather_cluster_info(cluster_name, defaults, variables)
20
- say "Configure nodes"
21
- nodes = []
22
- ask("How many nodes: ", Integer).times do |i|
23
- gather_node_info!(cluster_config)
24
- end
25
- puts cluster_config.inspect
26
- cluster_config
27
- end
28
-
29
- def self.gather_value(key, value, indent=0)
30
- case value
31
- when Array
32
- answers = []
33
- ask("#{"\t"*indent}How many #{key.to_s}: ", Integer).times do |i|
34
- answers << gather_value(key, value.first, 1)
35
- say "Configured #{i+1} #{key.to_s}"
36
- end
37
- answers
38
- when Hash
39
- ask("#{"\t"*indent}<%= @key %>: ", lambda {|ans| ans =~ /^\{\s*['|:].+$/ ? eval(ans) : ans}) do |q|
40
- q.gather = value
41
- end
42
- when Integer
43
- ask("#{"\t"*indent}#{key.to_s}: ", Integer)
44
- else
45
- ask("#{"\t"*indent}#{key.to_s}: ")
46
- end
47
- end
48
-
49
- def self.gather_node_info!(cluster_config)
50
- hostname = ask("Hostname: ")
51
- ip = ask("Ip: ")
52
- role_names = ClassifyCluster::Configurator::ROLES.map { |k| k.is_a?(Hash) ? k.keys.first : k }
53
-
54
- cluster_config.node(hostname, ip) do |node|
55
- more_roles = true
56
- while more_roles
57
- types = {}
58
- role_name = ask("Role [#{role_names.join(', ')}]: ", role_names)
59
- if ClassifyCluster::Configurator::ROLES.reject { |k| !k.is_a?(Hash) }.map(&:keys).flatten.include?(role_name)
60
- possible_types = ClassifyCluster::Configurator::ROLES.reject { |k| !k.is_a?(Hash) || !k.has_key?(role_name)}[0][role_name]
61
- more_types = true
62
- while more_types
63
- type = ask("Type [#{possible_types.join(', ')}]: ", possible_types)
64
- possible_types -= [type]
65
- types[type] = true
66
- more_types = possible_types.size > 0 && agree("More types? ")
67
- end
68
- end
69
- node.role role_name.to_sym, types do |role|
70
- while agree("Role variables?")
71
- name = ask("name: ")
72
- value = ask("value: ")
73
- role.variable name, value
74
- end
75
- end
76
- role_names -= [role_name]
77
- more_roles = role_names.size > 0 && agree("More roles? ")
78
- end
79
- end
80
- end
81
-
82
- def self.gather_cluster_info(cluster_name, defaults={}, variables={})
83
- cluster_name = ask("Cluster Name (no spaces): ") do |q|
84
- q.validate = /^\w.*/
85
- end unless cluster_name
86
-
87
- ClassifyCluster::Configurator::Cluster.new(cluster_name) do |cluster_config|
88
- file_path = ask("Ssl pem path: ") do |q|
89
- q.validate{ |a| File.exists?(a) }
90
- q.default = ClassifyCluster::Configurator::Cluster::SSLPEM_FILEPATH
91
- end
92
- module_name = ask("Puppet module to move it to: ") do |q|
93
- q.default = ClassifyCluster::Configurator::Cluster::SSLPEM_MODULE
94
- end
95
- cluster_config.ssl_pem(file_path, module_name)
96
-
97
- defaults.each_pair do |key, value|
98
- cluster_config.variable key, value
99
- end
100
- variables.each_pair do |key, value|
101
- cluster_config.variable key, gather_value(key, value)
102
- end
103
-
104
- klasses = ask("Classes: (q to stop)") do |q|
105
- q.gather = 'q'
106
- end
107
- klasses.delete_if {|klass| klass.nil? || klass.empty?}.each do |klass|
108
- cluster_config.klass klass
109
- end
110
- end
111
- end
112
- end
113
- end
114
- end
@@ -1,25 +0,0 @@
1
- module ClassifyCluster
2
- module Writers
3
- class Classify
4
- def self.export!(classify_configurator)
5
- File.open('/etc/cluster.rb', 'w') do |file|
6
- output file, "# Autogenerated on #{Time.now.to_s}"
7
- output file, "cluster :\"#{classify_configurator.name}\" do |cluster|"
8
-
9
- classify_configurator.classes.each do |klass|
10
- output file, "cluster.klass #{klass.inspect}", 1
11
- end
12
- classify_configurator.variables.each_pair do |key, variable|
13
- output file, "cluster.variable #{key.inspect}, #{variable.inspect}", 1
14
- end
15
-
16
- output file, "end"
17
- end
18
- end
19
-
20
- def self.output(file, str, indent=0)
21
- file.write("#{"\s"*(indent*4)}#{str}\n")
22
- end
23
- end
24
- end
25
- end