--select-instances hbal manpage update
[ganeti-local] / tools / cfgupgrade
index 9e4b02b..0d341c3 100755 (executable)
@@ -171,31 +171,40 @@ def main():
     raise Error("Inconsistent configuration: found config_version in"
                 " configuration file")
 
-  # Upgrade from 2.0/2.1/2.2 to 2.3
-  if config_major == 2 and config_minor in (0, 1, 2):
+  # Upgrade from 2.0/2.1/2.2/2.3 to 2.4
+  if config_major == 2 and config_minor in (0, 1, 2, 3):
     if config_revision != 0:
       logging.warning("Config revision is %s, not 0", config_revision)
 
-    config_data["version"] = constants.BuildVersion(2, 3, 0)
+    config_data["version"] = constants.BuildVersion(2, 4, 0)
 
-  elif config_major == 2 and config_minor == 3:
+  elif config_major == 2 and config_minor == 4:
     logging.info("No changes necessary")
 
   else:
     raise Error("Configuration version %d.%d.%d not supported by this tool" %
                 (config_major, config_minor, config_revision))
 
-  if os.path.isfile(options.RAPI_USERS_FILE_PRE24):
+  if (os.path.isfile(options.RAPI_USERS_FILE_PRE24) and
+      not os.path.islink(options.RAPI_USERS_FILE_PRE24)):
+    if os.path.exists(options.RAPI_USERS_FILE):
+      raise Error("Found pre-2.4 RAPI users file at %s, but another file"
+                  " already exists at %s" %
+                  (options.RAPI_USERS_FILE_PRE24, options.RAPI_USERS_FILE))
     logging.info("Found pre-2.4 RAPI users file at %s, renaming to %s",
                  options.RAPI_USERS_FILE_PRE24, options.RAPI_USERS_FILE)
-    utils.RenameFile(options.RAPI_USERS_FILE_PRE24, options.RAPI_USERS_FILE,
-                     mkdir=True, mkdir_mode=0750)
+    if not options.dry_run:
+      utils.RenameFile(options.RAPI_USERS_FILE_PRE24, options.RAPI_USERS_FILE,
+                       mkdir=True, mkdir_mode=0750)
 
   # Create a symlink for RAPI users file
-  if not os.path.islink(options.RAPI_USERS_FILE_PRE24):
+  if (not (os.path.islink(options.RAPI_USERS_FILE_PRE24) or
+           os.path.isfile(options.RAPI_USERS_FILE_PRE24)) and
+      os.path.isfile(options.RAPI_USERS_FILE)):
     logging.info("Creating symlink from %s to %s",
                  options.RAPI_USERS_FILE_PRE24, options.RAPI_USERS_FILE)
-    os.symlink(options.RAPI_USERS_FILE, options.RAPI_USERS_FILE_PRE24)
+    if not options.dry_run:
+      os.symlink(options.RAPI_USERS_FILE, options.RAPI_USERS_FILE_PRE24)
 
   try:
     logging.info("Writing configuration file to %s", options.CONFIG_DATA_PATH)
@@ -221,6 +230,7 @@ def main():
   if not (options.dry_run or options.no_verify):
     logging.info("Testing the new config file...")
     cfg = config.ConfigWriter(cfg_file=options.CONFIG_DATA_PATH,
+                              accept_foreign=options.ignore_hostname,
                               offline=True)
     # if we reached this, it's all fine
     vrfy = cfg.VerifyConfig()