+def _GetConfig():
+ """Simple wrapper to return a ConfigReader.
+
+ @rtype: L{ssconf.SimpleConfigReader}
+ @return: a SimpleConfigReader instance
+
+ """
+ return ssconf.SimpleConfigReader()
+
+
+def _GetSshRunner(cluster_name):
+ """Simple wrapper to return an SshRunner.
+
+ @type cluster_name: str
+ @param cluster_name: the cluster name, which is needed
+ by the SshRunner constructor
+ @rtype: L{ssh.SshRunner}
+ @return: an SshRunner instance
+
+ """
+ return ssh.SshRunner(cluster_name)
+
+
+def _CleanDirectory(path, exclude=[]):
+ """Removes all regular files in a directory.
+
+ @type path: str
+ @param path: the directory to clean
+ @type exclude: list
+ @param exclude: list of files to be excluded, defaults
+ to the empty list
+ @rtype: None
+
+ """
+ if not os.path.isdir(path):
+ return
+
+ # Normalize excluded paths
+ exclude = [os.path.normpath(i) for i in exclude]
+
+ for rel_name in utils.ListVisibleFiles(path):
+ full_name = os.path.normpath(os.path.join(path, rel_name))
+ if full_name in exclude:
+ continue
+ if os.path.isfile(full_name) and not os.path.islink(full_name):
+ utils.RemoveFile(full_name)
+
+
+def JobQueuePurge():
+ """Removes job queue files and archived jobs.
+
+ @rtype: None
+
+ """
+ _CleanDirectory(constants.QUEUE_DIR, exclude=[constants.JOB_QUEUE_LOCK_FILE])
+ _CleanDirectory(constants.JOB_QUEUE_ARCHIVE_DIR)
+
+
+def GetMasterInfo():
+ """Returns master information.
+
+ This is an utility function to compute master information, either
+ for consumption here or from the node daemon.
+
+ @rtype: tuple
+ @return: (master_netdev, master_ip, master_name) if we have a good
+ configuration, otherwise (None, None, None)
+
+ """
+ try:
+ cfg = _GetConfig()
+ master_netdev = cfg.GetMasterNetdev()
+ master_ip = cfg.GetMasterIP()
+ master_node = cfg.GetMasterNode()
+ except errors.ConfigurationError, err:
+ logging.exception("Cluster configuration incomplete")
+ return (None, None, None)
+ return (master_netdev, master_ip, master_node)