Skip to content

Commit

Permalink
Functions to fix nodes with same alias
Browse files Browse the repository at this point in the history
  • Loading branch information
Mich committed Nov 5, 2014
1 parent 89cd84e commit c58253a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
35 changes: 35 additions & 0 deletions starcluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

import iptools

from collections import Counter

from starcluster import utils
from starcluster import static
from starcluster import sshutils
Expand Down Expand Up @@ -1739,6 +1741,39 @@ def ssh_to_node(self, alias, user='root', command=None, forward_x11=False,
pseudo_tty=pseudo_tty,
command=command)

def _get_duplicate_aliases(self):
aliases = [_n.alias for _n in self.nodes]
tmp_aliases = Counter(aliases)
return filter(lambda k: tmp_aliases[k] > 1, tmp_aliases)

def _recover_duplicate_aliases(self):
aliases = self._get_duplicate_aliases()
if not aliases:
return

log.error("Nodes with same alias detected! {}".format(aliases))
etc_hosts = self._master.ssh.get_remote_file_lines('/etc/hosts')
for alias in aliases:
ip = None
for line in etc_hosts:
if re.findall(alias, line):
ip, _ = line.split(" ", 1)
log.debug("Found ip: " + ip)
break
else:
log.debug("No ip found")
for node in self.nodes:
if node.alias != alias:
continue
if node.private_ip_address != ip:
new_alias = self._make_alias(self._get_next_node_num())
log.info("Renaming {} from {} to {}"
.format(node, node.alias, new_alias))
node.rename(new_alias)
# force a memory refresh
self._nodes = []
self.nodes


class ClusterValidator(validators.Validator):

Expand Down
16 changes: 16 additions & 0 deletions starcluster/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1190,3 +1190,19 @@ def package_install(self, pkgs):
def __del__(self):
if self._ssh:
self._ssh.close()

def rename(self, new_name):
"""
Used to reset the name and alias when there is a conflict
"""
self.remove_tag("alias")
self.remove_tag("Name")
self.add_tag("Name", new_name)
self.add_tag("alias", new_name)
while True:
tags = self.tags
if tags.get("Name", "") == new_name \
and tags.get("alias", "") == new_name:
break
log.info("Waiting for new name to propagate")
time.sleep(5)

0 comments on commit c58253a

Please sign in to comment.