class AwsCli::CLI::EC2::Instances

Public Instance Methods

console_output() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 295
def console_output
  create_ec2_object
  @ec2.get_console_output options[:instance_id]
end
create() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 192
def create
  create_ec2_object
  @ec2.create_instance options
end
create_centos() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 204
def create_centos
  create_ec2_object
  centos_amis    = {
      'us-east-1'       => 'ami-a96b01c0',  #Virginia
      'us-west-1'       => 'ami-51351b14',  #Northern California
      'us-west-2'       => 'ami-bd58c98d',  #Oregon
      'eu-west-1'       => 'ami-050b1b71',  #Ireland
      'ap-southeast-1'  => 'ami-23682671',  #Singapore
      'ap-southeast-2'  => 'ami-ffcd5ec5',  #Sydney
      'ap-northeast-1'  => 'ami-3fe8603e',  #Tokyo
      'sa-east-1'       => 'ami-e2cd68ff',  #Sao Paulo
  }
  @ec2.create_instance  :image_id             => centos_amis[parent_options[:region]],
                        :block_device_mapping => %w(/dev/sda=:100:true::),
                        :groups               => options[:groups],
                        :flavor_id            => options[:flavor_id],
                        :key_name             => options[:key_name],
                        :tags                 => options[:tags],
                        :count                => options[:count],
                        :wait_for             => options[:wait_for]
end
create_ubuntu() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 233
def create_ubuntu
  create_ec2_object
  ubuntu_amis    = {
      'us-east-1'       => 'ami-9b85eef2',  #Virginia
      'us-west-1'       => 'ami-9b2d03de',  #Northern California
      'us-west-2'       => 'ami-77be2f47',  #Oregon
      'eu-west-1'       => 'ami-f5736381',  #Ireland
      'ap-southeast-1'  => 'ami-085b155a',  #Singapore
      'ap-southeast-2'  => 'ami-37c0530d',  #Sydney
      'ap-northeast-1'  => 'ami-57109956',  #Tokyo
      'sa-east-1'       => 'ami-a4fb5eb9',  #Sao Paulo
  }
  @ec2.create_instance  :image_id             => ubuntu_amis[parent_options[:region]],
                        :block_device_mapping => %w(/dev/sda1=:100:true::),
                        :groups               => options[:groups],
                        :flavor_id            => options[:flavor_id],
                        :key_name             => options[:key_name],
                        :tags                 => options[:tags],
                        :count                => options[:count],
                        :wait_for             => options[:wait_for]

end
describe_instance() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 35
def describe_instance
  create_ec2_object
  @ec2.describe_instance(options)
end
diatt() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 62
def diatt
  create_ec2_object
  @ec2.describe_instance_attribute(options[:id], options[:attr])
end
dins() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 115
def dins
  create_ec2_object
  @ec2.describe_instance_status options[:instance_id]
end
list() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 26
def list
  puts "Listing Instances for region: #{parent_options[:region]}"
  create_ec2_object
  # puts parent_options #access awscli/cli/ec2.rb class options
  @ec2.list_instances
end
list_all() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 41
def list_all
  Awscli::Instances::REGIONS.each do |region|
    puts "Listing instances for region: #{region}"
    ec2 = Awscli::EC2::EC2.new(Awscli::Connection.new.request_ec2 region)
    ec2.list_instances
  end
end
list_regions() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 16
def list_regions
  puts Awscli::Instances::REGIONS
end
list_sizes() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 11
def list_sizes
  puts Awscli::Instances::INSTANCE_SIZES
end
miatt() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 81
def miatt
  create_ec2_object
  opts = Marshal.load(Marshal.dump(options))  #create a copy of options, as original options hash cannot be modified
  opts.reject!{ |k| k == 'id' } #remove id from opts
  abort "Please pass an attribute by setting respective option" unless opts
  abort "You can only pass one attribute at a time" if opts.size != 1
  opts.each do |k,v|
    puts "calling modify_instance_attribute with: #{options[:id]}, #{k}, #{opts[k]}"
    @ec2.modify_instance_attribute(options[:id], k, opts[k])
  end

end
reboot() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 136
def reboot
  create_ec2_object
  @ec2.reboot_instance options[:instance_id]
end
riatt() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 98
def riatt
  puts "Not yet Implemented"
end
start() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 261
def start
  create_ec2_object
  @ec2.start_instance options[:instance_id]
end
stop() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 271
def stop
  create_ec2_object
  @ec2.stop_instance options[:instance_id]
end
terminate() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 281
def terminate
  create_ec2_object
  @ec2.terminate_instance options[:instance_id]
end
terminate_all() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 288
def terminate_all
  create_ec2_object
  @ec2.terminate_instances options[:delete_volumes]
end

Private Instance Methods

create_ec2_object() click to toggle source
# File lib/awscli/cli/ec2/instances.rb, line 302
def create_ec2_object
  puts "ec2 Establishing Connetion..."
  $ec2_conn = if parent_options[:region]
                Awscli::Connection.new.request_ec2(parent_options[:region])
              else
                Awscli::Connection.new.request_ec2
              end
  puts "ec2 Establishing Connetion... OK"
  @ec2 = Awscli::EC2::EC2.new($ec2_conn)
end