+ data = self._ReadFile(constants.SS_UID_POOL)
+ return data
+
+ def GetPrimaryIPFamily(self):
+ """Return the cluster-wide primary address family.
+
+ """
+ try:
+ return int(self._ReadFile(constants.SS_PRIMARY_IP_FAMILY,
+ default=netutils.IP4Address.family))
+ except (ValueError, TypeError), err:
+ raise errors.ConfigurationError("Error while trying to parse primary IP"
+ " family: %s" % err)
+
+
+def WriteSsconfFiles(values, dry_run=False):
+ """Update all ssconf files.
+
+ Wrapper around L{SimpleStore.WriteFiles}.
+
+ """
+ SimpleStore().WriteFiles(values, dry_run=dry_run)
+
+
+def GetMasterAndMyself(ss=None):
+ """Get the master node and my own hostname.
+
+ This can be either used for a 'soft' check (compared to CheckMaster,
+ which exits) or just for computing both at the same time.
+
+ The function does not handle any errors, these should be handled in
+ the caller (errors.ConfigurationError, errors.ResolverError).
+
+ @param ss: either a sstore.SimpleConfigReader or a
+ sstore.SimpleStore instance
+ @rtype: tuple
+ @return: a tuple (master node name, my own name)
+
+ """
+ if ss is None:
+ ss = SimpleStore()
+ return ss.GetMasterNode(), netutils.Hostname.GetSysName()
+
+
+def CheckMaster(debug, ss=None):
+ """Checks the node setup.
+
+ If this is the master, the function will return. Otherwise it will
+ exit with an exit code based on the node status.
+
+ """
+ try:
+ master_name, myself = GetMasterAndMyself(ss)
+ except errors.ConfigurationError, err:
+ print "Cluster configuration incomplete: '%s'" % str(err)
+ sys.exit(constants.EXIT_NODESETUP_ERROR)
+ except errors.ResolverError, err:
+ sys.stderr.write("Cannot resolve my own name (%s)\n" % err.args[0])
+ sys.exit(constants.EXIT_NODESETUP_ERROR)
+
+ if myself != master_name:
+ if debug:
+ sys.stderr.write("Not master, exiting.\n")
+ sys.exit(constants.EXIT_NOTMASTER)
+
+
+def VerifyClusterName(name, _cfg_location=None):
+ """Verifies cluster name against a local cluster name.
+
+ @type name: string
+ @param name: Cluster name
+
+ """
+ sstore = SimpleStore(cfg_location=_cfg_location)
+
+ try:
+ local_name = sstore.GetClusterName()
+ except errors.ConfigurationError, err:
+ logging.debug("Can't get local cluster name: %s", err)
+ else:
+ if name != local_name:
+ raise errors.GenericError("Current cluster name is '%s'" % local_name)
+
+
+def VerifyKeys(keys):
+ """Raises an exception if unknown ssconf keys are given.
+
+ @type keys: sequence
+ @param keys: Key names to verify
+ @raise errors.GenericError: When invalid keys were found
+
+ """
+ invalid = frozenset(keys) - _VALID_KEYS
+ if invalid:
+ raise errors.GenericError("Invalid ssconf keys: %s" %
+ utils.CommaJoin(sorted(invalid)))