lib/ec2/right_ec2_instances.rb
# Launch new EC2 instances.
# 
# Options: :image_id, :min_count, max_count, :key_name, :kernel_id, :ramdisk_id,
# :availability_zone, :monitoring_enabled, :subnet_id, :disable_api_termination, :instance_initiated_shutdown_behavior,
# :block_device_mappings, :placement_group_name, :license_pool, :group_ids, :group_names, :private_ip_address,
# :ebs_optimized
# 
# Returns a list of launched instances or an exception.
#
#  ec2.launch_instances( "ami-78779511",
#                        :min_count => 1,
#                        :group_names => ["default", "eugeg223123123"],
#                        :user_data => 'Ohoho!',
#                        :availability_zone => "us-east-1a",
#                        :disable_api_termination => false,
#                        :instance_initiated_shutdown_behavior => 'terminate',
#                        :block_device_mappings => [ {:ebs_snapshot_id=>"snap-e40fd188",
#                                                     :ebs_delete_on_termination=>true,
#                                                     :device_name => "/dev/sdk",
#                                                     :virtual_name => "mystorage"} ] ) #=>
#    [{:hypervisor=>"xen",
#      :private_dns_name=>"",
#      :client_token=>"1309532374-551037-gcsBj-gEypk-piG06-ODfQm",
#      :monitoring_state=>"disabled",
#      :aws_availability_zone=>"us-east-1a",
#      :root_device_name=>"/dev/sda1",
#      :state_reason_code=>"pending",
#      :dns_name=>"",
#      :tags=>{},
#      :aws_reason=>"",
#      :virtualization_type=>"paravirtual",
#      :state_reason_message=>"pending",
#      :aws_reservation_id=>"r-6fada703",
#      :aws_ramdisk_id=>"ari-a51cf9cc",
#      :ami_launch_index=>"0",
#      :groups=>
#       [{:group_id=>"sg-a0b85dc9", :group_name=>"default"},
#        {:group_id=>"sg-70733019", :group_name=>"eugeg223123123"}],
#      :aws_owner=>"826693181925",
#      :aws_instance_type=>"m1.small",
#      :aws_state=>"pending",
#      :root_device_type=>"ebs",
#      :aws_image_id=>"ami-78779511",
#      :aws_kernel_id=>"aki-a71cf9ce",
#      :aws_launch_time=>"2011-07-01T14:59:35.000Z",
#      :aws_state_code=>0,
#      :aws_instance_id=>"i-4f202621",
#      :aws_product_codes=>[]}]
#
Launch new EC2 instances.

Returns a list of launched instances or an exception.


Launch new EC2 instances . Returns a list of launched instances or an exception .
def launch_instances(image_id, options={})
      options[:user_data] = options[:user_data].to_s
      params = map_api_keys_and_values( options,
        :key_name, :kernel_id,
        :ramdisk_id, :subnet_id, :instance_initiated_shutdown_behavior,
        :private_ip_address, :additional_info, :license_pool, :ebs_optimized,
        :image_id                => { :value => image_id },
        :min_count               => { :value => options[:min_count] || 1 },
        :max_count               => { :value => options[:max_count] || options[:min_count] || 1 },
        :placement_tenancy       => 'Placement.Tenancy',
        :placement_group_name    => 'Placement.GroupName',
        :availability_zone       => 'Placement.AvailabilityZone',
        :group_names             => { :amazonize_list => 'SecurityGroup' },
        :group_ids               => { :amazonize_list => 'SecurityGroupId' },
        :block_device_mappings   => { :amazonize_bdm  => 'BlockDeviceMapping' },
        :instance_type           => { :value => options[:instance_type] || DEFAULT_INSTANCE_TYPE },
        :disable_api_termination => { :value => Proc.new{ !options[:disable_api_termination].nil? && options[:disable_api_termination].to_s }},
        :client_token            => { :value => !@params[:eucalyptus] && (options[:client_token] || AwsUtils::generate_unique_token)},
        :user_data               => { :value => Proc.new { !options[:user_data].empty? && Base64.encode64(options[:user_data]).delete("\n") }},
        :monitoring_enabled      => { :name  => 'Monitoring.Enabled',
                                      :value => Proc.new{ options[:monitoring_enabled] && options[:monitoring_enabled].to_s }})
      @logger.info("Launching instance of image {image_id}. Options: {params.inspect}")
      options[:options]                 ||= {}
      options[:options][:api_version]   ||= INSTANCE_API_VERSION
      params.delete("EbsOptimized") if options[:options][:api_version] < INSTANCE_API_VERSION
      link = generate_request("RunInstances", params, options[:options])
      instances = request_info(link, QEc2DescribeInstancesParser.new(:logger => @logger))
      get_desc_instances(instances)
    rescue Exception
      on_exception
    end
def launch_instances ( image_id , options = { } ) options [ :user_data ] = options [ :user_data ] . to_s params = map_api_keys_and_values ( options , :key_name , :kernel_id , :ramdisk_id , :subnet_id , :instance_initiated_shutdown_behavior , :private_ip_address , :additional_info , :license_pool , :ebs_optimized , :image_id => { :value => image_id } , :min_count => { :value => options [ :min_count ] || 1 } , :max_count => { :value => options [ :max_count ] || options [ :min_count ] || 1 } , :placement_tenancy => 'Placement.Tenancy' , :placement_group_name => 'Placement.GroupName' , :availability_zone => 'Placement.AvailabilityZone' , :group_names => { :amazonize_list => 'SecurityGroup' } , :group_ids => { :amazonize_list => 'SecurityGroupId' } , :block_device_mappings => { :amazonize_bdm => 'BlockDeviceMapping' } , :instance_type => { :value => options [ :instance_type ] || DEFAULT_INSTANCE_TYPE } , :disable_api_termination => { :value => Proc . new { ! options [ :disable_api_termination ] . nil? && options [ :disable_api_termination ] . to_s } } , :client_token => { :value => ! @params [ :eucalyptus ] && ( options [ :client_token ] || AwsUtils :: generate_unique_token ) } , :user_data => { :value => Proc . new { ! options [ :user_data ] . empty? && Base64 . encode64 ( options [ :user_data ] ) . delete ( "\n" ) } } , :monitoring_enabled => { :name => 'Monitoring.Enabled' , :value => Proc . new { options [ :monitoring_enabled ] && options [ :monitoring_enabled ] . to_s } } ) @logger . info ( "Launching instance of image #{image_id}. Options: #{params.inspect}" ) options [ :options ] ||= { } options [ :options ] [ :api_version ] ||= INSTANCE_API_VERSION params . delete ( "EbsOptimized" ) if options [ :options ] [ :api_version ] < INSTANCE_API_VERSION link = generate_request ( "RunInstances" , params , options [ :options ] ) instances = request_info ( link , QEc2DescribeInstancesParser . new ( :logger => @logger ) ) get_desc_instances ( instances ) rescue Exception on_exception end
Launch new EC2 instances.
Launch new EC2 instances .
# Log debug information # Add IOPS support (default behavior) but skip it when an old API version call is requested #
image_id
<not_specific>
options
<not_specific>