diff --git a/lib/cmdlib.py b/lib/cmdlib.py index a5f5a9c5c06c98028b29f46182e01c99a6d447e3..fa254326a8e6417fa7dd78e904a692d7b05bc8e4 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 8c76d81a79448b966ef584a5f87ef6e528e6ce1c..f83fab6e2a1ad0769d733e0f3f1efe1b8d4d7c18 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 dc83b3f85a001b73bfa13cf89e4e1f2afcbb1763..8caf8e2d1a4bfbe37c3e975d1a66df2595ca0aa7 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 d34f9c2f17465eccbf3fc966552b82ad954671a1..2d2ed47ea0f31b9457e5ead264a77fabb11c8285 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 61f3675c51c4eb9eb6e7795c834a6c59c8c14728..66e7e2db246cf8233f8f0c20351ce013e3f8127d 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 5df44c319e4ddfbc45ef983cbff4e4167f9b5516..866e212c0c0da1cf3f5243c875836442e59c38bc 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 966cc99e68ed9297e0b82fa5c24c4774b74c013b..4a28036bc9f8ff908691f59231c13416e8fc43d2 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