bootstrap-vz/bootstrapvz/providers/gce/tasks/host.py
Paul Marks 15c7d1ccb3 Do not remove ::1 from the loopback interface.
An environment with AF_INET6 sockets but no loopback interface creates
nothing but pain.

If an IPv4 server binds to 0.0.0.0:8080, clients may connect to
0.0.0.0:8080, which automatically picks 127.0.0.1 as a source address.
However, when a server binds to [::]:8080, the absence of ::1 causes
clients to fail with ENETUNREACH.

For a demonstration, run the following in a python shell:

import socket
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM, 0)
s.bind(("", 0))
print s.getsockname()  # Example: ('::', 39079, 0, 0)
s.listen(10)
c = socket.socket(socket.AF_INET6, socket.SOCK_STREAM, 0)
c.connect(s.getsockname())
print c.getsockname(), c.getpeername()

This yields the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 101] Network is unreachable
2016-03-24 17:14:17 -07:00

42 lines
1.9 KiB
Python

from bootstrapvz.base import Task
from bootstrapvz.common import phases
from bootstrapvz.common.tasks import network
from bootstrapvz.common.tools import log_check_call
import os.path
class DisableIPv6(Task):
description = "Disabling IPv6 support"
phase = phases.system_modification
predecessors = [network.ConfigureNetworkIF]
@classmethod
def run(cls, info):
network_configuration_path = os.path.join(info.root, 'etc/sysctl.d/70-disable-ipv6.conf')
with open(network_configuration_path, 'w') as config_file:
print >>config_file, "net.ipv6.conf.all.disable_ipv6 = 1"
print >>config_file, "net.ipv6.conf.lo.disable_ipv6 = 0"
class InstallHostnameHook(Task):
description = "Installing hostname hook"
phase = phases.system_modification
@classmethod
def run(cls, info):
# There's a surprising amount of software out there which doesn't react well to the system
# hostname being set to a potentially long the fully qualified domain name, including Java 7
# and lower, quite relevant to a lot of cloud use cases such as Hadoop. Since Google Compute
# Engine's out-of-the-box domain names are long but predictable based on project name, we
# install this hook to set the hostname to the short hostname but add a suitable /etc/hosts
# entry.
#
# Since not all operating systems which Google supports on Compute Engine work with the
# /etc/dhcp/dhclient-exit-hooks.d directory, Google's internally-built packaging uses the
# consistent install path of /usr/share/google/set-hostname, and OS-specific build steps are
# used to activate the DHCP hook. In any future Debian-maintained distro-specific packaging,
# the updated deb could handle installing the below symlink or the script itself into
# /etc/dhcp/dhclient-exit-hooks.d.
log_check_call(['chroot', info.root, 'ln', '-s',
'/usr/share/google/set-hostname',
'/etc/dhcp/dhclient-exit-hooks.d/set-hostname'])