Skip to content

Commit

Permalink
Added --dns-sufix option
Browse files Browse the repository at this point in the history
  • Loading branch information
Mich committed Jul 25, 2014
1 parent 1c27e42 commit 72f3bc5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
38 changes: 29 additions & 9 deletions starcluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ def __init__(self,
public_ips=None,
plugins_order=[],
config_on_master=False,
dns_sufix=None,
**kwargs):
# update class vars with given vars
_vars = locals().copy()
Expand All @@ -454,6 +455,7 @@ def __init__(self,
self.force_spot_master = force_spot_master
self.disable_cloudinit = disable_cloudinit
self.plugins_order = plugins_order
self.dns_sufix = dns_sufix and cluster_tag

self._cluster_group = None
self._placement_group = None
Expand All @@ -467,6 +469,7 @@ def __init__(self,
self._vpc_id = None
self._subnet_zones_mapping = None


def __repr__(self):
return '<Cluster: %s (%s-node)>' % (self.cluster_tag,
self.cluster_size)
Expand Down Expand Up @@ -748,7 +751,8 @@ def _get_settings(self):
public_ips=self.public_ips,
disable_queue=self.disable_queue,
disable_cloudinit=self.disable_cloudinit,
plugins_order=self.plugins_order)
plugins_order=self.plugins_order,
dns_sufix=self.dns_sufix)
user_settings = dict(cluster_user=self.cluster_user,
cluster_shell=self.cluster_shell,
keyname=self.keyname, spot_bid=self.spot_bid)
Expand Down Expand Up @@ -971,18 +975,17 @@ def _nodes_in_states(self, states):

def _make_alias(self, id=None, master=False):
if master:
if self.dns_prefix:
return "%s-master" % self.dns_prefix
else:
return "master"
alias = "master"
elif id is not None:
if self.dns_prefix:
alias = '%s-node%.3d' % (self.dns_prefix, id)
else:
alias = 'node%.3d' % id
alias = 'node{:03d}'.format(id)
else:
raise AttributeError("_make_alias(...) must receive either"
" master=True or a node id number")

if self.dns_prefix:
alias = "{}-{}".format(self.dns_prefix, alias)
if self.dns_sufix:
alias = "{}.{}".format(alias, self.dns_sufix)
return alias

@property
Expand Down Expand Up @@ -2140,6 +2143,7 @@ def validate(self):
self.validate_required_settings()
self.validate_vpc()
self.validate_dns_prefix()
self.validate_dns_sufix()
self.validate_spot_bid()
self.validate_cluster_size()
self.validate_cluster_user()
Expand Down Expand Up @@ -2186,6 +2190,22 @@ def validate_dns_prefix(self):
dns_prefix=self.cluster.dns_prefix))
return True

def validate_dns_sufix(self):
if not self.cluster.dns_sufix:
return True

# check that the dns prefix is a valid hostname
is_valid = utils.is_valid_hostname(self.cluster.dns_sufix)
if not is_valid:
raise exception.ClusterValidationError(
"The cluster name you chose, {dns_prefix}, is"
" not a valid dns name. "
" Since you have chosen to prepend the hostnames"
" via the dns_prefix option, {dns_prefix} should only have"
" alphanumeric characters and a '-' or '.'".format(
dns_prefix=self.cluster.dns_sufix))
return True

def validate_spot_bid(self):
cluster = self.cluster
if cluster.spot_bid is not None:
Expand Down
10 changes: 10 additions & 0 deletions starcluster/commands/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,19 @@ def addopts(self, parser):
action='store_true', help="Store the config on the "
"master node rather than into the security group "
"tags")
parser.add_option("--dns-sufix", action='store_true',
help="Sufix dns names of all nodes in the cluster "
"with the cluster tag.")

def execute(self, args):
if len(args) != 1:
self.parser.error("please specify a <cluster_tag>")
tag = args[0]
if tag.find("master") > -1:
# Because of Node.is_master
raise exception.ClusterValidationError("Cluster name cannot "
"contain master")

create = not self.opts.no_create
scluster = self.cm.get_cluster_group_or_none(tag)
if scluster and create:
Expand Down Expand Up @@ -252,6 +260,8 @@ def execute(self, args):
self.warn_experimental(msg, num_secs=5)
if self.opts.dns_prefix:
scluster.dns_prefix = tag
if self.opts.dns_sufix:
scluster.dns_sufix = tag
if config_on_master:
scluster.config_on_master = True
if self.opts.no_create:
Expand Down
14 changes: 10 additions & 4 deletions starcluster/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ def alias(self):
self._alias = alias
return self._alias

@property
def short_alias(self):
return self.alias.split(".", 1)[0]

def reset_alias(self):
"""
Used to reset the name and alias when there is a conflict
Expand Down Expand Up @@ -878,8 +882,8 @@ def remove_from_etc_hosts(self, nodes):
Remove all network names and ips for node in nodes arg from this node's
/etc/hosts file
"""
aliases = map(lambda x: x.alias, nodes)
ips = map(lambda x: x.private_ip_address.replace(".", "\."), nodes)
aliases = [n.short_alias for n in nodes]
ips = [n.private_ip_address.replace(".", "\.") for n in nodes]
self.ssh.remove_lines_from_file('/etc/hosts', '|'.join(aliases))
self.ssh.remove_lines_from_file('/etc/hosts', '|'.join(ips))

Expand Down Expand Up @@ -912,6 +916,7 @@ def network_names(self):
names['INTERNAL_NAME'] = self.private_dns_name
names['INTERNAL_NAME_SHORT'] = self.private_dns_name_short
names['INTERNAL_ALIAS'] = self.alias
names['INTERNAL_SHORT_ALIAS'] = self.short_alias
return names

@property
Expand Down Expand Up @@ -968,7 +973,7 @@ def get_spot_request(self):
return spot[0]

def is_master(self):
return self.alias == 'master' or self.alias.endswith("-master")
return self.alias.find("master") != -1

def is_instance_store(self):
return self.instance.root_device_type == "instance-store"
Expand Down Expand Up @@ -1240,7 +1245,8 @@ def shell(self, user=None, forward_x11=False, forward_agent=False,

def get_hosts_entry(self):
""" Returns /etc/hosts entry for this node """
etc_hosts_line = "%(INTERNAL_IP)s %(INTERNAL_ALIAS)s"
etc_hosts_line = \
"%(INTERNAL_IP)s %(INTERNAL_ALIAS)s %(INTERNAL_SHORT_ALIAS)s"
etc_hosts_line = etc_hosts_line % self.network_names
return etc_hosts_line

Expand Down
5 changes: 2 additions & 3 deletions starcluster/plugins/sge.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,11 @@ def get_nodes_to_recover(self, nodes):
for node in nodes:
# nodes missing from qhost
if node.alias not in parsed_qhosts:
if node.alias == "master":
if node.alias.is_master():
assert(not self.master_is_exec_host)
else:
missing.append(node)
elif parsed_qhosts[node.alias][-1] == "-" \
and node.alias != "master":
elif parsed_qhosts[node.alias][-1] == "-" and not node.is_master():
# nodes present but w/o stats
try:
node.ssh.execute("qhost", source_profile=True)
Expand Down

0 comments on commit 72f3bc5

Please sign in to comment.