Commit 05f86716 authored by Guido Trotter's avatar Guido Trotter

Move SetKey to WritableSimpleStore and use it

Before we used to be able to update SimpleStore by just calling SetKey, this
feature is now moved to an external class, which inherits from it. In this
patch the new WritableSimpleStore class is also put to use, in the LUs that
need it. Rather than making each LU instantiate it, we have a new LogicalUnit
flag REQ_WSSTORE which defaults to False, but when declared to be True asks the
LogicalUnit to be initialized with a writeable version of the SimpleStore.
LUMasterFailover and LURenameCluster are then changed to use it.

InitCluster is also changed to instantiate a WritableSimpleStore, rather
than a normal one.

Reviewed-by: imsnah
parent 2a10865c
......@@ -75,6 +75,9 @@ def _InitGanetiServerSetup(ss):
This creates the nodepass file containing the shared password for
the cluster and also generates the SSL certificate.
Args:
ss: A WritableSimpleStore
"""
# Create pseudo random password
randpass = sha.new(os.urandom(64)).hexdigest()
......@@ -191,7 +194,7 @@ def InitCluster(cluster_name, hypervisor_type, mac_prefix, def_bridge,
" executable." % constants.NODE_INITD_SCRIPT)
# set up the simple store
ss = ssconf.SimpleStore()
ss = ssconf.WritableSimpleStore()
ss.SetKey(ss.SS_HYPERVISOR, hypervisor_type)
ss.SetKey(ss.SS_MASTER_NODE, hostname.name)
ss.SetKey(ss.SS_MASTER_IP, clustername.ip)
......
......@@ -54,14 +54,18 @@ class LogicalUnit(object):
- implement Exec
- implement BuildHooksEnv
- redefine HPATH and HTYPE
- optionally redefine their run requirements (REQ_MASTER); note that all
commands require root permissions
- optionally redefine their run requirements:
REQ_MASTER: the LU needs to run on the master node
REQ_WSSTORE: the LU needs a writable SimpleStore
Note that all commands require root permissions.
"""
HPATH = None
HTYPE = None
_OP_REQP = []
REQ_MASTER = True
REQ_WSSTORE = False
def __init__(self, processor, op, cfg, sstore):
"""Constructor for LogicalUnit.
......@@ -849,6 +853,7 @@ class LURenameCluster(LogicalUnit):
HPATH = "cluster-rename"
HTYPE = constants.HTYPE_CLUSTER
_OP_REQP = ["name"]
REQ_WSSTORE = True
def BuildHooksEnv(self):
"""Build hooks env.
......@@ -1661,6 +1666,7 @@ class LUMasterFailover(LogicalUnit):
HPATH = "master-failover"
HTYPE = constants.HTYPE_CLUSTER
REQ_MASTER = False
REQ_WSSTORE = True
_OP_REQP = []
def BuildHooksEnv(self):
......
......@@ -118,7 +118,10 @@ class Processor(object):
if self.cfg is None:
self.cfg = config.ConfigWriter()
self.sstore = ssconf.SimpleStore()
if lu_class.REQ_WSSTORE:
self.sstore = ssconf.WritableSimpleStore()
else:
self.sstore = ssconf.SimpleStore()
if self.cfg is not None:
write_count = self.cfg.write_count
else:
......
......@@ -47,8 +47,7 @@ class SimpleStore:
Other particularities of the datastore:
- keys are restricted to predefined values
- values are small (<4k)
- some keys are handled specially (read from the system, so
we can't update them)
- some keys are handled specially (read from the system)
"""
_SS_FILEPREFIX = "ssconf_"
......@@ -170,6 +169,25 @@ class SimpleStore:
raise errors.ConfigurationError("Failed to convert config version %s to"
" int: '%s'" % (value, str(err)))
def GetFileList(self):
"""Return the list of all config files.
This is used for computing node replication data.
"""
return [self.KeyToFilename(key) for key in self._VALID_KEYS]
class WritableSimpleStore(SimpleStore):
"""This is a read/write interface to SimpleStore, which is used rarely, when
values need to be changed. Since WriteFile handles updates in an atomic way
it should be fine to use two WritableSimpleStore at the same time, but in
the future we might want to put additional protection for this class.
A WritableSimpleStore cannot be used to update system-dependent values.
"""
def SetKey(self, key, value):
"""Set the value of a key.
......@@ -181,10 +199,3 @@ class SimpleStore:
utils.WriteFile(file_name, data="%s\n" % str(value),
uid=0, gid=0, mode=0400)
def GetFileList(self):
"""Return the list of all config files.
This is used for computing node replication data.
"""
return [self.KeyToFilename(key) for key in self._VALID_KEYS]
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