Class: Chef::Knife::RackspaceServerCreate
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::RackspaceServerCreate
- Defined in:
- lib/chef/knife/rackspace_server_create.rb
Instance Attribute Summary
Attributes inherited from Chef::Knife
Instance Method Summary collapse
Methods inherited from Chef::Knife
#ask_question, build_sub_class, #bulk_delete, #configure_chef, #confirm, #create_object, #delete_object, #edit_data, #edit_object, #file_exists_and_is_readable?, find_command, #format_for_display, #format_list_for_display, list_commands, load_commands, #load_from_file, #output, #pretty_print, #rest, #stdin, #stdout
Methods included from Mixin::ConvertToClassName
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
Instance Method Details
#h ⇒ Object
60 61 62 |
# File 'lib/chef/knife/rackspace_server_create.rb', line 60 def h @highline ||= HighLine.new end |
#run ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/chef/knife/rackspace_server_create.rb', line 64 def run require 'fog' require 'highline' require 'net/ssh/multi' require 'readline' connection = Fog::Rackspace::Servers.new( :rackspace_api_key => Chef::Config[:knife][:rackspace_api_key], :rackspace_username => Chef::Config[:knife][:rackspace_api_username] ) server = connection.servers.new server.flavor_id = config[:flavor] server.image_id = config[:image] server.name = config[:server_name] server.personality = [ { 'path' => '/etc/install-chef', 'contents' => "#!/bin/bash\n# Customized rc.local for chef installation\n\nif [ ! -f /usr/bin/chef-client ]; then\n apt-get update\n apt-get install -y ruby ruby1.8-dev build-essential wget libruby-extras libruby1.8-extras\n cd /tmp\n wget http://rubyforge.org/frs/download.php/69365/rubygems-1.3.6.tgz\n tar xvf rubygems-1.3.6.tgz\n cd rubygems-1.3.6\n ruby setup.rb\n cp /usr/bin/gem1.8 /usr/bin/gem\n gem install chef ohai --no-rdoc --no-ri --verbose\nfi\n\nexit 0\n" }, { 'path' => "/etc/chef/validation.pem", 'contents' => IO.read(Chef::Config[:validation_key]) }, { 'path' => "/etc/chef/client.rb", 'contents' => "log_level :info\nlog_location STDOUT\nchef_server_url \"\#{Chef::Config[:chef_server_url]}\" \nvalidation_client_name \"\#{Chef::Config[:validation_client_name]}\"\n" }, { 'path' => "/etc/chef/first-boot.json", 'contents' => { "run_list" => @name_args }.to_json }, ] server.save $stdout.sync = true puts "#{h.color("Name", :cyan)}: #{server.name}" puts "#{h.color("Flavor", :cyan)}: #{server.flavor_id}" puts "#{h.color("Image", :cyan)}: #{server.image_id}" puts "#{h.color("Public Address", :cyan)}: #{server.addresses["public"]}" puts "#{h.color("Private Address", :cyan)}: #{server.addresses["private"]}" puts "#{h.color("Password", :cyan)}: #{server.password}" print "\n#{h.color("Requesting server", :magenta)}" saved_password = server.password # wait for it to be ready to do stuff server.wait_for { print "."; ready? } puts "\nServer ready, waiting 15 seconds to bootstrap." sleep 15 puts "\nBootstrapping #{h.color(server.name, :bold)}..." ssh = Chef::Knife::Ssh.new ssh.name_args = [ server.addresses["public"][0], "/bin/bash /etc/install-chef && /usr/bin/chef-client -j /etc/chef/first-boot.json" ] ssh.config[:ssh_user] = "root" ssh.config[:manual] = true ssh.config[:password] = saved_password ssh.password = saved_password ssh.run end |