Class: Chef::Knife::SlicehostServerCreate
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::SlicehostServerCreate
- Defined in:
- lib/chef/knife/slicehost_server_create.rb
Constant Summary
Constants inherited from Chef::Knife
Instance Attribute Summary
Attributes inherited from Chef::Knife
Instance Method Summary collapse
Methods inherited from Chef::Knife
#ask_question, #bulk_delete, category, #configure_chef, #confirm, #create_object, #delete_object, #edit_data, #edit_object, #file_exists_and_is_readable?, #format_for_display, #format_list_for_display, guess_category, inherited, #initialize, list_commands, load_commands, #load_from_file, #msg, msg, #output, #parse_options, #pretty_print, #rest, run, #show_usage, snake_case_name, #stdin, #stdout, subcommand_category, subcommand_class_from, subcommands, subcommands_by_category, unnamed?
Methods included from Mixin::ConvertToClassName
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
Constructor Details
This class inherits a constructor from Chef::Knife
Instance Method Details
#h ⇒ Object
55 56 57 |
# File 'lib/chef/knife/slicehost_server_create.rb', line 55 def h @highline ||= HighLine.new end |
#run ⇒ Object
59 60 61 62 63 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 |
# File 'lib/chef/knife/slicehost_server_create.rb', line 59 def run require 'fog' require 'highline' require 'net/ssh/multi' require 'readline' slicehost = Fog::Slicehost.new( :slicehost_password => Chef::Config[:knife][:slicehost_password] ) flavors = slicehost.flavors.inject({}) { |h,f| h[f.id] = f.name; h } images = slicehost.images.inject({}) { |h,i| h[i.id] = i.name; h } response = slicehost.create_slice(config[:flavor], config[:image], config[:server_name]) $stdout.sync = true puts "#{h.color("Name", :cyan)}: #{response.body['name']}" puts "#{h.color("Flavor", :cyan)}: #{flavors[response.body['flavor-id']]}" puts "#{h.color("Image", :cyan)}: #{images[response.body['image-id']]}" puts "#{h.color("Public Address", :cyan)}: #{response.body['addresses'][1]}" puts "#{h.color("Private Address", :cyan)}: #{response.body['addresses'][0]}" puts "#{h.color("Password", :cyan)}: #{response.body['root-password']}" print "\n#{h.color("Requesting status of #{response.body['name']}", :magenta)}" saved_password = response.body['root-password'] # wait for it to be ready to do stuff loop do sleep 15 host = slicehost.get_slice(response.body['id']) if host.body['status'] == 'active' break end end puts "\nServer ready!!" end |