265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
# File 'lib/chef/knife/softlayer_server_create.rb', line 265
def run
$stdout.sync = true
config.merge!(slurp_from_file(config[:from_file])) if config[:from_file]
raise SoftlayerServerCreateError, "#{ui.color("Windows VMs not currently supported.", :red)}" if config[:os_code] =~ /^WIN_/
raise SoftlayerServerCreateError, "#{ui.color("identity file (-i) option is incompatible with password (-P) option required.", :red)}" if !!config[:identity_file] and !!config[:ssh_password]
raise SoftlayerServerCreateError, "#{ui.color("--new-global-ip value must be 'v4' or 'v6'.", :red)}" if config[:new_global_ip] and !config[:new_global_ip].to_s.match(/^v[4,6]$/i)
config[:vlan] = config[:vlan].to_i if config[:vlan]
config[:private_vlan] = config[:private_vlan].to_i if config[:private_vlan]
Fog.credentials[:private_key_path] = config[:identity_file] if config[:identity_file]
opts = {
:flavor => :flavor_id,
:hostname => :name,
:domain => nil,
:cores => :cpu,
:os_code => nil,
:ram => nil,
:block_storage => :disk,
:local_storage => :ephemeral_storage,
:datacenter => nil,
:ssh_keys => :key_pairs,
:vlan => nil,
:private_vlan => nil,
:image_id => nil,
:private_network_only => nil,
:user_data => nil
}
opts.keys.each do |opt|
if opts[opt].nil?
opts[opt] = config[opt]
else
opts[opts.delete(opt)] = config[opt] end
end
opts[:network_components] = [ {"speed" => config[:nic]} ] if !!config[:nic]
opts.delete_if { |k,v| v.nil? }
puts ui.color("Launching SoftLayer VM, this may take a few minutes.", :green)
instance = connection.servers.create(opts)
if config[:private_network_only] || config[:use_private_network]
instance.ssh_ip_address = Proc.new {|server| server.private_ip_address }
end
progress Proc.new { instance.wait_for(timeout=config[:wait_for_timeout].to_i) { ready? and sshable? } }
putc("\n")
if config[:tags]
puts ui.color("Applying tags to SoftLayer instance.", :green)
progress Proc.new { instance.add_tags(config[:tags]) }
putc("\n")
end
if config[:new_global_ip] || config[:assign_global_ip]
if config[:new_global_ip] begin
puts ui.color('Provisioning new Global IP' + config[:new_global_ip].downcase + ', this may take a few minutes.', :green)
create_global_ip = Proc.new do
existing_records = connection(:network).get_global_ip_records.body
connection(:network).send('create_new_global_ip' + config[:new_global_ip].downcase) or raise SoftlayerServerCreateError, "Unable to create new Global IP Address.";
sleep 20 new_record_global_id = (connection(:network).get_global_ip_records.body - existing_records).reduce['id']
connection(:network).ips.select { |ip| ip.global_id == new_record_global_id }.reduce
end
global_ip = progress(create_global_ip) or raise SoftlayerServerCreateError, "Error encountered creating Global IP Address."
puts ui.color('Global IP Address successfully created.', :green)
rescue SoftlayerServerCreateError => e
puts ui.color('We have encountered a problem ordering the requested global IP. The transaction may not have completed.', :red)
puts ui.color(e.message, :yellow)
end
end
if config[:assign_global_ip]
case config[:assign_global_ip].to_s
when /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/
global_ip = connection(:network).ips.by_address(config[:assign_global_ip])
when /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/
global_ip = connection(:network).ips.by_address(config[:assign_global_ip])
else
raise SoftlayerServerCreateError, "--assign-global-ip value must be valid IPv4 or IPv6 address"
end
global_ip or raise SoftlayerServerCreateError, "Global IP address not found. Please check the address or id supplied and try again."
global_ip.reload
end
route_global_ip = Proc.new do
puts ui.color('Routing Global IP Address to Instance.', :green)
global_ip.route(connection(:network).ips.by_address(instance.public_ip_address)) or raise SoftlayerServerCreateError, "Global IP address failed to route."
puts ui.color('Global IP Address has been assigned.', :green)
puts ui.color('Global IP Address will not function without networking rules on the endpoint operating system. See http://knowledgelayer.softlayer.com/learning/global-ip-addresses for details.', :yellow)
end
progress(route_global_ip)
end
puts ui.color('Bootstrapping Chef node, this may take a few minutes.', :green)
linux_bootstrap(instance).run
puts ui.color("Applying tags to Chef node.", :green)
progress apply_tags(instance)
end
|