Skip to content
This repository has been archived by the owner on Aug 4, 2018. It is now read-only.

Commit

Permalink
provision with a second backend network for cluster communication
Browse files Browse the repository at this point in the history
  • Loading branch information
ewdurbin committed Nov 23, 2013
1 parent c99297e commit 38f69a3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Vagrant.configure("2") do |config|

config.vm.define "pg_master" do |pg_master|
pg_master.vm.network "private_network", ip: "192.168.57.5"
pg_master.vm.network "private_network", ip: "10.10.10.5"

pg_master.vm.provision :salt do |s|
s.verbose = true
Expand All @@ -51,6 +52,7 @@ Vagrant.configure("2") do |config|

config.vm.define "pg_slave" do |pg_slave|
pg_slave.vm.network "private_network", ip: "192.168.57.6"
pg_slave.vm.network "private_network", ip: "10.10.10.6"

pg_slave.vm.provision :salt do |s|
s.verbose = true
Expand Down
2 changes: 2 additions & 0 deletions provisioning/salt/roots/pillar/networking.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

pypi_internal_network: 10.10.10.0/24
4 changes: 2 additions & 2 deletions provisioning/salt/roots/pillar/postgresql/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ firewall:
- 5432

postgresql_cluster:
primary_server: 192.168.57.5
primary_server: 10.10.10.5
standby_servers:
- 192.168.57.6
- 10.10.10.6
4 changes: 4 additions & 0 deletions provisioning/salt/roots/pillar/top.sls
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
base:

'*':
- networking

'roles:pypi-mirror':
- match: grain
- pypi-mirror
Expand Down
32 changes: 32 additions & 0 deletions provisioning/salt/roots/salt/_modules/ip_picker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import salt

def __virtual__():
'''
Only work on POSIX-like systems
'''
# Disable on Windows, a specific file module exists:
if salt.utils.is_windows():
return False

return True

def ip_addrs(interface=None, include_loopback=False, cidr=None):
'''
Returns a list of IPv4 addresses assigned to the host. 127.0.0.1 is
ignored, unless 'include_loopback=True' is indicated. If 'interface' is
provided, then only IP addresses from that interface will be returned.
Providing a CIDR via 'cidr="10.0.0.0/8"' will return only the addresses
which are within that subnet.
CLI Example:
.. code-block:: bash
salt '*' network.ip_addrs
'''
addrs = salt.utils.network.ip_addrs(interface=interface,
include_loopback=include_loopback)
if cidr:
return [i for i in addrs if salt.utils.network.in_subnet(cidr, [i])]
else:
return addrs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ lc_numeric = 'en_US.UTF-8'
lc_time = 'en_US.UTF-8'
default_text_search_config = 'pg_catalog.english'

listen_addresses = '*'
{% set internal = salt['pillar.get']('pypi_internal_network') %}
listen_addresses = '{{ salt['ip_picker.ip_addrs'](cidr=internal)[0] }},127.0.01'

{% if 'master' in grains['roles'] %}
# Master
Expand Down

0 comments on commit 38f69a3

Please sign in to comment.