Class/Module Index [+]

Quicksearch

Rudy::CLI::AWS::EC2::Instances

Public Instance Methods

consoles() click to toggle source
# File lib/rudy/cli/aws/ec2/instances.rb, line 124
def consoles
  opts = {}
  opts[:group] = @option.group if @option.group
  opts[:id] = @argv.instid if @argv.instid
  opts[:id] &&= [opts[:id]].flatten
  
  lt = Rudy::AWS::EC2::Instances.list_group(opts[:group], :any, opts[:id]) do |inst|
    li instance_separator(inst.dns_public || inst.state, inst.awsid)
    console = Rudy::AWS::EC2::Instances.console(inst.awsid)
    output = console ? Base64.decode64(console) : "Unavailable"
    
    # The linux console can include ANSI escape codes for color, 
    # clear screen etc... We strip them out to get rid of the 
    # clear specifically. Otherwise the display is messed!
    output &&= output.noansi 
    
    li output 
    
    if output.match(/<Password>(.+)<\/Password>/)  # /m, match multiple lines
      li
      if @@global.pkey
        encrtypted_text = ($1 || '').strip
        k = Rye::Key.from_file(@@global.pkey)
        pword = k.decrypt(encrtypted_text)
        answer = "%s: %s" % ['password', pword] 
        Annoy.timed_display(answer, STDERR, 10)
        li
      else
        li "Please supply a private key path to decode the administrator password"
        li "rudy-ec2 -k path/2/privatekey console [-g group] [instance ID]"
      end
    end
    
  end
  
end
consoles_valid?() click to toggle source
# File lib/rudy/cli/aws/ec2/instances.rb, line 116
def consoles_valid?
  if @@global.pkey
    raise "Cannot find file #{@@global.pkey}" unless File.exists?(@@global.pkey)
    raise "Insecure permissions for #{@@global.pkey}" unless (File.stat(@@global.pkey).mode & 600) == 0
  end
  raise "No instances" unless Rudy::AWS::EC2::Instances.any?
  true
end
instances() click to toggle source
Alias for: status
instances_create() click to toggle source
# File lib/rudy/cli/aws/ec2/instances.rb, line 27
def instances_create
  
  opts = {                 # Defaults
    :group => 'default',
    :size => 'm1.small',
    :zone => @@global.zone
  }
        
  if @option.address
    raise "Cannot specify both -a and -n" if @option.newaddress
    unless Rudy::AWS::EC2::Addresses.exists?(@option.address)
      raise "#{@option.address} is not allocated to you" 
    end
    if Rudy::AWS::EC2::Addresses.associated?(@option.address)
      raise "#{@option.address} is already associated!" 
    end
  end
  
  # These can be sent directly to EC2 class
  [:group, :ami, :size, :keypair, :private].each do |n|
    opts[n] = @option.send(n) if @option.send(n)
  end
  
  li "Creating #{opts[:size]} instance in #{@@global.zone}"
  
  unless opts[:keypair]
    li "You did not specify a keypair. Unless you've prepared a user account".bright
    li "on this image (#{opts[:ami]}) you will not be able to log in to it.".bright
    exit unless Annoy.proceed?(:low)
  end
  
  instances = Rudy::AWS::EC2::Instances.list_group(opts[:group], :running)
  
  if instances && instances.size > 0
    instance_count = (instances.size == 1) ? 'is 1 instance' : "are #{instances.size} instances"
    li "There #{instance_count} running in the #{opts[:group]} group."
    exit unless Annoy.proceed?(:low)
  end
  
  if @option.newaddress
    print "Creating address... "
    address = Rudy::AWS::EC2::Addresses.create
    li "#{address.ipaddress}"
    @option.address = address.ipaddress
  end
     
  execute_action do
    first_instance = true
    Rudy::AWS::EC2::Instances.create(opts) do |inst| # Rudy::AWS::EC2::Instance objects
    
      # Assign IP address to only the first instance
      if first_instance && @option.address
        li "Associating #{@option.address} to #{inst.awsid}"
        Rudy::AWS::EC2::Addresses.associate(@option.address, inst.awsid)
        first_instance = false
      end
    
      print_stobject(inst)
    end
  end
end
instances_create_valid?() click to toggle source
# File lib/rudy/cli/aws/ec2/instances.rb, line 14
def instances_create_valid?
  
  raise "Cannot supply an instance ID" if @option.instid
  
  if @option.group
    unless Rudy::AWS::EC2::Groups.exists?(@option.group)
      raise "Group #{@option.group} does not exist"
    end
  end
  
  true
end
instances_destroy() click to toggle source
# File lib/rudy/cli/aws/ec2/instances.rb, line 108
def instances_destroy
  instances_action :destroy
end
instances_destroy_valid?() click to toggle source
instances_restart() click to toggle source
# File lib/rudy/cli/aws/ec2/instances.rb, line 112
def instances_restart
  instances_action :restart
end
instances_restart_valid?() click to toggle source
# File lib/rudy/cli/aws/ec2/instances.rb, line 89
def instances_restart_valid?
  raise InstanceAndGroupError.new(nil, @alias) if @option.group && @argv.instid
  raise NoInstanceError.new(nil, @alias) if !@option.group && !@argv.instid
  
  if @option.group
    unless Rudy::AWS::EC2::Groups.exists?(@option.group)
      raise "Group #{@option.group} does not exist"
    end
  end
  
  if @option.private
    raise Drydock::OptsError.new(nil, @alias, "Cannot allocate public IP for private instance") if @option.address || @option.newadress
  end
  
  raise "No instances" unless Rudy::AWS::EC2::Instances.any?
  true
end
Also aliased as: instances_destroy_valid?
status() click to toggle source
# File lib/rudy/cli/aws/ec2/instances.rb, line 161
def status
  opts = {}
  
  opts[:group] = @option.group if @option.group
  opts[:state] = @option.state if @option.state

  # A nil value forces the @@ec2.instances.list to return all instances
  if @option.all
    opts[:state] = :any
    opts[:group] = :any
  end

  opts[:id] = @argv.instid if @argv.instid
  opts[:id] &&= [opts[:id]].flatten
  
  ilist = Rudy::AWS::EC2::Instances.list_group(opts[:group], opts[:state], opts[:id])
  ilist.nil? ? li( "No instances running" ) : print_stobjects(ilist)
end
Also aliased as: instances

[Validate]

Generated with the Darkfish Rdoc Generator 2.