From 5fcdc80db13233a8718074a18064c40b0d3a1e20 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Fri, 27 Jul 2007 07:41:30 +0000 Subject: [PATCH] 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 --- lib/cmdlib.py | 5 +++-- lib/config.py | 12 +----------- lib/mcpu.py | 3 +-- lib/objects.py | 1 - lib/ssconf.py | 9 ++++++++- testing/mocks.py | 6 +++--- tools/cfgshell | 5 ++--- 7 files changed, 18 insertions(+), 23 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index a5f5a9c5c..fa254326a 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -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, diff --git a/lib/config.py b/lib/config.py index 8c76d81a7..f83fab6e2 100644 --- a/lib/config.py +++ b/lib/config.py @@ -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. diff --git a/lib/mcpu.py b/lib/mcpu.py index dc83b3f85..8caf8e2d1 100644 --- a/lib/mcpu.py +++ b/lib/mcpu.py @@ -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: diff --git a/lib/objects.py b/lib/objects.py index d34f9c2f1..2d2ed47ea 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -342,7 +342,6 @@ class Cluster(ConfigObject): __slots__ = [ "config_version", "serial_no", - "name", "rsahostkeypub", "highest_used_port", "tcpudp_port_pool", diff --git a/lib/ssconf.py b/lib/ssconf.py index 61f3675c5..66e7e2db2 100644 --- a/lib/ssconf.py +++ b/lib/ssconf.py @@ -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. diff --git a/testing/mocks.py b/testing/mocks.py index 5df44c319..866e212c0 100644 --- a/testing/mocks.py +++ b/testing/mocks.py @@ -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() diff --git a/tools/cfgshell b/tools/cfgshell index 966cc99e6..4a28036bc 100755 --- a/tools/cfgshell +++ b/tools/cfgshell @@ -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 -- GitLab