knife-joyent 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -17,23 +17,15 @@ class Chef
|
|
17
17
|
|
18
18
|
banner 'knife joyent server create (options)'
|
19
19
|
|
20
|
+
option :server_name,
|
21
|
+
:short => "-S NAME",
|
22
|
+
:long => "--server-name <name>",
|
23
|
+
:description => "The Joyent server name"
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
def is_loopback(ip)
|
27
|
-
loopback = IPAddr.new "127.0.0.0/8"
|
28
|
-
return loopback.include?(ip)
|
29
|
-
end
|
30
|
-
|
31
|
-
def is_private(ip)
|
32
|
-
block_a = IPAddr.new "10.0.0.0/8"
|
33
|
-
block_b = IPAddr.new "172.16.0.0/12"
|
34
|
-
block_c = IPAddr.new "192.168.0.0/16"
|
35
|
-
return (block_a.include?(ip) or block_b.include?(ip) or block_c.include?(ip))
|
36
|
-
end
|
25
|
+
option :chef_node_name,
|
26
|
+
:short => "-N NAME",
|
27
|
+
:long => "--node-name NAME",
|
28
|
+
:description => "The Chef node name for your new node"
|
37
29
|
|
38
30
|
option :package,
|
39
31
|
:short => '-f FLAVOR_NAME',
|
@@ -51,6 +43,13 @@ class Chef
|
|
51
43
|
:description => "Comma separated list of roles/recipes to apply",
|
52
44
|
:proc => lambda { |o| o.split(/[\s,]+/) },
|
53
45
|
:default => []
|
46
|
+
|
47
|
+
option :json_attributes,
|
48
|
+
:short => "-j JSON",
|
49
|
+
:long => "--json-attributes JSON",
|
50
|
+
:description => "A JSON string to be added to the first run of chef-client",
|
51
|
+
:proc => lambda { |o| JSON.parse(o) },
|
52
|
+
:default => {}
|
54
53
|
|
55
54
|
option :private_network,
|
56
55
|
:long => "--private-network",
|
@@ -69,11 +68,6 @@ class Chef
|
|
69
68
|
:long => "--identity-file IDENTITY_FILE",
|
70
69
|
:description => "The SSH identity file used for authentication"
|
71
70
|
|
72
|
-
option :chef_node_name,
|
73
|
-
:short => "-N NAME",
|
74
|
-
:long => "--node-name NAME",
|
75
|
-
:description => "The Chef node name for your new node"
|
76
|
-
|
77
71
|
option :prerelease,
|
78
72
|
:long => "--prerelease",
|
79
73
|
:description => "Install the pre-release chef gems"
|
@@ -133,37 +127,15 @@ class Chef
|
|
133
127
|
tcp_socket && tcp_socket.close
|
134
128
|
end
|
135
129
|
|
136
|
-
# Run Chef bootstrap script
|
137
|
-
def bootstrap_for_node(server, bootstrap_ip_address)
|
138
|
-
bootstrap = Chef::Knife::Bootstrap.new
|
139
|
-
Chef::Log.debug("Bootstrap name_args = [ #{bootstrap_ip_address} ]")
|
140
|
-
bootstrap.name_args = [ bootstrap_ip_address ]
|
141
|
-
Chef::Log.debug("Bootstrap run_list = #{config[:run_list]}")
|
142
|
-
bootstrap.config[:run_list] = config[:run_list]
|
143
|
-
Chef::Log.debug("Bootstrap ssh_user = #{config[:ssh_user]}")
|
144
|
-
bootstrap.config[:ssh_user] = config[:ssh_user]
|
145
|
-
Chef::Log.debug("Bootstrap identity_file = #{config[:identity_file]}")
|
146
|
-
bootstrap.config[:identity_file] = config[:identity_file]
|
147
|
-
Chef::Log.debug("Bootstrap chef_node_name = #{config[:chef_node_name]}")
|
148
|
-
bootstrap.config[:chef_node_name] = config[:chef_node_name] || server.id
|
149
|
-
Chef::Log.debug("Bootstrap prerelease = #{config[:prerelease]}")
|
150
|
-
bootstrap.config[:prerelease] = config[:prerelease]
|
151
|
-
Chef::Log.debug("Bootstrap distro = #{config[:distro]}")
|
152
|
-
bootstrap.config[:distro] = config[:distro]
|
153
|
-
#Chef::Log.debug("Bootstrap use_sudo = #{config[:use_sudo]}")
|
154
|
-
#bootstrap.config[:use_sudo] = true
|
155
|
-
Chef::Log.debug("Bootstrap environment = #{config[:environment]}")
|
156
|
-
bootstrap.config[:environment] = config[:environment]
|
157
|
-
Chef::Log.debug("Bootstrap no_host_key_verify = #{config[:no_host_key_verify]}")
|
158
|
-
bootstrap.config[:no_host_key_verify] = config[:no_host_key_verify]
|
159
|
-
|
160
|
-
bootstrap
|
161
|
-
end
|
162
|
-
|
163
130
|
def run
|
164
131
|
$stdout.sync = true
|
165
132
|
|
166
133
|
# add some validation here ala knife-ec2
|
134
|
+
unless config[:server_name] || config[:chef_node_name]
|
135
|
+
ui.error("You have not provided a valid server or node name.")
|
136
|
+
show_usage
|
137
|
+
exit 1
|
138
|
+
end
|
167
139
|
|
168
140
|
node_name = config[:chef_node_name] || config[:server_name]
|
169
141
|
|
@@ -179,9 +151,7 @@ class Chef
|
|
179
151
|
server.wait_for { print "."; ready? }
|
180
152
|
|
181
153
|
#which IP address to bootstrap
|
182
|
-
bootstrap_ip_addresses = server.ips.select{|ip|
|
183
|
-
ip and not(is_loopback(ip) or is_linklocal(ip))
|
184
|
-
}
|
154
|
+
bootstrap_ip_addresses = server.ips.select{ |ip| ip and not(is_loopback(ip) or is_linklocal(ip)) }
|
185
155
|
|
186
156
|
if bootstrap_ip_addresses.count == 1
|
187
157
|
bootstrap_ip_address = bootstrap_ip_addresses.first
|
@@ -215,6 +185,7 @@ class Chef
|
|
215
185
|
msg_pair("Type", server.type)
|
216
186
|
msg_pair("Dataset", server.dataset)
|
217
187
|
msg_pair("IP's", server.ips)
|
188
|
+
msg_pair("JSON Attributes",config[:json_attributes]) unless config[:json_attributes].empty?
|
218
189
|
end
|
219
190
|
|
220
191
|
# Run Chef bootstrap script
|
@@ -240,15 +211,11 @@ class Chef
|
|
240
211
|
bootstrap.config[:environment] = config[:environment]
|
241
212
|
Chef::Log.debug("Bootstrap no_host_key_verify = #{config[:no_host_key_verify]}")
|
242
213
|
bootstrap.config[:no_host_key_verify] = config[:no_host_key_verify]
|
214
|
+
Chef::Log.debug("Bootstrap json_attributes = #{config[:json_attributes]}")
|
215
|
+
bootstrap.config[:first_boot_attributes] = config[:json_attributes]
|
243
216
|
|
244
217
|
bootstrap
|
245
218
|
end
|
246
|
-
|
247
|
-
def msg_pair(label, value = nil)
|
248
|
-
if value && !value.empty?
|
249
|
-
puts "#{ui.color(label, :cyan)}: #{value}"
|
250
|
-
end
|
251
|
-
end
|
252
219
|
end
|
253
220
|
end
|
254
221
|
end
|
data/lib/knife-joyent/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-joyent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
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:
|
12
|
+
date: 2013-03-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog
|