class Chef::Knife::OpennebulaServerCreate
Public Instance Methods
bootstrap(ip)
click to toggle source
# File lib/chef/knife/opennebula_server_create.rb, line 169 def bootstrap(ip) bootstrap = Chef::Knife::Bootstrap.new bootstrap.name_args = ip bootstrap.config[:run_list] = locate_config_value(:run_list) bootstrap.config[:ssh_user] = locate_config_value(:ssh_user) bootstrap.config[:ssh_port] = locate_config_value(:ssh_port) bootstrap.config[:identity_file] = locate_config_value(:identity_file) bootstrap.config[:distro] = locate_config_value(:distro) bootstrap.config[:host_key_verify] = config[:host_key_verify] bootstrap.config[:first_boot_attributes] = locate_config_value(:json_attributes) || {} bootstrap.config[:template_file] = locate_config_value(:template_file) bootstrap.config[:chef_node_name] = locate_config_value(:chef_node_name) bootstrap.config[:bootstrap_install_command] = locate_config_value(:bootstrap_install_command) bootstrap.config[:use_sudo] = true unless bootstrap.config[:ssh_user] == 'root' bootstrap.run end
flavor()
click to toggle source
# File lib/chef/knife/opennebula_server_create.rb, line 210 def flavor @flavor ||= connection.flavors.get_by_name(locate_config_value(:opennebula_template)) @flavor[0] end
h()
click to toggle source
# File lib/chef/knife/opennebula_server_create.rb, line 115 def h @highline ||= HighLine.new end
run()
click to toggle source
# File lib/chef/knife/opennebula_server_create.rb, line 119 def run validate! validate_flavor! newvm = connection.servers.new newvm.flavor = connection.flavors.get(flavor.id) # set the name of the vm newvm.name = locate_config_value(:chef_node_name) newvm.flavor.vcpu = 1 vm = newvm.save ser = server(vm.id) puts ui.color("\nServer:", :green) msg_pair("VM Name", ser.name) msg_pair("VM ID", ser.id) msg_pair("IP", ser.ip) msg_pair("Template", flavor.name) print "\n#{ui.color("Waiting for server", :magenta)}" # wait for it to be ready to do stuff ser.wait_for { print "."; ready? } puts("\n") # hack to ensure the nodes have had time to spin up print(".") sleep 30 print(".") print(".") until tcp_test_ssh(ser.ip) { sleep @initial_sleep_delay ||= 10 puts("done") } #Bootstrap VM bootstrap(ser.ip) puts ui.color("Server:", :green) msg_pair("Name", ser.name) msg_pair("IP", ser.ip) msg_pair("Environment", config[:environment] || '_default') msg_pair("Run List", config[:run_list].join(', ')) msg_pair("JSON Attributes",config[:json_attributes]) unless !config[:json_attributes] || config[:json_attributes].empty? end
server(id)
click to toggle source
# File lib/chef/knife/opennebula_server_create.rb, line 215 def server(id) @server ||= connection.servers.get(id) end
tcp_test_ssh(hostname) { || ... }
click to toggle source
# File lib/chef/knife/opennebula_server_create.rb, line 186 def tcp_test_ssh(hostname) tcp_socket = TCPSocket.new(hostname, 22) 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
validate_flavor!()
click to toggle source
# File lib/chef/knife/opennebula_server_create.rb, line 219 def validate_flavor! if flavor.nil? ui.error("You have not provided a valid Template NAme. Please note the options for this value are -t or --template-name.") exit 1 end end