Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a container's host as an extra host as part of its physical spec. #303

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions nixops/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ def get_ssh_password(self):
def get_ssh_for_copy_closure(self):
return self.ssh

def getExtraHosts(self):
# No extra hosts by default.
extraHosts = []
return extraHosts

@property
def public_ipv4(self):
return None
Expand Down
15 changes: 15 additions & 0 deletions nixops/backends/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ def __init__(self, depl, name, id):
def resource_id(self):
return self.vm_id

def _getHostPrivateIp(self):
# This is kind of hackish but should return what's expected. I'm not
# sure there are any better way of retrieving the host's ip address.
hostIp = self.private_ipv4.split('.')[:-1]

# Host always at ip ending in "1".
hostIp.append("1")

return ".".join(hostIp)

def getExtraHosts(self):
# As a convenience, a container backend adds the container's host as an extra host.
extraHosts = [(self._getHostPrivateIp(), ["container-host", "container-host-private"])]
return extraHosts

def address_to(self, m):
if isinstance(m, ContainerState) and self.host == m.host:
return m.private_ipv4
Expand Down
6 changes: 6 additions & 0 deletions nixops/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,12 @@ def index_to_private_ip(index):
# than for the canonical name!
hosts[m.name][index_to_private_ip(m.index)].append(m.name + "-encrypted")

backendExtraHosts = m.getExtraHosts()

# Add backend specific extra hosts.
for ip, hs in backendExtraHosts:
hosts[m.name][ip] += hs

def do_machine(m):
defn = self.definitions[m.name]
attrs_list = attrs_per_resource[m.name]
Expand Down