Skip to content

Commit 96ae777

Browse files
committed
1) Use private network and static IPs for all vagrant VMs. 2) Use
'knife edit' in provision script to override the ipaddress for the Controller so that subseuent nodes have the correct rsyslog server address. 3) Use hostname of the host machine to connect to it over SSH form the Controller, this gets around IP address changes. But it means use must have avahi-daemon running.
1 parent 28e395a commit 96ae777

5 files changed

Lines changed: 19 additions & 20 deletions

File tree

Vagrantfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ Vagrant.configure("2") do |config|
1111
# Avahi-daemon will broadcast the server's address as deis-controller.local
1212
config.vm.host_name = "deis-controller"
1313

14-
# Create a public network, which generally matched to bridged network.
15-
# Bridged networks make the machine appear as another physical device on
16-
# your network. IP will be fetched via DCHP and associated to 'chefserver.local'
17-
# using avahi-daemon
18-
config.vm.network :public_network
14+
# IP will be associated to 'chefserver.local' using avahi-daemon
15+
config.vm.network :private_network, ip: "192.168.61.100"
1916

2017
# Chef Server requires at least 1G of RAM to install.
2118
# You may be able to run it with less once it's installed.

client/deis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,7 @@ def providers_discover(self, args): # noqa
17691769
print("Detected locally running Deis Controller VM")
17701770
# In order for the Controller to be able to boot Vagrant VMs it needs to run commands
17711771
# on the host machine. It does this via an SSH server. In order to access that server
1772-
# we need to send the current user's name and IP address.
1772+
# we need to send the current user's name and host.
17731773
try:
17741774
user = subprocess.check_output(
17751775
"whoami",
@@ -1781,7 +1781,7 @@ def providers_discover(self, args): # noqa
17811781
shell=True
17821782
).strip()
17831783
except subprocess.CalledProcessError:
1784-
print("Error detecting username and host IP address.")
1784+
print("Error detecting username and host address.")
17851785
sys.exit(1)
17861786
creds = {
17871787
'user': user,

contrib/vagrant/nodes_vagrantfile_template.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
# Avahi-daemon will broadcast the node's address as $id.local
99
config.vm.host_name = "$id"
1010

11-
# Create a public network, which generally matched to bridged network.
12-
# Bridged networks make the machine appear as another physical device on
13-
# your network. IP will be fetched via DCHP and associated to '$id.local'
14-
# using avahi-daemon
15-
config.vm.network :public_network
11+
# IP will be associated to '$id.local' using avahi-daemon
12+
config.vm.network :private_network, ip: "$ipaddress"
1613

1714
config.vm.provider :virtualbox do |vb|
1815
vb.customize ["modifyvm", :id, "--memory", "$memory"]

contrib/vagrant/provision-controller.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ if [ ! -f /etc/ssh/sshd_config ] && [ ! -f /etc/sshd_config ]; then
2020
exit 1
2121
fi
2222

23-
# Make sure avahi-daemon is installed
24-
if ! which avahi-daemon > /dev/null; then
23+
# Make sure avahi-daemon is installed and running
24+
if ! pgrep avahi-daemon >/dev/null; then
2525
echo 'Please install avahi-daemon to broadcast your hostname to the local network.'
2626
exit 1
2727
fi
@@ -104,11 +104,11 @@ set +x
104104
# The IP address detected by Chef is the VM's eth0 10.0.0.0 range address.
105105
# However we need the 192 range address set on eth1.
106106
echo_color "Updating the IP address stored on the Chef Server for the Deis Controller node..."
107-
ipaddress=$(ping -c1 deis-controller.local | head -n1 | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')
108-
knife exec -E "nodes.transform(\"name:deis-controller\") { \
109-
|n| n.normal_attrs[\"network\"][\"ipaddress\"] = "$ipaddress"; \
110-
n.save \
111-
}"
107+
knife exec -E 'nodes.transform("name:deis-controller") { |n|
108+
n.automatic_attrs["ipaddress"] = "192.168.61.100"
109+
n.save
110+
}'
111+
112112
if [ $? -eq 0 ]; then
113113
echo_color "IP address updated."
114114
fi

provider/vagrant.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import uuid
1313

1414
from api.models import Layer
15+
from api.models import Node
1516

1617
# Collect details for connecting to the host machine
1718
HOST_NODES_DIR = open('/home/vagrant/.host_nodes_dir').read().strip()
@@ -72,7 +73,11 @@ def build_node(node):
7273
node['params'].setdefault('memory', '512')
7374
template = open('/opt/deis/controller/contrib/vagrant/nodes_vagrantfile_template.rb')
7475
raw = string.Template(template.read())
75-
result = raw.substitute({'id': uid, 'memory': node['params']['memory']})
76+
result = raw.substitute({
77+
'id': uid,
78+
'ipaddress': '192.168.61.' + str(Node.objects.all().count() + 100),
79+
'memory': node['params']['memory']
80+
})
7681

7782
# Make a folder for the VM with its own Vagrantfile. Vagrant will then create a .vagrant folder
7883
# there too when it first gets booted.

0 commit comments

Comments
 (0)