#!/usr/bin/ruby # = Interactive Rudy (experimental) # # === Not your granparent's deployment tool # # See ird -h for usage # $:.unshift File.join(File.dirname(__FILE__), '..', 'lib') # Put our local lib in first place $:.unshift File.join(File.dirname(__FILE__), '..', 'vendor', 'highline-1.5.1', 'lib') %w{drydock caesars rye}.each { |dir| $:.unshift File.join(File.dirname(__FILE__), '..', '..', dir, 'lib') } require 'rubygems' # SEE: http://github.com/rubyspec/matzruby/blob/a34130eb7c4ecc164115a59aa1b76c643bd98202/lib/irb/xmp.rb # SEE: http://github.com/blackwinter/wirble/tree/master require "irb" require 'irb/completion' require 'rudy' require 'drydock' require 'rudy/cli' module RudyCLI_Interactive # :nodoc:all extend self extend Drydock include Readline global :A, :accesskey, String, "AWS Access Key" global :S, :secretkey, String, "AWS Secret Access Key" #global :R, :region, String, "Connect to a specific EC2 region (ie: #{Rudy::DEFAULT_REGION})" #global :n, :nocolor, "Disable output colors" global :f, :config, String, "Specify another configuration file to read (ie: #{Rudy::CONFIG_FILE})" global :z, :zone, String, "Connect to a specific EC2 zone (ie: #{Rudy::DEFAULT_ZONE})" global :e, :environment, String, "Connect to the specified environment (ie: #{Rudy::DEFAULT_ENVIRONMENT})" global :r, :role, String, "Connect to a machine with the specified role (ie: #{Rudy::DEFAULT_ROLE})" global :p, :position, String, "Position in the machine in its group (ie: #{Rudy::DEFAULT_POSITION})" global :u, :user, String, "Provide a username (ie: #{Rudy::DEFAULT_USER})" #global :q, :quiet, "Run with less output" #global :v, :verbose, "Increase verbosity of output (i.e. -v or -vv or -vvv)" do # @verbose ||= 0 # @verbose += 1 #end global :V, :version, "Display version number" do puts "Rudy version: #{Rudy::VERSION}" exit 0 end default :interactive debug :off desc "An interactive REPL for Rudy." usage "#{$0} [global options]" command :interactive do |obj| @@rmach = Rudy::Machines.new(:global => obj.global) @@rkey = Rudy::KeyPairs.new(:global => obj.global) @@rgrp = Rudy::Groups.new(:global => obj.global) @@rvol = Rudy::Volumes.new(:global => obj.global) @@radd = Rudy::Addresses.new(:global => obj.global) puts Rudy::CLI.generate_header(@@rmach.global, @@rmach.config) puts Rudy::Utils.without_indent(%Q` ------------------------------------------------------------ Welcome Interactive Rudy! (EXPERIMENTAL) ------------------------------------------------------------ `) h # What's the deal with this error message when defining a help method? # => rb: warn: can't alias help from irb_help if __FILE__ == $0 IRB.start(__FILE__) else # check -e option if /^-e$/ =~ $0 IRB.start(__FILE__) else IRB.start(__FILE__) end end end def h; puts (%Q` HELP h Help (this screen) m Rudy::Machines instance g Rudy::Groups instance k Rudy::KeyPairs instance v Rudy::Volumes instance a Rudy::Addresses instance ssh [GROUP] Connect to a machine example Start an EC2 instance from scratch. `) end def example puts (%Q` EXAMPLE Start an EC2 instance from scratch. # Create a security group >> g.create => # # Create a keypair (used to login as root) >> k.create => # # Start an EC2 machine instance: >> m.create Instance: i-228def51 Waiting for the instance to startup ........It's up! # Login to the new instance >> ssh All commands in Rudy refer to the global defaults unless otherwise specified. "stage" is the default environment and "app" is the default role. You can change these with command line arguments or by modifying the defaults in your Rudy config file: #{@@rmach.config_dirname} You can also specify your own names by providing one as the first argument: g.create 'group5000'. # List instances in stage-app >> m.list :running => [#] # Print the instance in a human readable way >> puts m.list.first.to_s # Print instance system console output >> puts m.console # Destroy ALL INSTANCES in stage-app >> m.destroy `) end def m; @@rmach; end def k; @@rkey; end def g; @@rgrp; end def v; @@rvol; end def a; @@radd; end # Change Group #def cg(name); end def ssh(*args) @@rmach.switch_user :root @@rmach.connect(*args) @@rmach.switch_user # back to previous user nil end end include CLI # So we don't have to say CLI.example in the REPL. __END__ #@rbox = Rye::Box.new('ec2-174-129-173-3.compute-1.amazonaws.com', 'root') #@rbox2 = Rye::Box.new('ec2-174-129-173-3.compute-1.amazonaws.com', 'root') #@rbox.add_keys('/Users/delano/Projects/git/rudy/.rudy/key-test-app.private')