<commit_before>require 'fog/compute/models/server'

module Fog
  module Compute
    class AWS

      class SpotRequest < Fog::Compute::Server

        identity :id,                          :aliases => 'spotInstanceRequestId'

        attribute :price,                      :aliases => 'spotPrice'
        attribute :request_type,               :aliases => 'type'
        attribute :created_at,                 :aliases => 'createTime'
        attribute :instance_count,             :aliases => 'instanceCount'
        attribute :instance_id,                :aliases => 'instanceId'
        attribute :state

        attribute :valid_from,                 :aliases => 'validFrom'
        attribute :valid_until,                :aliases => 'validUntil'
        attribute :launch_group,               :aliases => 'launchGroup'
        attribute :availability_zone_group,    :aliases => 'availabilityZoneGroup'
        attribute :product_description,        :aliases => 'productDescription'

        attribute :ebs_optimized,              :aliases => 'LaunchSpecification.EbsOptimized'
        attribute :groups,                     :aliases => 'LaunchSpecification.SecurityGroup'
        attribute :key_name,                   :aliases => 'LaunchSpecification.KeyName'
        attribute :availability_zone,          :aliases => 'LaunchSpecification.Placement.AvailabilityZone'
        attribute :flavor_id,                  :aliases => 'LaunchSpecification.InstanceType'
        attribute :image_id,                   :aliases => 'LaunchSpecification.ImageId'
        attribute :monitoring,                 :aliases => 'LaunchSpecification.Monitoring'
        attribute :block_device_mapping,       :aliases => 'LaunchSpecification.BlockDeviceMapping'
        attribute :subnet_id,                  :aliases => 'LaunchSpecification.SubnetId'
        attribute :iam_instance_profile,       :aliases => 'LaunchSpecification.IamInstanceProfile'

        attribute :tags,                       :aliases => 'tagSet'
        attribute :fault,                      :squash  => 'message'
        attribute :user_data

        attr_writer   :iam_instance_profile_name, :iam_instance_profile_arn

        def initialize(attributes={})
          self.groups ||= ["default"]
          self.flavor_id ||= 't1.micro'
          self.image_id   ||= begin
            self.username = 'ubuntu'

            # Old 'connection' is renamed as service and should be used instead
            prepare_service_value(attributes)

            case @service.instance_variable_get(:@region) # Ubuntu 10.04 LTS 64bit (EBS)
            when 'ap-northeast-1'
              'ami-5e0fa45f'
            when 'ap-southeast-1'
              'ami-f092eca2'
            when 'eu-west-1'
              'ami-3d1f2b49'
            when 'us-east-1'
              'ami-3202f25b'
            when 'us-west-1'
              'ami-f5bfefb0'
            end
          end
          super
        end<commit_msg>Allows custom username for aws spot instances<commit_after>require 'fog/compute/models/server'

module Fog
  module Compute
    class AWS

      class SpotRequest < Fog::Compute::Server

        identity :id,                          :aliases => 'spotInstanceRequestId'

        attribute :price,                      :aliases => 'spotPrice'
        attribute :request_type,               :aliases => 'type'
        attribute :created_at,                 :aliases => 'createTime'
        attribute :instance_count,             :aliases => 'instanceCount'
        attribute :instance_id,                :aliases => 'instanceId'
        attribute :state

        attribute :valid_from,                 :aliases => 'validFrom'
        attribute :valid_until,                :aliases => 'validUntil'
        attribute :launch_group,               :aliases => 'launchGroup'
        attribute :availability_zone_group,    :aliases => 'availabilityZoneGroup'
        attribute :product_description,        :aliases => 'productDescription'

        attribute :ebs_optimized,              :aliases => 'LaunchSpecification.EbsOptimized'
        attribute :groups,                     :aliases => 'LaunchSpecification.SecurityGroup'
        attribute :key_name,                   :aliases => 'LaunchSpecification.KeyName'
        attribute :availability_zone,          :aliases => 'LaunchSpecification.Placement.AvailabilityZone'
        attribute :flavor_id,                  :aliases => 'LaunchSpecification.InstanceType'
        attribute :image_id,                   :aliases => 'LaunchSpecification.ImageId'
        attribute :monitoring,                 :aliases => 'LaunchSpecification.Monitoring'
        attribute :block_device_mapping,       :aliases => 'LaunchSpecification.BlockDeviceMapping'
        attribute :subnet_id,                  :aliases => 'LaunchSpecification.SubnetId'
        attribute :iam_instance_profile,       :aliases => 'LaunchSpecification.IamInstanceProfile'

        attribute :tags,                       :aliases => 'tagSet'
        attribute :fault,                      :squash  => 'message'
        attribute :user_data

        attr_writer   :iam_instance_profile_name, :iam_instance_profile_arn

        def initialize(attributes={})
          self.groups ||= ["default"]
          self.flavor_id ||= 't1.micro'
          self.image_id   ||= begin
            self.username ||= 'ubuntu'

            # Old 'connection' is renamed as service and should be used instead
            prepare_service_value(attributes)

            case @service.instance_variable_get(:@region) # Ubuntu 10.04 LTS 64bit (EBS)
            when 'ap-northeast-1'
              'ami-5e0fa45f'
            when 'ap-southeast-1'
              'ami-f092eca2'
            when 'eu-west-1'
              'ami-3d1f2b49'
            when 'us-east-1'
              'ami-3202f25b'
            when 'us-west-1'
              'ami-f5bfefb0'
            end
          end
          super
        end
{'fraction_non_alphanumeric': 0.0903594222371515, 'fraction_numerical': 0.011084984884111521, 'mean_word_length': 1.810287871637565, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3094966', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1517, 'n_words': 321}