class Chef::Knife::ScalewayServerCreate
Public Instance Methods
bootstrap_class()
click to toggle source
# File lib/chef/knife/scaleway_droplet_create.rb, line 319 def bootstrap_class if solo_bootstrap? Chef::Knife::SoloBootstrap elsif zero_bootstrap? Chef::Knife::ZeroBootstrap else Chef::Knife::Bootstrap end end
bootstrap_for_node(ip_address)
click to toggle source
# File lib/chef/knife/scaleway_droplet_create.rb, line 303 def bootstrap_for_node(ip_address) bootstrap = bootstrap_class.new bootstrap.name_args = [ip_address] bootstrap.config.merge! config bootstrap.config[:chef_node_name] = locate_config_value(:server_name) bootstrap.config[:bootstrap_version] = locate_config_value(:bootstrap_version) bootstrap.config[:ssh_port] = Chef::Config[:knife][:ssh_port] || config[:ssh_port] bootstrap.config[:distro] = locate_config_value(:distro) bootstrap.config[:use_sudo] = true unless config[:ssh_user] == 'root' bootstrap.config[:template_file] = locate_config_value(:template_file) bootstrap.config[:environment] = locate_config_value(:environment) bootstrap.config[:first_boot_attributes] = locate_config_value(:json_attributes) || {} bootstrap.config[:secret_file] = locate_config_value(:secret_file) || {} bootstrap end
ip_address_available(server_id) { || ... }
click to toggle source
# File lib/chef/knife/scaleway_droplet_create.rb, line 267 def ip_address_available(server_id) server = Scaleway::Server.find(server_id) if server.public_ip yield server.public_ip else sleep @initial_sleep_delay ||= 10 false end end
run()
click to toggle source
# File lib/chef/knife/scaleway_droplet_create.rb, line 169 def run $stdout.sync = true validate! unless locate_config_value(:server_name) ui.error('Server Name cannot be empty: -N <servername>') exit 1 end unless locate_config_value(:image) ui.error('Image cannot be empty: -I <image>') exit 1 end =begin unless locate_config_value(:size) ui.error('Size cannot be empty: -S <size>') exit 1 end unless locate_config_value(:location) ui.error('Location cannot be empty: -L <region>') exit 1 end unless locate_config_value(:ssh_key_ids) ui.error('One or more Scaleway SSH key ids missing: -K <KEY1>, <KEY2> ...') exit 1 end =end if solo_bootstrap? && !defined?(Chef::Knife::SoloBootstrap) ui.error [ 'Knife plugin knife-solo was not found.', 'Please add the knife-solo gem to your Gemfile or', 'install it manually with `gem install knife-solo`.' ].join(' ') exit 1 end if zero_bootstrap? && !defined?(Chef::Knife::ZeroBootstrap) ui.error [ 'Knife plugin knife-zero was not found.', 'Please add the knife-zero gem to your Gemfile or', 'install it manually with `gem install knife-zero`.' ].join(' ') exit 1 end =begin server = DropletKit::Droplet.new(name: locate_config_value(:server_name), size: locate_config_value(:size), image: locate_config_value(:image), region: locate_config_value(:location), ssh_keys: locate_config_value(:ssh_key_ids), private_networking: locate_config_value(:private_networking), backups: locate_config_value(:backups), ipv6: locate_config_value(:ipv6) ) =end server = Scaleway::Server.create(locate_config_value(:server_name), locate_config_value(:image), 'VC1S') #server = client.servers.create(server) if Scaleway::Server.find(server.id).state != 'stopped' ui.error("Droplet could not be started #{server.inspect}") exit 1 end puts "Droplet creation for #{locate_config_value(:server_name)} started. Droplet-ID is #{server.id}" unless !config.key?(:json_attributes) || config[:json_attributes].empty? puts ui.color("JSON Attributes: #{config[:json_attributes]}", :magenta) end puts "Starting server #{server.id}" Scaleway::Server.action(server.id, 'poweron') print ui.color('Waiting for IPv4-Address', :magenta) print('.') until ip_address = ip_address_available(server.id) do puts 'done' end puts ui.color("IPv4 address is: #{ip_address.address}", :green) print ui.color('Waiting for sshd:', :magenta) print('.') until tcp_test_ssh(ip_address.address) do sleep 2 puts 'done' end if locate_config_value(:bootstrap) || solo_bootstrap? || zero_bootstrap? bootstrap_for_node(ip_address.address).run else puts ip_address.address exit 0 end end
solo_bootstrap?()
click to toggle source
# File lib/chef/knife/scaleway_droplet_create.rb, line 329 def solo_bootstrap? config[:solo] || (config[:solo].nil? && Chef::Config[:knife][:solo]) end
tcp_test_ssh(hostname) { || ... }
click to toggle source
# File lib/chef/knife/scaleway_droplet_create.rb, line 278 def tcp_test_ssh(hostname) port = Chef::Config[:knife][:ssh_port] || config[:ssh_port] tcp_socket = TCPSocket.new(hostname, port) readable = IO.select([tcp_socket], nil, nil, 5) if readable Chef::Log.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}") yield true else false end rescue Errno::ETIMEDOUT false rescue Errno::EPERM false rescue Errno::ECONNREFUSED sleep 2 false rescue Errno::EHOSTUNREACH sleep 2 false ensure tcp_socket && tcp_socket.close end
zero_bootstrap?()
click to toggle source
# File lib/chef/knife/scaleway_droplet_create.rb, line 333 def zero_bootstrap? config[:zero] || (config[:zero].nil? && Chef::Config[:knife][:zero]) end