class Chef::Knife::SakuraServerCreate
Public Instance Methods
bootstrap_node(server, bootstrap_ip_address)
click to toggle source
# File lib/chef/knife/sakura_server_create.rb, line 221 def bootstrap_node(server, bootstrap_ip_address) bootstrap = Chef::Knife::Bootstrap.new bootstrap.name_args = [bootstrap_ip_address] bootstrap.config[:ssh_user] = config[:ssh_user] bootstrap.config[:ssh_port] = config[:ssh_port] bootstrap.config[:ssh_gateway] = config[:ssh_gateway] bootstrap.config[:identity_file] = config[:identity_file] bootstrap.config[:chef_node_name] = locate_config_value(:chef_node_name) || server.name bootstrap.config[:use_sudo] = true unless config[:ssh_user] == 'root' bootstrap.config[:host_key_verify] = config[:host_key_verify] # bootstrap.config[:run_list] = config[:run_list] bootstrap.config[:bootstrap_version] = locate_config_value(:bootstrap_version) bootstrap.config[:distro] = locate_config_value(:distro) bootstrap.config[:template_file] = locate_config_value(:template_file) bootstrap.config[:environment] = locate_config_value(:environment) bootstrap.config[:prerelease] = config[:prerelease] bootstrap.config[:first_boot_attributes] = locate_config_value(:json_attributes) || {} bootstrap.config[:encrypted_data_bag_secret] = locate_config_value(:encrypted_data_bag_secret) bootstrap.config[:encrypted_data_bag_secret_file] = locate_config_value(:encrypted_data_bag_secret_file) bootstrap.config[:secret] = locate_config_value(:secret) bootstrap.config[:secret_file] = locate_config_value(:secret_file) # Modify global configuration state to ensure hint gets set by # knife-bootstrap Chef::Config[:knife][:hints] ||= {} Chef::Config[:knife][:hints]["sakura"] ||= {} bootstrap end
run()
click to toggle source
# File lib/chef/knife/sakura_server_create.rb, line 178 def run $stdout.sync = true validate! options = {} options[:name] = locate_config_value( :name ) options[:serverplan] = locate_config_value( :serverplan ) options[:volume] = { :diskplan => locate_config_value( :diskplan ), :sourcearchive => locate_config_value( :sourcearchive ) } options[:boot] = locate_config_value( :boot ) options[:sshkey] = locate_config_value( :sakuracloud_ssh_key ) if options[:name] == nil puts 'Error. Missing disk name (-n) option.' elsif options[:serverplan] == nil puts 'Error. Missing server plan id (--server-plan) option.' elsif options[:volume][:diskplan] == nil puts 'Error. Missing disk plan id (--disk-plan) option.' elsif options[:volume][:sourcearchive] == nil puts 'Error. Missing source_archive id (--source-archive) option.' else begin @server = connection.servers.create( options ) msg_pair("Instance ID", @server.id) msg_pair("Server Plan", @server.server_plan['Name']) bootstrap_ip_address = @server.interfaces.first['IPAddress'] msg_pair("Public IP Address", bootstrap_ip_address) bootstrap_node(@server, bootstrap_ip_address).run if options[:bootstrap] rescue Exception puts $!.message body = Fog::JSON.decode( $!.response.body ) puts "#{body['status']}: #{body['error_msg']}" end end end