Commit 5fcdc80d authored by Iustin Pop's avatar Iustin Pop
Browse files

Move the cluster name from ConfigWriter to SimpleStore.

Reason: if left ConfigWriter, nodes don't know to which cluster they belong.
This will bite us later when we'll revisit node join operation.

Cons: we lose the cluster name from the config file, which means a
standalone "cluster.data" is a little bit harder to analyze. But I have
a plan for this which will follow shortly.

Implementing this will also allow us to cleanly fix "gnt-cluster
getmaster".

Reviewed-by: imsnah
parent fe7b0351
......@@ -539,6 +539,7 @@ class LUInitCluster(LogicalUnit):
ss.SetKey(ss.SS_MASTER_NODE, hostname['hostname_full'])
ss.SetKey(ss.SS_MASTER_IP, clustername['ip'])
ss.SetKey(ss.SS_MASTER_NETDEV, self.op.master_netdev)
ss.SetKey(ss.SS_CLUSTER_NAME, clustername['hostname'])
# set up the inter-node password and certificate
_InitGanetiServerSetup(ss)
......@@ -568,7 +569,7 @@ class LUInitCluster(LogicalUnit):
# init of cluster config file
cfgw = config.ConfigWriter()
cfgw.InitConfig(hostname['hostname'], hostname['ip'], self.secondary_ip,
clustername['hostname'], sshkey, self.op.mac_prefix,
sshkey, self.op.mac_prefix,
self.op.vg_name, self.op.def_bridge)
......@@ -1481,7 +1482,7 @@ class LUQueryClusterInfo(NoHooksLU):
instances = [self.cfg.GetInstanceInfo(name)
for name in self.cfg.GetInstanceList()]
result = {
"name": self.cfg.GetClusterName(),
"name": self.sstore.GetClusterName(),
"software_version": constants.RELEASE_VERSION,
"protocol_version": constants.PROTOCOL_VERSION,
"config_version": constants.CONFIG_VERSION,
......
......@@ -483,7 +483,7 @@ class ConfigWriter:
self._DistributeConfig()
def InitConfig(self, node, primary_ip, secondary_ip,
clustername, hostkeypub, mac_prefix, vg_name, def_bridge):
hostkeypub, mac_prefix, vg_name, def_bridge):
"""Create the initial cluster configuration.
It will contain the current node, which will also be the master
......@@ -493,14 +493,12 @@ class ConfigWriter:
node: the nodename of the initial node
primary_ip: the IP address of the current host
secondary_ip: the secondary IP of the current host or None
clustername: the name of the cluster
hostkeypub: the public hostkey of this host
"""
hu_port = constants.FIRST_DRBD_PORT - 1
globalconfig = objects.Cluster(config_version=constants.CONFIG_VERSION,
serial_no=1,
name=clustername,
rsahostkeypub=hostkeypub,
highest_used_port=hu_port,
mac_prefix=mac_prefix,
......@@ -517,14 +515,6 @@ class ConfigWriter:
cluster=globalconfig)
self._WriteConfig()
def GetClusterName(self):
"""Return the cluster name.
"""
self._OpenConfig()
self._ReleaseLock()
return self._config_data.cluster.name
def GetVGName(self):
"""Return the volume group name.
......
......@@ -201,9 +201,8 @@ class HooksMaster(object):
for key in lu_env:
env["GANETI_" + key] = lu_env[key]
if self.cfg is not None:
env["GANETI_CLUSTER"] = self.cfg.GetClusterName()
if self.sstore is not None:
env["GANETI_CLUSTER"] = self.sstore.GetClusterName()
env["GANETI_MASTER"] = self.sstore.GetMasterNode()
for key in env:
......
......@@ -342,7 +342,6 @@ class Cluster(ConfigObject):
__slots__ = [
"config_version",
"serial_no",
"name",
"rsahostkeypub",
"highest_used_port",
"tcpudp_port_pool",
......
......@@ -60,8 +60,9 @@ class SimpleStore:
SS_MASTER_NODE = "master_node"
SS_MASTER_IP = "master_ip"
SS_MASTER_NETDEV = "master_netdev"
SS_CLUSTER_NAME = "cluster_name"
_VALID_KEYS = (SS_HYPERVISOR, SS_NODED_PASS, SS_MASTER_NODE, SS_MASTER_IP,
SS_MASTER_NETDEV)
SS_MASTER_NETDEV, SS_CLUSTER_NAME)
_MAX_SIZE = 4096
def __init__(self, cfg_location=None):
......@@ -150,6 +151,12 @@ class SimpleStore:
"""
return self._ReadFile(self.SS_MASTER_NETDEV)
def GetClusterName(self):
"""Get the cluster name.
"""
return self._ReadFile(self.SS_CLUSTER_NAME)
def SetKey(self, key, value):
"""Set the value of a key.
......
......@@ -29,9 +29,6 @@ class FakeConfig:
def IsCluster(self):
return True
def GetClusterName(self):
return "test.cluster"
def GetNodeList(self):
return ["a", "b", "c"]
......@@ -42,5 +39,8 @@ class FakeConfig:
class FakeSStore:
"""Fake simplestore object"""
def GetClusterName(self):
return "test.cluster"
def GetMasterNode(self):
return socket.gethostname()
......@@ -63,7 +63,7 @@ class ConfigShell(cmd.Cmd):
"""
cmd.Cmd.__init__(self)
self.cfg = self.cluster_name = None
self.cfg = None
self.parents = []
self.path = []
if cfg_file:
......@@ -133,7 +133,7 @@ class ConfigShell(cmd.Cmd):
if self.cfg is None:
self.prompt = "(#no config) "
else:
self.prompt = "(%s:/%s) " % (self.cluster_name, "/".join(self.path))
self.prompt = "(/%s) " % ("/".join(self.path),)
return stop
def do_load(self, line):
......@@ -155,7 +155,6 @@ class ConfigShell(cmd.Cmd):
self.cfg._OpenConfig()
self.parents = [self.cfg._config_data]
self.path = []
self.cluster_name = self.cfg.GetClusterName()
except errors.ConfigurationError, err:
print "Error: %s" % str(err)
return False
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment