Fix a small typo in a constant
[ganeti-local] / lib / backend.py
index ec3cb7a..b993f9d 100644 (file)
@@ -69,6 +69,19 @@ def _CleanDirectory(path, exclude=[]):
       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.
 
@@ -192,7 +205,8 @@ def LeaveCluster():
   """
   _CleanDirectory(constants.DATA_DIR)
 
-  JobQueuePurge()
+  # The lock can be removed because we're going to quit anyway.
+  _JobQueuePurge(keep_lock=False)
 
   try:
     priv_key, pub_key, auth_keys = ssh.GetUserFiles(constants.GANETI_RUNAS)
@@ -516,8 +530,9 @@ def AddOSToInstance(instance, os_disk, swap_disk):
                                 inst_os.path, create_script, instance.name,
                                 real_os_dev.dev_path, real_swap_dev.dev_path,
                                 logfile)
+  env = {'HYPERVISOR': ssconf.SimpleStore().GetHypervisorType()}
 
-  result = utils.RunCmd(command)
+  result = utils.RunCmd(command, env=env)
   if result.failed:
     logging.error("os create command '%s' returned error: %s, logfile: %s,"
                   " output: %s", command, result.fail_reason, logfile,
@@ -1472,8 +1487,9 @@ def ImportOSIntoInstance(instance, os_disk, swap_disk, src_node, src_image):
                                logfile)
 
   command = '|'.join([utils.ShellQuoteArgs(remotecmd), comprcmd, impcmd])
+  env = {'HYPERVISOR': ssconf.SimpleStore().GetHypervisorType()}
 
-  result = utils.RunCmd(command)
+  result = utils.RunCmd(command, env=env)
 
   if result.failed:
     logging.error("os import command '%s' returned error: %s"
@@ -1698,8 +1714,9 @@ def JobQueuePurge():
   """Removes job queue files and archived jobs
 
   """
-  _CleanDirectory(constants.QUEUE_DIR)
-  _CleanDirectory(constants.JOB_QUEUE_ARCHIVE_DIR)
+  # The lock must not be removed, otherwise another process could create
+  # it again.
+  return _JobQueuePurge(keep_lock=True)
 
 
 def JobQueueRename(old, new):