vendor/bundle/ruby/1.8/gems/aws-2.5.6/lib/ec2/ec2.rb
def launch_instances(image_id, options={})
      @logger.info("Launching instance of image #{image_id} for #{@aws_access_key_id}, " +
                       "key: #{options[:key_name]}, groups: #{(options[:group_ids]).to_a.join(',')}")
      # careful: keyName and securityGroups may be nil
      params = hash_params('SecurityGroup', options[:group_ids].to_a)
      params.update({'ImageId'        => image_id,
                     'MinCount'       => (options[:min_count] || 1).to_s,
                     'MaxCount'       => (options[:max_count] || 1).to_s,
                     'AddressingType' => options[:addressing_type] || DEFAULT_ADDRESSING_TYPE,
                     'InstanceType'   => options[:instance_type] || DEFAULT_INSTANCE_TYPE})
      # optional params
      params['KeyName'] = options[:key_name] unless Aws::Utils.blank?(options[:key_name])
      params['KernelId'] = options[:kernel_id] unless Aws::Utils.blank?(options[:kernel_id])
      params['RamdiskId'] = options[:ramdisk_id] unless Aws::Utils.blank?(options[:ramdisk_id])
      params['Placement.AvailabilityZone'] = options[:availability_zone] unless Aws::Utils.blank?(options[:availability_zone])
      params['BlockDeviceMappings'] = options[:block_device_mappings] unless Aws::Utils.blank?(options[:block_device_mappings])
      params['Monitoring.Enabled'] = options[:monitoring_enabled] unless Aws::Utils.blank?(options[:monitoring_enabled])
      params['SubnetId'] = options[:subnet_id] unless Aws::Utils.blank?(options[:subnet_id])
      params['AdditionalInfo'] = options[:additional_info] unless Aws::Utils.blank?(options[:additional_info])
      params['DisableApiTermination'] = options[:disable_api_termination].to_s unless options[:disable_api_termination].nil?
      params['InstanceInitiatedShutdownBehavior'] = options[:instance_initiated_shutdown_behavior] unless Aws::Utils.blank?(options[:instance_initiated_shutdown_behavior])
      unless Aws::Utils.blank?(options[:user_data])
        options[:user_data].strip!
        # Do not use CGI::escape(encode64(...)) as it is done in Amazons EC2 library.
        # Amazon 169.254.169.254 does not like escaped symbols!
        # And it doesn't like "\n" inside of encoded string! Grrr....
        # Otherwise, some of UserData symbols will be lost...
        params['UserData'] = Base64.encode64(options[:user_data]).delete("\n").strip unless Aws::Utils.blank?(options[:user_data])
      end
      unless Aws::Utils.blank?(options[:block_device_mappings])
        options[:block_device_mappings].size.times do |n|
          if options[:block_device_mappings][n][:virtual_name]
            params["BlockDeviceMapping.#{n+1}.VirtualName"] = options[:block_device_mappings][n][:virtual_name] 
          end
          if options[:block_device_mappings][n][:device_name]
            params["BlockDeviceMapping.#{n+1}.DeviceName"] = options[:block_device_mappings][n][:device_name]  
          end
          if options[:block_device_mappings][n][:ebs_snapshot_id]
            params["BlockDeviceMapping.#{n+1}.Ebs.SnapshotId"] = options[:block_device_mappings][n][:ebs_snapshot_id]  
          end
        end
      end
      link      = generate_request("RunInstances", params)
      #debugger
      instances = request_info(link, QEc2DescribeInstancesParser.new(:logger => @logger))
      get_desc_instances(instances)
    rescue Exception
      on_exception
    end
# Launch new EC2 instances. Returns a list of launched instances or an exception.
#
# +lparams+ keys (default values in parenthesis):
#  :min_count              fixnum, (1)
#  :max_count              fixnum, (1)
#  :group_ids              array or string ([] == 'default')
#  :instance_type          string (DEFAULT_INSTACE_TYPE)
#  :addressing_type        string (DEFAULT_ADDRESSING_TYPE
#  :key_name               string
#  :kernel_id              string
#  :ramdisk_id             string
#  :availability_zone      string
#  :block_device_mappings  string
#  :user_data              string
#  :monitoring_enabled     boolean (default=false)
#
#  ec2.launch_instances('ami-e444444d', :group_ids => 'my_awesome_group',
#                                       :user_data => "Woohoo!!!",
#                                       :addressing_type => "public",
#                                       :key_name => "my_awesome_key",
#                                       :availability_zone => "us-east-1c") #=>
#   [{:aws_image_id       => "ami-e444444d",
#     :aws_reason         => "",
#     :aws_state_code     => "0",
#     :aws_owner          => "000000000888",
#     :aws_instance_id    => "i-123f1234",
#     :aws_reservation_id => "r-aabbccdd",
#     :aws_state          => "pending",
#     :dns_name           => "",
#     :ssh_key_name       => "my_awesome_key",
#     :aws_groups         => ["my_awesome_group"],
#     :private_dns_name   => "",
#     :aws_instance_type  => "m1.small",
#     :aws_launch_time    => "2008-1-1T00:00:00.000Z",
#     :aws_ramdisk_id     => "ari-8605e0ef"
#     :aws_kernel_id      => "aki-9905e0f0",
#     :ami_launch_index   => "0",
#     :aws_availability_zone => "us-east-1c"
#     }]
#
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={})
      @logger.info("Launching instance of image #{image_id} for #{@aws_access_key_id}, " +
                       "key: #{options[:key_name]}, groups: #{(options[:group_ids]).to_a.join(',')}")
      params = hash_params('SecurityGroup', options[:group_ids].to_a)
      params.update({'ImageId'        => image_id,
                     'MinCount'       => (options[:min_count] || 1).to_s,
                     'MaxCount'       => (options[:max_count] || 1).to_s,
                     'AddressingType' => options[:addressing_type] || DEFAULT_ADDRESSING_TYPE,
                     'InstanceType'   => options[:instance_type] || DEFAULT_INSTANCE_TYPE})
      params['KeyName'] = options[:key_name] unless Aws::Utils.blank?(options[:key_name])
      params['KernelId'] = options[:kernel_id] unless Aws::Utils.blank?(options[:kernel_id])
      params['RamdiskId'] = options[:ramdisk_id] unless Aws::Utils.blank?(options[:ramdisk_id])
      params['Placement.AvailabilityZone'] = options[:availability_zone] unless Aws::Utils.blank?(options[:availability_zone])
      params['BlockDeviceMappings'] = options[:block_device_mappings] unless Aws::Utils.blank?(options[:block_device_mappings])
      params['Monitoring.Enabled'] = options[:monitoring_enabled] unless Aws::Utils.blank?(options[:monitoring_enabled])
      params['SubnetId'] = options[:subnet_id] unless Aws::Utils.blank?(options[:subnet_id])
      params['AdditionalInfo'] = options[:additional_info] unless Aws::Utils.blank?(options[:additional_info])
      params['DisableApiTermination'] = options[:disable_api_termination].to_s unless options[:disable_api_termination].nil?
      params['InstanceInitiatedShutdownBehavior'] = options[:instance_initiated_shutdown_behavior] unless Aws::Utils.blank?(options[:instance_initiated_shutdown_behavior])
      unless Aws::Utils.blank?(options[:user_data])
        options[:user_data].strip!
        params['UserData'] = Base64.encode64(options[:user_data]).delete("\n").strip unless Aws::Utils.blank?(options[:user_data])
      end
      unless Aws::Utils.blank?(options[:block_device_mappings])
        options[:block_device_mappings].size.times do |n|
          if options[:block_device_mappings][n][:virtual_name]
            params["BlockDeviceMapping.#{n+1}.VirtualName"] = options[:block_device_mappings][n][:virtual_name] 
          end
          if options[:block_device_mappings][n][:device_name]
            params["BlockDeviceMapping.#{n+1}.DeviceName"] = options[:block_device_mappings][n][:device_name]  
          end
          if options[:block_device_mappings][n][:ebs_snapshot_id]
            params["BlockDeviceMapping.#{n+1}.Ebs.SnapshotId"] = options[:block_device_mappings][n][:ebs_snapshot_id]  
          end
        end
      end
      link      = generate_request("RunInstances", params)
      instances = request_info(link, QEc2DescribeInstancesParser.new(:logger => @logger))
      get_desc_instances(instances)
    rescue Exception
      on_exception
    end
def launch_instances ( image_id , options = { } ) @logger . info ( "Launching instance of image #{image_id} for #{@aws_access_key_id}, " + "key: #{options[:key_name]}, groups: #{(options[:group_ids]).to_a.join(',')}" ) params = hash_params ( 'SecurityGroup' , options [ :group_ids ] . to_a ) params . update ( { 'ImageId' => image_id , 'MinCount' => ( options [ :min_count ] || 1 ) . to_s , 'MaxCount' => ( options [ :max_count ] || 1 ) . to_s , 'AddressingType' => options [ :addressing_type ] || DEFAULT_ADDRESSING_TYPE , 'InstanceType' => options [ :instance_type ] || DEFAULT_INSTANCE_TYPE } ) params [ 'KeyName' ] = options [ :key_name ] unless Aws :: Utils . blank? ( options [ :key_name ] ) params [ 'KernelId' ] = options [ :kernel_id ] unless Aws :: Utils . blank? ( options [ :kernel_id ] ) params [ 'RamdiskId' ] = options [ :ramdisk_id ] unless Aws :: Utils . blank? ( options [ :ramdisk_id ] ) params [ 'Placement.AvailabilityZone' ] = options [ :availability_zone ] unless Aws :: Utils . blank? ( options [ :availability_zone ] ) params [ 'BlockDeviceMappings' ] = options [ :block_device_mappings ] unless Aws :: Utils . blank? ( options [ :block_device_mappings ] ) params [ 'Monitoring.Enabled' ] = options [ :monitoring_enabled ] unless Aws :: Utils . blank? ( options [ :monitoring_enabled ] ) params [ 'SubnetId' ] = options [ :subnet_id ] unless Aws :: Utils . blank? ( options [ :subnet_id ] ) params [ 'AdditionalInfo' ] = options [ :additional_info ] unless Aws :: Utils . blank? ( options [ :additional_info ] ) params [ 'DisableApiTermination' ] = options [ :disable_api_termination ] . to_s unless options [ :disable_api_termination ] . nil? params [ 'InstanceInitiatedShutdownBehavior' ] = options [ :instance_initiated_shutdown_behavior ] unless Aws :: Utils . blank? ( options [ :instance_initiated_shutdown_behavior ] ) unless Aws :: Utils . blank? ( options [ :user_data ] ) options [ :user_data ] . strip! params [ 'UserData' ] = Base64 . encode64 ( options [ :user_data ] ) . delete ( "\n" ) . strip unless Aws :: Utils . blank? ( options [ :user_data ] ) end unless Aws :: Utils . blank? ( options [ :block_device_mappings ] ) options [ :block_device_mappings ] . size . times do | n | if options [ :block_device_mappings ] [ n ] [ :virtual_name ] params [ "BlockDeviceMapping.#{n+1}.VirtualName" ] = options [ :block_device_mappings ] [ n ] [ :virtual_name ] end if options [ :block_device_mappings ] [ n ] [ :device_name ] params [ "BlockDeviceMapping.#{n+1}.DeviceName" ] = options [ :block_device_mappings ] [ n ] [ :device_name ] end if options [ :block_device_mappings ] [ n ] [ :ebs_snapshot_id ] params [ "BlockDeviceMapping.#{n+1}.Ebs.SnapshotId" ] = options [ :block_device_mappings ] [ n ] [ :ebs_snapshot_id ] end end end link = generate_request ( "RunInstances" , params ) 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 .
# careful: keyName and securityGroups may be nil # optional params # Do not use CGI::escape(encode64(...)) as it is done in Amazons EC2 library. # Amazon 169.254.169.254 does not like escaped symbols! # And it doesn't like "\n" inside of encoded string! Grrr.... # Otherwise, some of UserData symbols will be lost... #debugger
image_id
options