Skip to content

Commit b467998

Browse files
author
Gabriel Monroy
committed
fix vagrant provider in containerized env by using ip_addr instead of avahi hostnames
1 parent bd2ba0a commit b467998

4 files changed

Lines changed: 17 additions & 18 deletions

File tree

Vagrantfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ Vagrant.configure("2") do |config|
1515
vb.customize ["modifyvm", :id, "--memory", "2048"]
1616
end
1717

18+
# 'deis provider:discover' detects the host machine's user and IP address, however, that command cannot
19+
# be guareteed to run inside the deis codebase. Therefore we can't use that opportunity to discover
20+
# the path of the codebase on the host machine. Therefore we do it now as this Vagrantfile has to exist
21+
# inside the codebase.
22+
nodes_dir = File.dirname(__FILE__) + '/contrib/vagrant/nodes'
23+
1824
config.vm.provision :shell, inline: <<-SCRIPT
1925
# install latest stable chef for subsequent provision blocks
2026
sudo apt-get install -yq curl
@@ -24,6 +30,8 @@ Vagrant.configure("2") do |config|
2430
# Avahi-daemon broadcasts the machine's hostname to local DNS.
2531
# Therefore 'deis-controller.local' in this case.
2632
sudo apt-get install -yq avahi-daemon
33+
# Make a record of where the deis code base is on the host machine
34+
echo "#{nodes_dir}" > /home/vagrant/.host_nodes_dir
2735
SCRIPT
2836

2937
# load chef config from ~/.chef/knife.rb (requires `vagrant plugin install chef`)

client/deis.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ def config_list(self, args):
814814
width = max(map(len, keys)) + 5
815815
for k in keys:
816816
v = values[k]
817-
print(("{k:<"+str(width)+"} {v}").format(**locals()))
817+
print(("{k:<" + str(width) + "} {v}").format(**locals()))
818818
else:
819819
output = []
820820
for k in keys:
@@ -1907,19 +1907,12 @@ def providers_discover(self, args): # noqa
19071907
"whoami",
19081908
stderr=subprocess.PIPE
19091909
).strip()
1910-
hostname = subprocess.check_output(
1911-
"hostname",
1912-
stderr=subprocess.PIPE,
1913-
shell=True
1914-
).strip()
19151910
except subprocess.CalledProcessError:
1916-
print("Error detecting username and host address.")
1911+
print("Error detecting username.")
19171912
sys.exit(1)
1918-
if not hostname.endswith('.local'):
1919-
hostname += '.local'
19201913
creds = {
19211914
'user': user,
1922-
'host': hostname
1915+
'host': '192.168.61.1'
19231916
}
19241917
body = {'creds': json.dumps(creds)}
19251918
sys.stdout.write('Activating Vagrant as a provider... ')

deis/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292
CM_MODULE = os.environ.get('DEIS_CM_MODULE', 'cm.mock')
293293

294294
# default providers, typically overriden in local_settings to include ec2, etc.
295-
PROVIDER_MODULES = ('mock', 'digitalocean', 'ec2', 'rackspace', 'static')
295+
PROVIDER_MODULES = ('mock', 'digitalocean', 'ec2', 'rackspace', 'vagrant', 'static')
296296

297297
# default to sqlite3, but allow postgresql config through envvars
298298
DATABASES = {

provider/vagrant.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ def build_node(node):
7777

7878
# Create a new Vagrantfile from a template
7979
node['params'].setdefault('memory', '512')
80-
template = open('/opt/deis/controller/contrib/vagrant/nodes_vagrantfile_template.rb')
80+
template = open('/app/deis/contrib/vagrant/nodes_vagrantfile_template.rb')
8181
raw = string.Template(template.read())
82+
ip_addr = '192.168.61.' + str(Node.objects.all().count() + 100)
8283
result = raw.substitute({
8384
'id': uid,
84-
'ipaddress': '192.168.61.' + str(Node.objects.all().count() + 100),
85+
'ipaddress': ip_addr,
8586
'memory': node['params']['memory']
8687
})
8788

@@ -107,15 +108,12 @@ def build_node(node):
107108
)
108109

109110
provider_id = uid
110-
fqdn = provider_id
111-
if not fqdn.endswith('.local'):
112-
fqdn += '.local' # hostname is broadcast via avahi-daemon
113111
metadata = {
114112
'id': uid,
115-
'fqdn': fqdn,
113+
'fqdn': ip_addr,
116114
'flavor': node['params']['memory']
117115
}
118-
return provider_id, fqdn, metadata
116+
return provider_id, ip_addr, metadata
119117

120118

121119
def destroy_node(node):

0 commit comments

Comments
 (0)