Juan Hernandez has uploaded a new change for review.

Change subject: packaging: Functions to configure for maintenance
......................................................................

packaging: Functions to configure for maintenance

This patch adds functions that will later be used to configure the
engine in maintenance mode during upgrades.

Change-Id: I84c0f819276bfa121b95227fd8303305b5775563
Signed-off-by: Juan Hernandez <[email protected]>
---
M packaging/fedora/setup/common_utils.py
1 file changed, 79 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/48/8748/1

diff --git a/packaging/fedora/setup/common_utils.py 
b/packaging/fedora/setup/common_utils.py
index 7097a94..c545969 100755
--- a/packaging/fedora/setup/common_utils.py
+++ b/packaging/fedora/setup/common_utils.py
@@ -1345,3 +1345,82 @@
 
     # Return the result:
     return javaHome
+
+def configureEngineForMaintenance():
+    """
+    Configures the engine for maintenance.
+
+    In order to do this we need to disable all the network access to the
+    engine.
+    """
+
+    # First check that the file that we are trying to modify does exist:
+    originalPath = basedefs.FILE_ENGINE_SYSCONFIG
+    if not os.path.exists(originalPath):
+        raise Exception("The file \"%s\" doesn't exist.", originalPath)
+
+    # Make a backup copy that we will later restore when going out of
+    # the maintenance mode, but only if it doesn't already exist, as
+    # otherwise we lose the original content:
+    backupPath = originalPath + ".backup"
+    if not os.path.exists(backupPath):
+        logging.debug("Making a backup copy \"%s\" to \"%s\".", originalPath, 
backupPath)
+        copyFile(originalPath, backupPath)
+
+    # All edits will be performed in a temporary file, and only if
+    # everything works correctly will the original be replaced:
+    temporaryPath = originalPath + ".tmp"
+    copyFile(originalPath, temporaryPath)
+
+    # Edit the engine local configuration file as required, then replace
+    # the original and always remember to remove the temporary file when
+    # finished:
+    try:
+        logging.debug("Updating \"%s\".", temporaryPath)
+        editEngineSysconfigForMaintenance(temporaryPath)
+        logging.debug("Replacing \"%s\" with \"%s\".", originalPath, 
temporaryPath)
+        os.rename(temporaryPath, originalPath)
+    finally:
+        if os.path.exists(temporaryPath):
+            os.remove(temporaryPath)
+
+def restoreEngineFromMaintenance():
+    """
+    Restores the engine from maintentance.
+
+    This means restoring the backup copies of the configuration files that have
+    been modified.
+    """
+
+    # First check that the backup file that we need does exist:
+    originalPath = basedefs.FILE_ENGINE_SYSCONFIG
+    backupPath = originalPath + ".backup"
+    if not os.path.exists(backupPath):
+        raise Exception("Backup copy \"%s\" of \"%s\" doesn't exist.", 
backupPath, originalPath)
+
+    # Replace the original with the backup, that's it:
+    logging.debug("Replacing \"%s\" with \"%s\".", originalPath, backupPath)
+    os.rename(backupPath, originalPath)
+
+def editEngineSysconfigForMaintenance(path):
+    """
+    Configures the engine local configuration for maintenance.
+
+    The full path of the local configuration file is provided as a
+    parameter, the function will not try to locate it.
+    """
+
+    # Load the file:
+    logging.debug("Loading configuration from \"%s\".", path)
+    handler = TextConfigFileHandler(path)
+    handler.open()
+
+    # Disable all the ports:
+    logging.debug("Disabling all ports.")
+    handler.editParam("ENGINE_HTTP_ENABLED", "false")
+    handler.editParam("ENGINE_HTTPS_ENABLED", "false")
+    handler.editParam("ENGINE_AJP_ENABLED", "false")
+
+    # Save and close the file:
+    logging.debug("Saving configuration to \"%s\".", path) 
+    handler.close()


--
To view, visit http://gerrit.ovirt.org/8748
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I84c0f819276bfa121b95227fd8303305b5775563
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to