knife-block 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,7 +6,7 @@ The knife block plugin has been created to enable the use of multiple knife.rb f
6
6
 
7
7
  The premise is that you have a "block" in which you store all your "knives" and you can choose the one best suited to the task.
8
8
 
9
- ## Requirements
9
+ ## Requirements
10
10
 
11
11
  At present, knife-block requires ruby 1.9.2 or above. This is owing to the use of "Dir.home()" to find a user's home directory.
12
12
 
@@ -18,7 +18,7 @@ At present, knife-block requires ruby 1.9.2 or above. This is owing to the use
18
18
 
19
19
  Knife looks for knife.rb in ~/.chef - all this script does is create a symlink from the required configuration to knife.rb so that knife can act on the appropriate server.
20
20
 
21
- Create a knife-<service_name>.rb configuration file in your ~/.chef directory for each Chef server that you wish to connect to.
21
+ Create a knife-<service_name>.rb configuration file in your ~/.chef directory for each Chef server that you wish to connect to.
22
22
 
23
23
  **Please note - this script will check to see if knife.rb exists and whether it is a symlink or not.**
24
24
 
@@ -28,14 +28,14 @@ Create a knife-<service_name>.rb configuration file in your ~/.chef directory fo
28
28
  (This command will also tell you which server is currently selected)
29
29
 
30
30
  knife block list
31
-
31
+
32
32
  The available chef servers are:
33
33
  * local-testing [ Currently Selected ]
34
34
  * opscode-hosted-chef
35
35
 
36
36
  #### Change to a new server
37
37
  knife block use <server_name>
38
-
38
+
39
39
  You are asking to change from local-testing to opscode-hosted-chef. Are you sure? (Y/N) y
40
40
  The knife configuration has been updated to use opscode-hosted-chef
41
41
 
@@ -45,6 +45,9 @@ Create a knife-<service_name>.rb configuration file in your ~/.chef directory fo
45
45
  knife block new <friendlyname>
46
46
 
47
47
 
48
+ ### Berkshelf integration
49
+ Knife block supports Berkshelf, however, the berkshelf config files must be manually created and named "config-<block>.json" and put in the Berkshelf directory (typically ~/.berkshelf). In the future, these files could be automatically created by knife block.
50
+
48
51
 
49
52
  These knife plugins are supplied without any warranty or guarantees regarding suitability for purpose.
50
53
 
@@ -22,9 +22,16 @@ module GreenAndSecure
22
22
  end
23
23
  module_function :printable_server
24
24
 
25
+ # Returns path to berkshelf
26
+ def berkshelf_path
27
+ @berkshelf_path ||= ENV['BERKSHELF_PATH'] || File.expand_path('~/.berkshelf')
28
+ end
29
+ module_function :berkshelf_path
30
+
25
31
  class Block < Chef::Knife
26
32
  banner "knife block"
27
33
  def run
34
+ GreenAndSecure::check_block_setup
28
35
  list = GreenAndSecure::BlockList.new
29
36
  if name_args.size == 1 and list.servers.include?(name_args[0])
30
37
  use = GreenAndSecure::BlockUse.new
@@ -45,7 +52,7 @@ module GreenAndSecure
45
52
  @current_server = nil
46
53
  def current_server
47
54
  GreenAndSecure::check_block_setup
48
-
55
+
49
56
  @current_server ||= if File.exists?(::Chef::Knife::chef_config_dir+"/knife.rb") then
50
57
  GreenAndSecure::printable_server(File.readlink(::Chef::Knife::chef_config_dir+"/knife.rb"))
51
58
  else
@@ -63,6 +70,7 @@ module GreenAndSecure
63
70
 
64
71
  # list the available environments
65
72
  def run
73
+ GreenAndSecure::check_block_setup
66
74
  puts "The available chef servers are:"
67
75
  servers.each do |server|
68
76
  if server == current_server then
@@ -94,6 +102,19 @@ module GreenAndSecure
94
102
  File.symlink(::Chef::Knife::chef_config_dir+"/knife-#{new_server}.rb",
95
103
  ::Chef::Knife::chef_config_dir+"/knife.rb")
96
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)
114
+ puts "The berkshelf configuration has been updated to use #{new_server}"
115
+ else
116
+ puts "Berkshelf configuration for #{new_server} not found"
117
+ end
97
118
  else
98
119
  puts "Knife configuration for #{new_server} not found, aborting switch"
99
120
  end
@@ -111,12 +132,15 @@ module GreenAndSecure
111
132
  end
112
133
 
113
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: ")
114
136
  require 'ohai'
115
137
  require 'chef/knife/configure'
116
138
  GreenAndSecure::check_block_setup
117
139
  knife_config = Chef::Knife::Configure.new
118
140
  knife_config.config[:config_file] = "#{::Chef::Knife::chef_config_dir}/knife-#{@config_name}.rb"
119
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"
120
144
  knife_config.run
121
145
  puts "#{::Chef::Knife::chef_config_dir}/knife-#{@config_name}.rb has been sucessfully created"
122
146
  GreenAndSecure::BlockList.new.run
@@ -1,5 +1,5 @@
1
1
  module Knife
2
2
  module Block
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
File without changes
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.6
4
+ version: 0.0.7
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-03 00:00:00.000000000 Z
12
+ date: 2013-07-30 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Create and manage knife.rb files for OpsCodes' Chef
15
15
  email:
@@ -27,6 +27,7 @@ files:
27
27
  - lib/chef/knife/block.rb
28
28
  - lib/knife-block.rb
29
29
  - lib/knife-block/version.rb
30
+ - libpeerconnection.log
30
31
  - test/unit/knifeblock_test.rb
31
32
  homepage: ''
32
33
  licenses: []