How to access the IP of my other instance inside my app when configure for multiple instances

1k views Asked by At

Im going to deploy my application in BOSH and cluster it with n number of nodes. E.g., 2 So in my app, when I deploy the app in my manifest.yml I have defined below. So it starts at 10.244.15.21 and next node starts in 10.244.15.22 when give instances : 2 in my manifest.yml

static: - 10.244.15.2 - 10.244.15.20 

So in my each app I need to access each other nodes' IPs inside a XML file. How can i do this dynamically in a xml file. Please advice. Thanks

E.g.,

<parameter name="localMemberHost">127.0.0.1</parameter> 

<members> 
     <member> 
           <hostName>10.244.15.21</hostName>
           <port>4000</port> 
     </member> 
     <member> 
           <hostName>10.244.15.22</hostName> 
           <port>4000</port> 
     </member>

 </members>
1

There are 1 answers

0
Eddie On

Based on your sample you should be able to accomplish this using the combination of ERB evaluation of the job template, and a known range of IPs.

First define a specific range of IPs in your manifest matching the count for that job. You will need to increase the static reservations in the shared network definition to cover the .21 + range you need. Then the job uses an allotment of those static IPs. see https://bosh.io/docs/networks.html

jobs:
- name: clustered-job
  instances: 5
  templates:
    - name: jobname
      release: releasename
  networks:
  - name: default
    static_ips: [10.244.15.21 - 10.244.15.26] <-- you would need to make sure these are reserved in cloud config

I'm assuming the xml file in question is defined as a "template" in your job spec, this is required to enable the ERB evaluation using the properties available. https://bosh.io/docs/jobs.html#templates https://bosh.io/docs/jobs.html#properties

You'll use a loop and a few known properties to define all cluster members.

 <%= spec.networks.default.static_ips %>

To make the loop ingest whatever is specified in the manifest. You may want to add a property for the job to specify starting IP, as I forget if above gives you the IPS for the entire manifest, or just the job (I think its the latter).

<% @spec.networks.default.static_ips.each do |static_ip| %>
    <member> 
           <hostName><%= static_ip %></hostName>
           <port>4000</port> 
     </member>
<% end %>

You can also check spec.ip for the IP of current instance if you need to exclude that from the loop.