Class: Runner
Constant Summary
Constants included from Utils
Utils::INSTANCE_MAPPINGS_FILENAME
Instance Method Summary collapse
Methods included from Options
#opts, #parse_attach_volume_options, #parse_spinup_options, #parse_ssh_options
Methods included from Utils
#console_output, #delete_instance_from_datastore, #get_instance, #get_instances, #get_name_for_instance, #load_instances_from_datastore, #parse_aws_status_line_into_instance, #run_instance, #scp_up, #spindown, #spinup, #ssh, #terminate_instances, #write_instance_to_datastore, #write_instances_to_datastore
Instance Method Details
#banner ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/runner.rb', line 63 def <<-EOS Script enabling easier interaction with Amazon EC2 instances. Usage: goec2 COMMAND [INSTANCE_NAME] [ARGS] Commands: spinup Tells EC2 service to launch a new instance. By default generates a random name to associate with that instance through goec2 spindown Terminates the specified instance status Retrieves the status of all running EC2 instances ssh SSH into an EC2 instance scp_up Upload a file to an EC2 instance (goec2 scp_up INSTANCE_NAME SOURCE DEST) webopen Open the EC2 instance in a web browser (Mac OSX only) output Get console output for a given EC2 instance address Get the public address for a given EC2 instance attach_volume Attach an EBS volume to the given EC2 instance EOS end |
#run(args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/runner.rb', line 9 def run(args) case args[0] when /spinup/ = (args, :name => get_name_for_instance, :instance_size => 'm1.large', :zone => 'us-east-1c') puts "Spining up image with options: #{.inspect}" spinup() when /spindown/ raise "Need an instance name" unless args[1] spindown args[1] when /status/ puts "Getting the status" instances = if args[1] then [get_instance(args[1])].compact else get_instances end instances.each do |instance| puts "%s\t%s\t%s\t%s" % [instance.name, instance.instance_id, instance.status, instance.url] end when /ssh/ instance_name = args.delete_at(1) raise "Need an instance name" unless instance_name instance = get_instance(instance_name) raise "Unknown instance name #{instance_name}" unless instance = (args, :user => 'w3dev', :keypair_path => EC2_KEYPAIR_PATH) ssh instance.url, when /scp_up/ raise "Need an istance name" unless args[1] raise "Need a source path" unless args[2] raise "Need a destination path" unless args[3] instance = get_instance(args[1]) scp_up instance, args[2], args[3] when /webopen/ raise "Need an instance name" unless args[1] instance = get_instance(args[1]) raise "Unknown instance name #{args[1]}" unless instance `open http://#{instance.url}` when /output/ raise "Need an instance name" unless args[1] console_output get_instance(args[1]) when /address/ raise "Need an instance name" unless args[1] instance = get_instance(args[1]) puts instance.url when /attach_volume/ raise "Need an instance name" unless args[1] instance_name = args.delete_at(1) = (args, :device => '/dev/sdf') instance = get_instance(instance_name) `ec2-attach-volume #{[:volume_id]} -i #{instance.instance_id} -d #{[:device]}` else puts end end |