+ # 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(keep_lock):
+ """Removes job queue files and archived jobs
+
+ """
+ if keep_lock:
+ exclude = [constants.JOB_QUEUE_LOCK_FILE]
+ else:
+ exclude = []
+
+ _CleanDirectory(constants.QUEUE_DIR, exclude=exclude)
+ _CleanDirectory(constants.JOB_QUEUE_ARCHIVE_DIR)
+
+
+def _GetMasterInfo():
+ """Return the master ip and netdev.
+
+ """
+ try:
+ ss = ssconf.SimpleStore()
+ master_netdev = ss.GetMasterNetdev()
+ master_ip = ss.GetMasterIP()
+ except errors.ConfigurationError, err:
+ logging.exception("Cluster configuration incomplete")
+ return (None, None)
+ return (master_netdev, master_ip)
+
+
+def StartMaster(start_daemons):
+ """Activate local node as master node.
+
+ The function will always try activate the IP address of the master
+ (if someone else has it, then it won't). Then, if the start_daemons
+ parameter is True, it will also start the master daemons
+ (ganet-masterd and ganeti-rapi).
+
+ """
+ ok = True
+ master_netdev, master_ip = _GetMasterInfo()
+ if not master_netdev: