lib/beaker/hypervisor/aws_sdk.rb
# Launch all nodes
#
# This is where the main launching work occurs for each node. Here we take
# care of feeding the information from the image required into the config
# for the new host, we perform the launch operation and ensure that the
# instance is properly tagged for identification.
#
# @return [void]
# @api private
Launch all nodes
This is where the main launching work occurs for each node. Here we take
care of feeding the information from the image required into the config
for the new host, we perform the launch operation and ensure that the
instance is properly tagged for identification.
Launch all nodes This is where the main launching work occurs for each node . Here we take care of feeding the information from the image required into the config for the new host we perform the launch operation and ensure that the instance is properly tagged for identification .
def launch_all_nodes
      ami_spec = YAML.load_file(@options[:ec2_yaml])["AMI"]
      @logger.notify("aws-sdk: Iterate across all hosts in configuration and launch them")
      @hosts.each do |host|
        amitype = host['vmname'] || host['platform']
        amisize = host['amisize'] || 'm1.small'
        subnet_id = host['subnet_id'] || nil
        vpc_id = host['vpc_id'] || nil
        if vpc_id and !subnet_id
          raise RuntimeError, "A subnet_id must be provided with a vpc_id"
        end
        image_type = host['snapshot']
        if not image_type
          raise RuntimeError, "No snapshot/image_type provided for EC2 provisioning"
        end
        ami = ami_spec[amitype]
        ami_region = ami[:region]
        region = @ec2.regions[ami_region]
        vpc = vpc_id ? region.vpcs[vpc_id] : nil
        image_id = ami[:image][image_type.to_sym]
        @logger.notify("aws-sdk: Checking image #{image_id} exists and getting its root device")
        image = region.images[image_id]
        if image.nil? and not image.exists?
          raise RuntimeError, "Image not found: #{image_id}"
        end
        orig_bdm = image.block_device_mappings()
        @logger.notify("aws-sdk: Image block_device_mappings: #{orig_bdm.to_hash}")
        block_device_mappings = []
        orig_bdm.each do |device_name, rest|
          block_device_mappings << {
            :device_name => device_name,
            :ebs => {
              :delete_on_termination => true,
            }
          }
        end
        @logger.notify("aws-sdk: Launch instance")
        config = {
          :count => 1,
          :image_id => image_id,
          :monitoring_enabled => true,
          :key_pair => ensure_key_pair(region),
          :security_groups => [ensure_group(vpc || region, Beaker::EC2Helper.amiports(host))],
          :instance_type => amisize,
          :disable_api_termination => false,
          :instance_initiated_shutdown_behavior => "terminate",
          :block_device_mappings => block_device_mappings,
          :subnet => subnet_id,
        }
        instance = region.instances.create(config)
        host['instance'] = instance
        @logger.notify("aws-sdk: Launched #{host.name} (#{amitype}:#{amisize}) using snapshot/image_type #{image_type}")
      end
      nil
    end
def launch_all_nodes ami_spec = YAML . load_file ( @options [ :ec2_yaml ] ) [ "AMI" ] @logger . notify ( "aws-sdk: Iterate across all hosts in configuration and launch them" ) @hosts . each do | host | amitype = host [ 'vmname' ] || host [ 'platform' ] amisize = host [ 'amisize' ] || 'm1.small' subnet_id = host [ 'subnet_id' ] || nil vpc_id = host [ 'vpc_id' ] || nil if vpc_id and ! subnet_id raise RuntimeError , "A subnet_id must be provided with a vpc_id" end image_type = host [ 'snapshot' ] if not image_type raise RuntimeError , "No snapshot/image_type provided for EC2 provisioning" end ami = ami_spec [ amitype ] ami_region = ami [ :region ] region = @ec2 . regions [ ami_region ] vpc = vpc_id ? region . vpcs [ vpc_id ] : nil image_id = ami [ :image ] [ image_type . to_sym ] @logger . notify ( "aws-sdk: Checking image #{image_id} exists and getting its root device" ) image = region . images [ image_id ] if image . nil? and not image . exists? raise RuntimeError , "Image not found: #{image_id}" end orig_bdm = image . block_device_mappings ( ) @logger . notify ( "aws-sdk: Image block_device_mappings: #{orig_bdm.to_hash}" ) block_device_mappings = [ ] orig_bdm . each do | device_name , rest | block_device_mappings << { :device_name => device_name , :ebs => { :delete_on_termination => true , } } end @logger . notify ( "aws-sdk: Launch instance" ) config = { :count => 1 , :image_id => image_id , :monitoring_enabled => true , :key_pair => ensure_key_pair ( region ) , :security_groups => [ ensure_group ( vpc || region , Beaker :: EC2Helper . amiports ( host ) ) ] , :instance_type => amisize , :disable_api_termination => false , :instance_initiated_shutdown_behavior => "terminate" , :block_device_mappings => block_device_mappings , :subnet => subnet_id , } instance = region . instances . create ( config ) host [ 'instance' ] = instance @logger . notify ( "aws-sdk: Launched #{host.name} (#{amitype}:#{amisize}) using snapshot/image_type #{image_type}" ) end nil end
Launch all nodes
This is where the main launching work occurs for each node.
Launch all nodes This is where the main launching work occurs for each node .
# Load the ec2_yaml spec file # Iterate across all hosts and launch them, adding tags along the way # Use snapshot provided for this host # Main region object for ec2 operations # Obtain the VPC object if it exists # Grab image object # Transform the images block_device_mappings output into a format # ready for a create. # This is required to override the images default for # delete_on_termination, forcing all volumes to be deleted once the # instance is terminated. # Launch the node, filling in the blanks from previous work. # Persist the instance object for this host, so later it can be # manipulated by 'cleanup' for example.
None
void
api
None