knife-nodefu 0.0.11 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -10,11 +10,11 @@ A basic utility to help automate the creation and destruction of ec2 servers man
10
10
 
11
11
  gem install knife-nodefu
12
12
 
13
- = Definitions File
13
+ = Definitions File Directory
14
14
 
15
- This file provides all the proper definitions for nodefu to be able to easily build out servers. You can either pass in the definitions file with the -d option, or set the following option in your knife.rb file.
15
+ This file provides all the proper definitions for nodefu to be able to easily build out servers. You can either pass in the definitions file directory with the -d option, or set the following option in your knife.rb file.
16
16
 
17
- nodefu_definitions_file "Path to file"
17
+ nodefu_definitions "Path to directory"
18
18
 
19
19
  Example definitions yml file:
20
20
 
data/knife-nodefu.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.has_rdoc = true
9
9
  s.authors = ['Brian Bianco']
10
10
  s.email = ['brian.bianco@gmail.com']
11
- s.homepage = 'https://github.com/brianbianco/nodefu'
11
+ s.homepage = 'https://github.com/brianbianco/knife-nodefu'
12
12
  s.summary = 'A knife plugin for simple node creation automation'
13
13
  s.description = s.summary
14
14
  s.extra_rdoc_files = ['README.rdoc', 'LICENSE' ]
@@ -30,9 +30,9 @@ class NodefuCreate < Chef::Knife
30
30
  :default => nil
31
31
 
32
32
  option :definitions_file,
33
- :short => "-d <definitions_file_path>",
34
- :long => "--definitions_file <definitions_file_path>",
35
- :description => "yml definitions file",
33
+ :short => "-d <definitions_directory>",
34
+ :long => "--definitions_dir <definitions_directory>",
35
+ :description => "yml definitions directory",
36
36
  :default => nil
37
37
 
38
38
  option :exit_on_fail,
@@ -60,26 +60,36 @@ class NodefuCreate < Chef::Knife
60
60
  ec2_delete.run
61
61
  end
62
62
 
63
+ def definitions_from_directory(dir)
64
+ definitions = Hash.new
65
+ Dir.entries(dir).each do |f|
66
+ if File.extname(f) == ".yml"
67
+ puts "loading #{f}"
68
+ loaded_defs = YAML.load_file(::File.join(dir,f))
69
+ definitions = Chef::Mixin::DeepMerge.merge(definitions,loaded_defs)
70
+ end
71
+ end
72
+ definitions
73
+ end
74
+
63
75
  def run
64
76
  check_args(1)
65
- env = Chef::Config[:environment]
66
- definitions_file = config[:definitions_file].nil? ? Chef::Config[:nodefu_definitions_file] : config[:definitions_file]
67
- yml_config = YAML.load_file definitions_file
68
-
69
- base_name, start_range, end_range = parse_servers(name_args[0])
70
-
71
- # Merge the current environment hash with the defaults
72
- merged_configuration = Chef::Mixin::DeepMerge.merge(yml_config['default'],yml_config['env'][env])
73
77
 
78
+ env = Chef::Config[:environment]
79
+ defs_dir = Chef::Config[:nodefu_definitions] || config[:definitionss]
80
+ yml_config = definitions_from_directory defs_dir
81
+ merged_config = Chef::Mixin::DeepMerge.merge(yml_config['default'],yml_config['env'][env])
74
82
  node_spec_name = config[:node_spec] || base_name
83
+ abort("I'm sorry I couldn't find any node_spec matches :(") unless (node_spec = merged_config['node_spec'][node_spec_name])
84
+
85
+ base_name, start_range, end_range = parse_servers(name_args[0])
75
86
 
76
- abort("I'm sorry I couldn't find any node_spec matches :(") unless (node_spec = merged_configuration['node_spec'][node_spec_name])
77
- domain = merged_configuration['domain']
87
+ domain = merged_config['domain']
78
88
  vm_spec_name = node_spec['vm_spec']
79
- vm_spec = merged_configuration['vm_spec'][vm_spec_name]
89
+ vm_spec = merged_config['vm_spec'][vm_spec_name]
80
90
  aux_groups = node_spec['aux_groups'].nil? ? '' : ",#{node_spec['aux_groups'].join(',')}"
81
91
 
82
- #Present the user with some totally rad visuals!!!
92
+ # Present the user with some totally rad visuals!!!
83
93
  ui.msg("#{ui.color('SHAZAM!',:red)} It looks like you want to launch #{ui.color((end_range - start_range + 1).to_s,:yellow)} of these:")
84
94
  ui.msg("#{ui.color('Base Name',:cyan)}: #{base_name}")
85
95
  ui.msg("#{ui.color('Node Spec',:cyan)}: #{node_spec_name}")
@@ -95,8 +105,8 @@ class NodefuCreate < Chef::Knife
95
105
  ec2_server_request = Ec2ServerCreate.new
96
106
  node_name = "#{base_name}#{i}"
97
107
  full_node_name = "#{base_name}#{i}.#{env}.#{domain}"
98
- #A handfull of the Ec2ServerCreate command line options use a :proc field so I have to
99
- #populate those by hand instead of simply passing a value to its config entry
108
+ # A handfull of the Ec2ServerCreate command line options use a :proc field so I have to
109
+ # populate those by hand instead of simply passing a value to its config entry
100
110
  Chef::Config[:knife][:aws_ssh_key_id] = vm_spec['ssh_key']
101
111
  Chef::Config[:knife][:image] = vm_spec['ami']
102
112
  Chef::Config[:knife][:region] = vm_spec['region']
@@ -119,7 +129,7 @@ class NodefuCreate < Chef::Knife
119
129
  end
120
130
  threads.each(&:join)
121
131
 
122
- #Build a servers hash with the node names as they key from the object returned by the threads
132
+ # Build a servers hash with the node names as the key from the object returned by the threads
123
133
  @servers = threads.inject({}) {|hash,t| hash[t.value[0]] = t.value[1]; hash}
124
134
 
125
135
  query = Chef::Search::Query.new
@@ -1,6 +1,6 @@
1
1
  module Knife
2
2
  module Nodefu
3
- VERSION = "0.0.11"
3
+ VERSION = "0.1.1"
4
4
  MAJOR, MINOR, TINY = VERSION.split(',')
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-nodefu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-23 00:00:00.000000000 Z
12
+ date: 2013-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: knife-ec2
@@ -59,7 +59,7 @@ files:
59
59
  - lib/chef/knife/nodefu_create.rb
60
60
  - lib/chef/knife/nodefu_destroy.rb
61
61
  - lib/knife-nodefu/version.rb
62
- homepage: https://github.com/brianbianco/nodefu
62
+ homepage: https://github.com/brianbianco/knife-nodefu
63
63
  licenses: []
64
64
  post_install_message:
65
65
  rdoc_options: []
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  requirements: []
81
81
  rubyforge_project:
82
- rubygems_version: 1.8.24
82
+ rubygems_version: 1.8.25
83
83
  signing_key:
84
84
  specification_version: 3
85
85
  summary: A knife plugin for simple node creation automation