diff --git a/lib/config.py b/lib/config.py index 353c2887da274b83cad121877849c39771323bfc..35d800c0a8bca634eecb3118ffe3f797d0a0e99d 100644 --- a/lib/config.py +++ b/lib/config.py @@ -43,6 +43,7 @@ from ganeti import constants from ganeti import rpc from ganeti import objects from ganeti import serializer +from ganeti import uidpool _config_lock = locking.SharedLock() @@ -1372,6 +1373,8 @@ class ConfigWriter: hypervisor_list = fn(cluster.enabled_hypervisors) + uid_pool = uidpool.FormatUidPool(cluster.uid_pool, separator="\n") + return { constants.SS_CLUSTER_NAME: cluster.cluster_name, constants.SS_CLUSTER_TAGS: cluster_tags, @@ -1390,6 +1393,7 @@ class ConfigWriter: constants.SS_RELEASE_VERSION: constants.RELEASE_VERSION, constants.SS_HYPERVISOR_LIST: hypervisor_list, constants.SS_MAINTAIN_NODE_HEALTH: str(cluster.maintain_node_health), + constants.SS_UID_POOL: uid_pool, } @locking.ssynchronized(_config_lock, shared=1) diff --git a/lib/constants.py b/lib/constants.py index f9df40f91d913df0601350f07f193a8388f01b15..ecf30858503007e83315dd7d2a18da84ad4ecab9 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -672,6 +672,7 @@ SS_INSTANCE_LIST = "instance_list" SS_RELEASE_VERSION = "release_version" SS_HYPERVISOR_LIST = "hypervisor_list" SS_MAINTAIN_NODE_HEALTH = "maintain_node_health" +SS_UID_POOL = "uid_pool" # cluster wide default parameters DEFAULT_ENABLED_HYPERVISOR = HT_XEN_PVM diff --git a/lib/ssconf.py b/lib/ssconf.py index 6b654abe577240faf9aa83a63946f547cd0f45e6..e561549ad8717eb2d9767a0cc2677de53eec5785 100644 --- a/lib/ssconf.py +++ b/lib/ssconf.py @@ -284,6 +284,7 @@ class SimpleStore(object): constants.SS_RELEASE_VERSION, constants.SS_HYPERVISOR_LIST, constants.SS_MAINTAIN_NODE_HEALTH, + constants.SS_UID_POOL, ) _MAX_SIZE = 131072 @@ -441,6 +442,19 @@ class SimpleStore(object): # we rely on the bool serialization here return data == "True" + def GetUidPool(self): + """Return the user-id pool definition string. + + The separator character is a newline. + + The return value can be parsed using uidpool.ParseUidPool(): + ss = ssconf.SimpleStore() + uid_pool = uidpool.ParseUidPool(ss.GetUidPool(), separator="\n") + + """ + data = self._ReadFile(constants.SS_UID_POOL) + return data + def GetMasterAndMyself(ss=None): """Get the master node and my own hostname. diff --git a/lib/uidpool.py b/lib/uidpool.py index c8c03a5108c078d8bf1fbf869fbf95c03ef35a34..85e664e6116cadcad525093d81ac6bc62cdb3b9f 100644 --- a/lib/uidpool.py +++ b/lib/uidpool.py @@ -118,17 +118,21 @@ def _FormatUidRange(lower, higher): return "%s-%s" % (lower, higher) -def FormatUidPool(uid_pool): +def FormatUidPool(uid_pool, separator=None): """Convert the internal representation of the user-id pool into a string. The output format is also accepted by ParseUidPool() @param uid_pool: a list of integer pairs representing UID ranges + @param separator: the separator character between the uids/uid-ranges. + Defaults to ", ". @return: a string with the formatted results """ - return utils.CommaJoin([_FormatUidRange(lower, higher) - for lower, higher in uid_pool]) + if separator is None: + separator = ", " + return separator.join([_FormatUidRange(lower, higher) + for lower, higher in uid_pool]) def CheckUidPool(uid_pool):