You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: ec2.rb
    path of file: ./repos/foreman/app/models/compute_resources/foreman/model
    
    the code of the file until where you have to start completion: module Foreman::Model
  class EC2 < ComputeResource
    GOV_CLOUD_REGION = 'us-gov-west-1'

    include KeyPairComputeResource
    delegate :flavors, :subnets, :to => :client
    validates :user, :password, :presence => true

    alias_attribute :access_key, :user
    alias_attribute :region, :url

    alias_method :available_flavors, :flavors

    def to_label
      "#{name} (#{region}-#{provider_friendly_name})"
    end

    def gov_cloud=(enable_gov_cloud)
      if enable_gov_cloud == '1'
        self.url ||= GOV_CLOUD_REGION
      elsif gov_cloud?
        self.url = nil
      end
    end

    def gov_cloud
      ['us-gov-west-1', 'us-gov-east-1'].include? url
    end
    alias_method :gov_cloud?, :gov_cloud

    def provided_attributes
      super.merge({ :ip => :vm_ip_address })
    end

    def self.available?
      Fog::Compute.providers.include?(:aws)
    end

    def self.model_name
      ComputeResource.model_name
    end

    def capabilities
      [:image]
    end

    def find_vm_by_uuid(uuid)
      super
    rescue Fog::AWS::Compute::Error
      raise(Act
    
    def normalize_vm_attrs(vm_attrs)
      normalized = slice_vm_attributes(vm_attrs, ['flavor_id', 'availability_zone', 'subnet_id', 'image_id', 'managed_ip'])

      normalized['flavor_name'] =  flavors.detect { |f| f.id == normalized['flavor_id'] }.try(:name)
      normalized['subnet_name'] =  subnets.detect { |f| f.subnet_id == normalized['subnet_id'] }.try(:cidr_block)
      normalized['image_name'] = images.find_by(:uuid => vm_attrs['image_id']).try(:name)

      group_ids = vm_attrs['security_group_ids'] || []
      group_ids = group_ids.select { |gid| gid != '' }
      normalized['security_groups'] = group_ids.map.with_index do |gid, idx|
        [idx.to_s, {
          'id' => gid,
          'name' => security_groups.detect { |g| g.group_id == gid }.try(:name),
        }]
      end.to_h

      normalized
    rescue Fog::AWS::Compute::Error => e
      Foreman::Logging.exception("Unhandled EC2 error", e)
      {}
    end

    private

    def subnet_implies_is_vpc?(args)
      args[:subnet_id].present?
    end

    def client
      self.url = region if gov_cloud
      @client ||= Fog::AWS::Compute.new(:aws_access_key_id => user, :aws_secret_access_key => password, :region => region, :connection_options => connection_options)
    end

    def vm_instance_defaults
      super.merge(
        :flavor_id => "m1.small",
        :key_pair  => key_pair
      )
    end
  end