knife-block 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.8.7
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in knife-block.gemspec
4
4
  gemspec
5
+ rake
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rake/testtask'
4
4
 
5
5
 
6
6
  desc "Run Unit Tests"
7
- Rake::TestTask.new("unit_tests") do |t|
7
+ Rake::TestTask.new("test") do |t|
8
8
  t.pattern = "test/unit/*_test.rb"
9
9
  t.verbose = true
10
10
  t.warning = true
@@ -5,148 +5,177 @@
5
5
  #
6
6
  # Copyright (c) Matthew Macdonald-Wallace / Green and Secure IT Limited 2012
7
7
  #
8
- module GreenAndSecure
9
- def check_block_setup
10
- if File.exists?(::Chef::Knife::chef_config_dir+"/knife.rb") then
11
- if !File.symlink?(::Chef::Knife::chef_config_dir+"/knife.rb") then
12
- puts "#{::Chef::Knife::chef_config_dir}/knife.rb is NOT a symlink."
13
- puts "Please copy the file to #{::Chef::Knife::chef_config_dir}/knife-<servername>.rb and re-run this command."
14
- exit 3
15
- end
16
- end
17
- end
18
- module_function :check_block_setup
19
8
 
20
- def printable_server(server_config)
21
- File.basename(server_config, ".rb").split('-')[1 .. -1].join('-')
9
+ # Monkey patch ::Chef::Knife to give us back the config file, cause there's
10
+ # no public method to actually use the lookup logic
11
+ class Chef
12
+ class Knife
13
+ def get_config_file
14
+ locate_config_file if not config[:config_file]
15
+ File.dirname(config[:config_file])
22
16
  end
23
- module_function :printable_server
17
+ end
18
+ end
24
19
 
25
- # Returns path to berkshelf
26
- def berkshelf_path
27
- @berkshelf_path ||= ENV['BERKSHELF_PATH'] || File.expand_path('~/.berkshelf')
20
+ module GreenAndSecure
21
+ @@knife = ::Chef::Knife.new
22
+ def chef_config_base
23
+ @@knife.get_config_file
24
+ end
25
+ module_function :chef_config_base
26
+
27
+ def check_block_setup
28
+ base = GreenAndSecure::chef_config_base
29
+ if File.exists?(base+"/knife.rb") then
30
+ if !File.symlink?(base+"/knife.rb") then
31
+ puts "#{base}/knife.rb is NOT a symlink."
32
+ puts "Please copy the file to #{base}/knife-<servername>.rb and re-run this command."
33
+ exit 3
34
+ end
28
35
  end
29
- module_function :berkshelf_path
36
+ end
37
+ module_function :check_block_setup
38
+
39
+ def printable_server(server_config)
40
+ File.basename(server_config, ".rb").split('-')[1 .. -1].join('-')
41
+ end
42
+ module_function :printable_server
43
+
44
+ # Returns path to berkshelf
45
+ def berkshelf_path
46
+ @berkshelf_path ||= ENV['BERKSHELF_PATH'] || File.expand_path('~/.berkshelf')
47
+ end
48
+ module_function :berkshelf_path
49
+
50
+ class Block < Chef::Knife
30
51
 
31
- class Block < Chef::Knife
32
52
  banner "knife block"
33
- def run
34
- GreenAndSecure::check_block_setup
35
- list = GreenAndSecure::BlockList.new
36
- if name_args.size == 1 and list.servers.include?(name_args[0])
37
- use = GreenAndSecure::BlockUse.new
38
- use.name_args = name_args
39
- use.run
40
- else
41
- puts 'Did you mean to run "knife block list" instead?'
42
- puts 'Running "knife block list" for you now'
43
- list.run
44
- end
45
- end
53
+
54
+ def run
55
+ GreenAndSecure::check_block_setup
56
+ list = GreenAndSecure::BlockList.new
57
+ if name_args.size == 1 and list.servers.include?(name_args[0])
58
+ use = GreenAndSecure::BlockUse.new
59
+ use.name_args = name_args
60
+ use.run
61
+ else
62
+ puts 'Did you mean to run "knife block list" instead?'
63
+ puts 'Running "knife block list" for you now'
64
+ list.run
65
+ end
46
66
  end
67
+ end
47
68
 
48
- class BlockList < Chef::Knife
69
+ class BlockList < Chef::Knife
49
70
 
50
- banner "knife block list"
71
+ banner "knife block list"
51
72
 
52
- @current_server = nil
53
- def current_server
54
- GreenAndSecure::check_block_setup
73
+ @current_server = nil
74
+ def current_server
75
+ GreenAndSecure::check_block_setup
55
76
 
56
- @current_server ||= if File.exists?(::Chef::Knife::chef_config_dir+"/knife.rb") then
57
- GreenAndSecure::printable_server(File.readlink(::Chef::Knife::chef_config_dir+"/knife.rb"))
58
- else
59
- nil
60
- end
61
- end
77
+ @current_server ||= if File.exists?(GreenAndSecure::chef_config_base+"/knife.rb") then
78
+ GreenAndSecure::printable_server(File.readlink(GreenAndSecure::chef_config_base+"/knife.rb"))
79
+ else
80
+ nil
81
+ end
82
+ end
62
83
 
63
- @servers = []
64
- def servers
65
- ## get the list of available environments by searching ~/.chef for knife.rb files
66
- @servers ||= Dir.glob(::Chef::Knife::chef_config_dir+"/knife-*.rb").sort.map do | fn |
67
- GreenAndSecure::printable_server(fn)
68
- end
69
- end
84
+ @servers = []
85
+ def servers
86
+ ## get the list of available environments by searching ~/.chef for knife.rb files
87
+ @servers ||= Dir.glob(GreenAndSecure::chef_config_base+"/knife-*.rb").sort.map do | fn |
88
+ GreenAndSecure::printable_server(fn)
89
+ end
90
+ end
70
91
 
71
- # list the available environments
72
- def run
73
- GreenAndSecure::check_block_setup
74
- puts "The available chef servers are:"
75
- servers.each do |server|
76
- if server == current_server then
77
- puts "\t* #{server} [ Currently Selected ]"
78
- else
79
- puts "\t* #{server}"
80
- end
81
- end
82
- end
92
+ # list the available environments
93
+ def run
94
+ GreenAndSecure::check_block_setup
95
+ puts "The available chef servers are:"
96
+ servers.each do |server|
97
+ if server == current_server then
98
+ puts "\t* #{server} [ Currently Selected ]"
99
+ else
100
+ puts "\t* #{server}"
101
+ end
102
+ end
83
103
  end
104
+ end
105
+
106
+ class BlockUse < Chef::Knife
107
+
108
+ banner "knife block use SERVERNAME"
109
+
110
+ def run
111
+ unless name_args.size == 1
112
+ puts "Please specify a server"
113
+ server_list = GreenAndSecure::BlockList.new
114
+ server_list.run
115
+ exit 1
116
+ end
117
+ list = GreenAndSecure::BlockList.new
118
+ new_server = name_args.first
84
119
 
85
- class BlockUse < Chef::Knife
86
-
87
- banner "knife block use SERVERNAME"
88
-
89
- def run
90
- unless name_args.size == 1
91
- puts "Please specify a server"
92
- server_list = GreenAndSecure::BlockList.new
93
- server_list.run
94
- exit 1
95
- end
96
- list = GreenAndSecure::BlockList.new
97
- new_server = name_args.first
98
- if File.exists?(::Chef::Knife::chef_config_dir+"/knife-#{new_server}.rb")
99
- if File.exists?(::Chef::Knife::chef_config_dir+"/knife.rb")
100
- File.unlink(::Chef::Knife::chef_config_dir+"/knife.rb")
120
+ base = GreenAndSecure::chef_config_base
121
+ if File.exists?(base+"/knife-#{new_server}.rb")
122
+ if File.exists?(base+"/knife.rb")
123
+ File.unlink(base+"/knife.rb")
124
+ end
125
+ File.symlink(base+"/knife-#{new_server}.rb",
126
+ base+"/knife.rb")
127
+ puts "The knife configuration has been updated to use #{new_server}"
128
+
129
+ # update berkshelf
130
+ berks = GreenAndSecure::berkshelf_path+"/config.json"
131
+ berks_new = GreenAndSecure::berkshelf_path+"/config-#{new_server}.json"
132
+ if File.exists?(berks_new)
133
+ if File.exists?(berks)
134
+ File.unlink(berks)
101
135
  end
102
- File.symlink(::Chef::Knife::chef_config_dir+"/knife-#{new_server}.rb",
103
- ::Chef::Knife::chef_config_dir+"/knife.rb")
104
- puts "The knife configuration has been updated to use #{new_server}"
105
-
106
- # update berkshelf
107
- berks = GreenAndSecure::berkshelf_path+"/config.json"
108
- berks_new = GreenAndSecure::berkshelf_path+"/config-#{new_server}.json"
109
- if File.exists?(berks_new)
110
- if File.exists?(berks)
111
- File.unlink(berks)
112
- end
113
- File.symlink(berks_new, berks)
136
+ File.symlink(berks_new, berks)
114
137
  puts "The berkshelf configuration has been updated to use #{new_server}"
115
138
  else
116
139
  puts "Berkshelf configuration for #{new_server} not found"
117
140
  end
118
- else
141
+ else
119
142
  puts "Knife configuration for #{new_server} not found, aborting switch"
120
- end
121
- end
143
+ end
122
144
  end
145
+ end
146
+
147
+ class BlockNew < Chef::Knife
123
148
 
124
- class BlockNew < Chef::Knife
125
- banner "knife block new SERVERNAME"
126
- def run
127
- puts "This will create a new knife configuration file for you to use with knife-block"
128
- unless name_args.size == 1
129
- @config_name = ui.ask_question("Please provide a friendly name for the new configuration file: ")
130
- else
131
- @config_name = name_args.first
132
- end
133
-
134
- @chef_server = ui.ask_question("Please enter the url to your Chef Server: ")
135
- @client_name = ui.ask_question("Please enter the name of the Chef client: ")
136
- require 'ohai'
137
- require 'chef/knife/configure'
138
- GreenAndSecure::check_block_setup
139
- knife_config = Chef::Knife::Configure.new
140
- knife_config.config[:config_file] = "#{::Chef::Knife::chef_config_dir}/knife-#{@config_name}.rb"
141
- knife_config.config[:chef_server_url] = @chef_server
142
- knife_config.config[:node_name] = @client_name
143
- knife_config.config[:client_key] = "#{::Chef::Knife::chef_config_dir}/#{@client_name}-#{@config_name}.pem"
144
- knife_config.run
145
- puts "#{::Chef::Knife::chef_config_dir}/knife-#{@config_name}.rb has been sucessfully created"
146
- GreenAndSecure::BlockList.new.run
147
- use = GreenAndSecure::BlockUse.new
148
- use.name_args = [ @config_name ]
149
- use.run
150
- end
149
+ banner "knife block new SERVERNAME"
150
+
151
+ def run
152
+ puts "This will create a new knife configuration file for you to use with knife-block"
153
+ unless name_args.size == 1
154
+ @config_name = ui.ask_question("Please provide a friendly name for the new configuration file: ")
155
+ else
156
+ @config_name = name_args.first
157
+ end
158
+
159
+ @chef_server = ui.ask_question("Please enter the url to your Chef Server: ")
160
+ @client_name = ui.ask_question("Please enter the name of the Chef client: ")
161
+
162
+ require 'ohai'
163
+ require 'chef/knife/configure'
164
+
165
+ GreenAndSecure::check_block_setup
166
+ knife_config = Chef::Knife::Configure.new
167
+ knife_config.config[:config_file] = "#{GreenAndSecure::chef_config_base}/knife-#{@config_name}.rb"
168
+ knife_config.config[:chef_server_url] = @chef_server
169
+ knife_config.config[:node_name] = @client_name
170
+ knife_config.config[:client_key] = "#{GreenAndSecure::chef_config_base}/#{@client_name}-#{@config_name}.pem"
171
+ knife_config.run
172
+
173
+ puts "#{GreenAndSecure::chef_config_base}/knife-#{@config_name}.rb has been sucessfully created"
174
+ GreenAndSecure::BlockList.new.run
175
+ use = GreenAndSecure::BlockUse.new
176
+ use.name_args = [ @config_name ]
177
+ use.run
151
178
  end
179
+ end
152
180
  end
181
+
@@ -1,5 +1,5 @@
1
1
  module Knife
2
2
  module Block
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-block
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
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: 2013-07-30 00:00:00.000000000 Z
12
+ date: 2013-09-20 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Create and manage knife.rb files for OpsCodes' Chef
15
15
  email:
@@ -19,6 +19,7 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - .gitignore
22
+ - .travis.yml
22
23
  - Gemfile
23
24
  - LICENSE
24
25
  - README.md
@@ -27,7 +28,6 @@ files:
27
28
  - lib/chef/knife/block.rb
28
29
  - lib/knife-block.rb
29
30
  - lib/knife-block/version.rb
30
- - libpeerconnection.log
31
31
  - test/unit/knifeblock_test.rb
32
32
  homepage: ''
33
33
  licenses: []
File without changes