These are chat archives for fog/fog-aws

9th
Mar 2017
phanindrakalva
@phanindrakalva
Mar 09 2017 19:53

We are seeing below error when ever we try to create instances in AWS. Sometime it succeeds but most of the time it is throwing error. If we try to create 5 nodes it creates, 1 or 2 and fails on other.

Failure/Error: conn.servers.length
Excon::Error::Socket:
XML declaration allowed only at the start of the document (Nokogiri::XML::SyntaxError)


      Fog::Compute.new(
        :provider               => 'AWS',
        :region                 => @region,
         :use_iam_profile              => true
      )
 def valid_connection?(conn)
     conn.servers.length
     true
   rescue Excon::Errors::Forbidden, Excon::Errors::Unauthorized, Fog::Compute::AWS::Error
     false
   end
This is how I call create_instance method


servers = aws.create_servers!(
      conn,
      nodes,
      {
        os_type: ENV['OS_TYPE'],
        key: ENV['KEY_NAME'],
        security_group_ids: [ENV['SECURITY_GROUP_ID']],
        subnet_id: ENV['SUBNET_ID'],
        num_of_vols: 2,
        vol_size: 250,
        flavor_id: ENV['FLAVOR_ID'],
        instance_tag: cluster_name,
        availability_zone: 'us-west-2a'
      }
    )

def create_server!(conn, instance_tag, opts = {})
  options = {
      :key => 'test',
      :security_group_ids => %w(sg-xxxxxx),
      :flavor_id => 'm4.2xlarge',
      :os_type => 'ubuntu',
      :num_of_vols => 2,
      :vol_size => 200,
      :root_vol_size => 50,
      :vol_type => 'ebs',
      :iops => 0
  }.merge(opts)

  unless valid_connection?(conn)
    @log.error 'Unable to authenticate with AWS, check your credentials'
    exit 2
  end

  case options[:os_type].downcase
  when 'ubuntu'
    server = create_server(
      conn,
      options[:key],
      instance_tag,
      options[:security_group_ids],
      options[:flavor_id],
      @ubuntu_amis[@region],
      options[:subnet_id],
      options[:private_dns_name],
      :num_of_vols => options[:num_of_vols],
      :vol_size => options[:vol_size],
      :root_ebs_size => options[:root_vol_size],
      :vol_type => options[:vol_type],
      :iops => options[:iops]
    )
    return server
  else
    @log.error 'Provided OS not supported yet!'
    exit 2
  end
end

I tried to enable the debug logging as well but it does not show much info.