From 0fbae49a3f6bca793f76e5a01e5b5a61994d9bae Mon Sep 17 00:00:00 2001
From: Balazs Lecz <leczb@google.com>
Date: Thu, 25 Mar 2010 15:50:24 +0000
Subject: [PATCH] Add uid_pool to ssconf

Signed-off-by: Balazs Lecz <leczb@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 lib/config.py    |  4 ++++
 lib/constants.py |  1 +
 lib/ssconf.py    | 14 ++++++++++++++
 lib/uidpool.py   | 10 +++++++---
 4 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/lib/config.py b/lib/config.py
index 353c2887d..35d800c0a 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 f9df40f91..ecf308585 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 6b654abe5..e561549ad 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 c8c03a510..85e664e61 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):
-- 
GitLab