knife-instance 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/chef/knife/instance_create.rb +13 -1
- data/lib/knife-instance/bootstrap_generator.rb +10 -7
- data/lib/knife-instance/templates/boot.sh.erb +2 -1
- data/lib/knife-instance/version.rb +1 -1
- data/spec/lib/chef/knife/instance_create_spec.rb +3 -2
- data/spec/lib/knife-instance/bootstrap_generator_spec.rb +98 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1108cde770487cd53011c74291711f9c593375c
|
4
|
+
data.tar.gz: 0e4e27fefd0221b81fdc722750dab95454922179
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfe6de0292f46449c9fea20bf894b494b30f8a6a8c78c92bc9c7f4da8805a8ee286327d925cc2388a7c34a1054fbd73836144f64b81ebc98d8f000100e6cec78
|
7
|
+
data.tar.gz: e3bc8be967811ab1ba9d81a07ea7b5d66897de5beb4be532bb4a2096afa11126079c026570b5852f8289b57dbca6287b9ed0b1a0aefa40060cc15df2f33ebc68
|
@@ -173,10 +173,15 @@ class Chef
|
|
173
173
|
:user_data => config[:without_user_data] ? "" : get_user_data,
|
174
174
|
:iam_instance_profile_name => config[:iam_role]
|
175
175
|
}
|
176
|
+
server_def[:associate_public_ip] = true if vpc_mode?
|
176
177
|
|
177
178
|
server_def
|
178
179
|
end
|
179
180
|
|
181
|
+
def vpc_mode?
|
182
|
+
config[:subnet_id]
|
183
|
+
end
|
184
|
+
|
180
185
|
def image
|
181
186
|
config[:image]
|
182
187
|
end
|
@@ -205,7 +210,14 @@ class Chef
|
|
205
210
|
end
|
206
211
|
|
207
212
|
def get_user_data
|
208
|
-
generator = Zest::BootstrapGenerator.new(Chef::Config[:validation_key], Chef::Config[:validation_client_name], Chef::Config[:chef_server_url],
|
213
|
+
generator = Zest::BootstrapGenerator.new(Chef::Config[:validation_key], Chef::Config[:validation_client_name], Chef::Config[:chef_server_url], config[:encrypted_data_bag_secret],
|
214
|
+
:environment => @environment,
|
215
|
+
:run_list => config[:run_list],
|
216
|
+
:hostname => hostname,
|
217
|
+
:color => @color,
|
218
|
+
:base_domain => @base_domain,
|
219
|
+
:domain => domain
|
220
|
+
)
|
209
221
|
generator.generate
|
210
222
|
end
|
211
223
|
end
|
@@ -3,16 +3,18 @@ module Zest
|
|
3
3
|
class BootstrapGenerator
|
4
4
|
CONFIG_FILE_TEMPLATE = File.expand_path 'templates/boot.sh.erb', File.dirname(__FILE__)
|
5
5
|
|
6
|
-
def initialize(validation_key_file, validation_client_name, chef_server_url,
|
6
|
+
def initialize(validation_key_file, validation_client_name, chef_server_url, encrypted_databag_secret_file, attr = {})
|
7
7
|
@validation_client_name = validation_client_name
|
8
8
|
@validation_key_file = validation_key_file
|
9
9
|
@chef_server_url = chef_server_url
|
10
|
-
@environment = environment
|
11
|
-
@run_list = run_list
|
12
|
-
@hostname = hostname
|
13
|
-
@color = color
|
14
|
-
@base_domain = base_domain
|
15
10
|
@encrypted_databag_secret_file = encrypted_databag_secret_file
|
11
|
+
|
12
|
+
@environment = attr[:environment]
|
13
|
+
@run_list = attr[:run_list]
|
14
|
+
@hostname = attr[:hostname]
|
15
|
+
@color = attr[:color]
|
16
|
+
@base_domain = attr[:base_domain]
|
17
|
+
@domain = attr[:domain]
|
16
18
|
end
|
17
19
|
|
18
20
|
def first_boot
|
@@ -20,7 +22,8 @@ module Zest
|
|
20
22
|
"run_list" => @run_list,
|
21
23
|
"assigned_hostname" => @hostname,
|
22
24
|
"rails" => {"cluster" => {"color" => @color}},
|
23
|
-
"base_domain" => @base_domain
|
25
|
+
"base_domain" => @base_domain,
|
26
|
+
"domain" => @domain
|
24
27
|
}.to_json
|
25
28
|
end
|
26
29
|
|
@@ -22,7 +22,8 @@ gem install chef --no-rdoc --no-ri --verbose --version 10.24.0
|
|
22
22
|
gem install tzinfo --no-rdoc --no-ri --verbose --version 0.3.33
|
23
23
|
gem install syslog-logger --no-rdoc --no-ri --verbose --version 1.6.8
|
24
24
|
|
25
|
-
mkdir -p /etc/chef
|
25
|
+
mkdir -p /etc/chef/ohai/hints
|
26
|
+
touch /etc/chef/ohai/hints/ec2.json # Tell ohai that it is an EC2 node in VPC
|
26
27
|
|
27
28
|
<%# Remember to suppress a newline at the end of an erb statement for keys --> -%>
|
28
29
|
|
@@ -102,8 +102,9 @@ describe Chef::Knife::InstanceCreate do
|
|
102
102
|
end
|
103
103
|
|
104
104
|
subject { @instance.create_server_def }
|
105
|
-
its([:security_group_ids])
|
106
|
-
its([:subnet_id])
|
105
|
+
its([:security_group_ids]) { should == security_group_ids }
|
106
|
+
its([:subnet_id]) { should == subnet_id }
|
107
|
+
its([:associate_public_ip]) { should == true }
|
107
108
|
end
|
108
109
|
end
|
109
110
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zest::BootstrapGenerator do
|
4
|
+
let(:bootstrap_generator) { described_class.new(validation_key_file, validation_client_name, chef_server_url, encrypted_databag_secret_file, attr) }
|
5
|
+
let(:validation_key_file) { "/path/to/validation_key" }
|
6
|
+
let(:validation_client_name) { "this is the validation client name" }
|
7
|
+
let(:chef_server_url) { "this is the url for the chef server" }
|
8
|
+
let(:encrypted_databag_secret_file) { "/path/to/encrypted_databag_secret_file" }
|
9
|
+
let(:attr) { {
|
10
|
+
:environment => environment,
|
11
|
+
:run_list => run_list,
|
12
|
+
:hostname => hostname,
|
13
|
+
:color => color,
|
14
|
+
:base_domain => base_domain,
|
15
|
+
:domain => domain
|
16
|
+
} }
|
17
|
+
let(:environment) { "this is an environment" }
|
18
|
+
let(:run_list) { "this is a run list" }
|
19
|
+
let(:hostname) { "this is a hostname" }
|
20
|
+
let(:color) { "this is a color" }
|
21
|
+
let(:base_domain) { "this is a base domain" }
|
22
|
+
let(:domain) { "this is a domain" }
|
23
|
+
|
24
|
+
describe "#first_boot" do
|
25
|
+
subject { JSON.parse(bootstrap_generator.first_boot) }
|
26
|
+
|
27
|
+
it "defines the run list" do
|
28
|
+
subject["run_list"].should == "this is a run list"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "assigns the hostname" do
|
32
|
+
subject["assigned_hostname"].should == "this is a hostname"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "contains the cluster color" do
|
36
|
+
subject["rails"]["cluster"]["color"].should == "this is a color"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "contains the base domain" do
|
40
|
+
subject["base_domain"].should == "this is a base domain"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "contains the domain" do
|
44
|
+
subject["domain"].should == "this is a domain"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#validation_key" do
|
49
|
+
subject { bootstrap_generator.validation_key }
|
50
|
+
|
51
|
+
before :each do
|
52
|
+
File.stub(:read).with(validation_key_file).and_return("this is a validation key")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns the contents of the validation key file" do
|
56
|
+
subject.should == "this is a validation key"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#encrypted_data_bag_secret" do
|
61
|
+
subject { bootstrap_generator.encrypted_data_bag_secret }
|
62
|
+
|
63
|
+
before :each do
|
64
|
+
File.stub(:read).with(encrypted_databag_secret_file).and_return("this is a encrypted data bag secret")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns the contents of the validation key file" do
|
68
|
+
subject.should == "this is a encrypted data bag secret"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#config_content" do
|
73
|
+
subject { bootstrap_generator.config_content }
|
74
|
+
|
75
|
+
it "generates the correct config" do
|
76
|
+
subject.should == <<-CONFIG
|
77
|
+
require 'syslog-logger'
|
78
|
+
Logger::Syslog.class_eval do
|
79
|
+
attr_accessor :sync, :formatter
|
80
|
+
end
|
81
|
+
|
82
|
+
log_level :info
|
83
|
+
log_location Logger::Syslog.new("chef-client")
|
84
|
+
chef_server_url "this is the url for the chef server"
|
85
|
+
validation_client_name "this is the validation client name"
|
86
|
+
node_name "this is a hostname"
|
87
|
+
CONFIG
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "#start_chef" do
|
92
|
+
subject { bootstrap_generator.start_chef }
|
93
|
+
|
94
|
+
it "generates the correct chef start command" do
|
95
|
+
subject.should == "/usr/bin/chef-client -j /etc/chef/first-boot.json -E this is an environment"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-instance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Tamoykin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chef
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/knife-instance/version.rb
|
105
105
|
- lib/knife-instance/zestknife.rb
|
106
106
|
- spec/lib/chef/knife/instance_create_spec.rb
|
107
|
+
- spec/lib/knife-instance/bootstrap_generator_spec.rb
|
107
108
|
- spec/lib/knife-instance/zestknife_spec.rb
|
108
109
|
- spec/spec_helper.rb
|
109
110
|
- spec/support/databag.key
|
@@ -133,6 +134,7 @@ specification_version: 4
|
|
133
134
|
summary: Manage EC2 instances with Chef from the command line
|
134
135
|
test_files:
|
135
136
|
- spec/lib/chef/knife/instance_create_spec.rb
|
137
|
+
- spec/lib/knife-instance/bootstrap_generator_spec.rb
|
136
138
|
- spec/lib/knife-instance/zestknife_spec.rb
|
137
139
|
- spec/spec_helper.rb
|
138
140
|
- spec/support/databag.key
|