<%   
  def discover_external_ip
    networks = spec.networks.marshal_dump
    _, network = networks.find do |_name, network_spec|
      network_spec.default
    end

    _, network = networks.first unless network

    raise "Could not determine IP via network spec: #{networks}" unless network

    network.ip
  end
  my_ip = discover_external_ip

  proxy_ips = nil
  if_p('cf_mysql.proxy.proxy_ips') do |ips|
    proxy_ips = ips.compact
  end.else do
    proxy_ips= link('proxy').instances.map { |instance| instance.address }
  end
  proxy_index = proxy_ips.index(my_ip)
%>

<% if p("cf_mysql.standalone") == false %>
message_bus_servers:
<% p('nats.machines').each do |ip| %>
- host: <%= ip %>:<%= p('nats.port') %>
  user: <%= p('nats.user') %>
  password: <%= p('nats.password') %>
<% end %>
host: <%= my_ip %>
routes:
- name: "proxy_<%= index %>"
  port: <%= p('cf_mysql.proxy.api_port') %>
  uris:
  - proxy-<%= proxy_index %>-<%= p('cf_mysql.external_host') %>
  registration_interval: 10s
<% end %>

<%   
  def discover_external_ip
    networks = spec.networks.marshal_dump
    _, network = networks.find do |_name, network_spec|
      network_spec.default
    end

    _, network = networks.first unless network

    raise "Could not determine IP via network spec: #{networks}" unless network

    network.ip
  end
  my_ip = discover_external_ip

  proxy_ips = nil
  if_p('cf_mysql.proxy.proxy_ips') do |ips|
    proxy_ips = ips.compact
  end.else do
    proxy_ips= link('proxy').instances.map { |instance| instance.address }
  end
  proxy_index = proxy_ips.index(my_ip)
%>

<% if p("cf_mysql.standalone") == false %>
message_bus_servers:
<% p('nats.machines').each do |ip| %>
- host: <%= ip %>:<%= p('nats.port') %>
  user: <%= p('nats.user') %>
  password: <%= p('nats.password') %>
<% end %>
host: <%= my_ip %>
routes:
- name: "proxy_<%= proxy_index %>"
  port: <%= p('cf_mysql.proxy.api_port') %>
  uris:
  - proxy-<%= proxy_index %>-<%= p('cf_mysql.external_host') %>
  registration_interval: 10s
<% end %>

Use consistent indexing for proxy routes
Use consistent indexing for proxy routes

Signed-off-by: Joseph Palermo <e623ceb69d4eba908c7aa121d8a6c4c407e290f1@pivotal.io>
