Blame SOURCES/bz1357945-01-add-support-for-clufter-s-dist-parameter.patch

15f218
From 4ffe5f795247be1f1a14100721bf09d54c904a94 Mon Sep 17 00:00:00 2001
15f218
From: Tomas Jelinek <tojeline@redhat.com>
15f218
Date: Wed, 20 Jul 2016 16:42:37 +0200
15f218
Subject: [PATCH] add support for clufter's 'dist' parameter
15f218
15f218
---
15f218
 pcs/config.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
15f218
 pcs/pcs.8     | 10 ++++-----
15f218
 pcs/usage.py  | 21 ++++++++++++------
15f218
 3 files changed, 76 insertions(+), 24 deletions(-)
15f218
15f218
diff --git a/pcs/config.py b/pcs/config.py
15f218
index 9119c3c..e410a5a 100644
15f218
--- a/pcs/config.py
15f218
+++ b/pcs/config.py
15f218
@@ -18,8 +18,10 @@ import logging
15f218
 import pwd
15f218
 import grp
15f218
 import time
15f218
+import platform
15f218
 
15f218
 try:
15f218
+    import clufter.facts
15f218
     import clufter.format_manager
15f218
     import clufter.filter_manager
15f218
     import clufter.command_manager
15f218
@@ -555,6 +557,7 @@ def config_import_cman(argv):
15f218
     cluster_conf = settings.cluster_conf_file
15f218
     dry_run_output = None
15f218
     output_format = "cluster.conf" if utils.is_rhel6() else "corosync.conf"
15f218
+    dist = None
15f218
     invalid_args = False
15f218
     for arg in argv:
15f218
         if "=" in arg:
15f218
@@ -571,6 +574,8 @@ def config_import_cman(argv):
15f218
                     output_format = value
15f218
                 else:
15f218
                     invalid_args = True
15f218
+            elif name == "dist":
15f218
+                dist = value
15f218
             else:
15f218
                 invalid_args = True
15f218
         else:
15f218
@@ -588,12 +593,34 @@ def config_import_cman(argv):
15f218
     force = "--force" in utils.pcs_options
15f218
     interactive = "--interactive" in utils.pcs_options
15f218
 
15f218
+    if dist is not None:
15f218
+        if output_format == "cluster.conf":
15f218
+            if not clufter.facts.cluster_pcs_flatiron("linux", dist.split(",")):
15f218
+                utils.err("dist does not match output-format")
15f218
+        elif output_format == "corosync.conf":
15f218
+            if not clufter.facts.cluster_pcs_needle("linux", dist.split(",")):
15f218
+                utils.err("dist does not match output-format")
15f218
+    elif (
15f218
+        (output_format == "cluster.conf" and utils.is_rhel6())
15f218
+        or
15f218
+        (output_format == "corosync.conf" and not utils.is_rhel6())
15f218
+    ):
15f218
+        dist = ",".join(platform.linux_distribution(full_distribution_name=0))
15f218
+    elif output_format == "cluster.conf":
15f218
+        dist = "redhat,6.7,Santiago"
15f218
+    elif output_format == "corosync.conf":
15f218
+        dist = "redhat,7.1,Maipo"
15f218
+    else:
15f218
+        # for output-format=pcs-command[-verbose]
15f218
+        dist = ",".join(platform.linux_distribution(full_distribution_name=0))
15f218
+
15f218
     clufter_args = {
15f218
         "input": str(cluster_conf),
15f218
         "cib": {"passin": "bytestring"},
15f218
         "nocheck": force,
15f218
         "batch": True,
15f218
         "sys": "linux",
15f218
+        "dist": dist,
15f218
         # Make it work on RHEL6 as well for sure
15f218
         "color": "always" if sys.stdout.isatty() else "never"
15f218
     }
15f218
@@ -606,11 +633,9 @@ def config_import_cman(argv):
15f218
         logging.getLogger("clufter").setLevel(logging.DEBUG)
15f218
     if output_format == "cluster.conf":
15f218
         clufter_args["ccs_pcmk"] = {"passin": "bytestring"}
15f218
-        clufter_args["dist"] = "redhat,6.7,Santiago"
15f218
         cmd_name = "ccs2pcs-flatiron"
15f218
     elif output_format == "corosync.conf":
15f218
         clufter_args["coro"] = {"passin": "struct"}
15f218
-        clufter_args["dist"] = "redhat,7.1,Maipo"
15f218
         cmd_name = "ccs2pcs-needle"
15f218
     elif output_format in ("pcs-commands", "pcs-commands-verbose"):
15f218
         clufter_args["output"] = {"passin": "bytestring"}
15f218
@@ -624,7 +649,15 @@ def config_import_cman(argv):
15f218
             clufter_args["text_width"] = "-1"
15f218
             clufter_args["silent"] = False
15f218
             clufter_args["noguidance"] = False
15f218
-        cmd_name = "ccs2pcscmd-flatiron"
15f218
+        if clufter.facts.cluster_pcs_flatiron("linux", dist.split(",")):
15f218
+            cmd_name = "ccs2pcscmd-flatiron"
15f218
+        elif clufter.facts.cluster_pcs_needle("linux", dist.split(",")):
15f218
+            cmd_name = "ccs2pcscmd-needle"
15f218
+        else:
15f218
+            utils.err(
15f218
+                "unrecognized dist, try something recognized"
15f218
+                + " (e. g. rhel,6.8 or redhat,7.3 or debian,7 or ubuntu,trusty)"
15f218
+            )
15f218
     clufter_args_obj = type(str("ClufterOptions"), (object, ), clufter_args)
15f218
 
15f218
     # run convertor
15f218
@@ -737,29 +770,36 @@ def config_export_pcs_commands(argv, verbose=False):
15f218
     interactive = "--interactive" in utils.pcs_options
15f218
     invalid_args = False
15f218
     output_file = None
15f218
+    dist = None
15f218
     for arg in argv:
15f218
         if "=" in arg:
15f218
             name, value = arg.split("=", 1)
15f218
             if name == "output":
15f218
                 output_file = value
15f218
+            elif name == "dist":
15f218
+                dist = value
15f218
             else:
15f218
                 invalid_args = True
15f218
         else:
15f218
             invalid_args = True
15f218
-    if invalid_args or not output_file:
15f218
+    # check options
15f218
+    if invalid_args:
15f218
         usage.config(["export", "pcs-commands"])
15f218
         sys.exit(1)
15f218
+    # complete optional options
15f218
+    if dist is None:
15f218
+        dist = ",".join(platform.linux_distribution(full_distribution_name=0))
15f218
 
15f218
     # prepare convertor options
15f218
     clufter_args = {
15f218
         "nocheck": force,
15f218
         "batch": True,
15f218
         "sys": "linux",
15f218
+        "dist": dist,
15f218
         # Make it work on RHEL6 as well for sure
15f218
         "color": "always" if sys.stdout.isatty() else "never",
15f218
         "coro": settings.corosync_conf_file,
15f218
         "ccs": settings.cluster_conf_file,
15f218
-        "output": {"passin": "bytestring"},
15f218
         "start_wait": "60",
15f218
         "tmp_cib": "tmp-cib.xml",
15f218
         "force": force,
15f218
@@ -767,6 +807,10 @@ def config_export_pcs_commands(argv, verbose=False):
15f218
         "silent": True,
15f218
         "noguidance": True,
15f218
     }
15f218
+    if output_file:
15f218
+        clufter_args["output"] = {"passin": "bytestring"}
15f218
+    else:
15f218
+        clufter_args["output"] = "-"
15f218
     if interactive:
15f218
         if "EDITOR" not in os.environ:
15f218
             utils.err("$EDITOR environment variable is not set")
15f218
@@ -791,13 +835,14 @@ def config_export_pcs_commands(argv, verbose=False):
15f218
         "Error: unable to export cluster configuration"
15f218
     )
15f218
 
15f218
-    # save commands
15f218
-    ok, message = utils.write_file(
15f218
-        output_file,
15f218
-        clufter_args_obj.output["passout"]
15f218
-    )
15f218
-    if not ok:
15f218
-        utils.err(message)
15f218
+    # save commands if not printed to stdout by clufter
15f218
+    if output_file:
15f218
+        ok, message = utils.write_file(
15f218
+            output_file,
15f218
+            clufter_args_obj.output["passout"]
15f218
+        )
15f218
+        if not ok:
15f218
+            utils.err(message)
15f218
 
15f218
 def run_clufter(cmd_name, cmd_args, debug, force, err_prefix):
15f218
     try:
15f218
diff --git a/pcs/pcs.8 b/pcs/pcs.8
15f218
index a26c94b..66ffb8c 100644
15f218
--- a/pcs/pcs.8
15f218
+++ b/pcs/pcs.8
15f218
@@ -624,14 +624,14 @@ Show specified configuration checkpoint.
15f218
 checkpoint restore <checkpoint_number>
15f218
 Restore cluster configuration to specified checkpoint.
15f218
 .TP
15f218
-import\-cman output=<filename> [input=<filename>] [\fB\-\-interactive\fR] [output\-format=corosync.conf|cluster.conf]
15f218
-Converts CMAN cluster configuration to Pacemaker cluster configuration.  Converted configuration will be saved to 'output' file.  To send the configuration to the cluster nodes the 'pcs config restore' command can be used.  If \fB\-\-interactive\fR is specified you will be prompted to solve incompatibilities manually.  If no input is specified /etc/cluster/cluster.conf will be used.  You can force to create output containing either cluster.conf or corosync.conf using the output-format option.
15f218
+import\-cman output=<filename> [input=<filename>] [\fB\-\-interactive\fR] [output\-format=corosync.conf|cluster.conf] [dist=<dist>]
15f218
+Converts CMAN cluster configuration to Pacemaker cluster configuration.  Converted configuration will be saved to 'output' file.  To send the configuration to the cluster nodes the 'pcs config restore' command can be used.  If \fB\-\-interactive\fR is specified you will be prompted to solve incompatibilities manually.  If no input is specified /etc/cluster/cluster.conf will be used.  You can force to create output containing either cluster.conf or corosync.conf using the output-format option.  Optionally you can specify output version by setting 'dist' option e. g. rhel,6.8 or redhat,7.3 or debian,7 or ubuntu,trusty.  If 'dist' is not specified, it defaults to this node's version if that matches output-format, otherwise redhat,6.7 is used for cluster.conf and redhat,7.1 is used for corosync.conf.
15f218
 .TP
15f218
-import\-cman output=<filename> [input=<filename>] [\fB\-\-interactive\fR] output\-format=pcs-commands|pcs-commands-verbose
15f218
+import\-cman output=<filename> [input=<filename>] [\fB\-\-interactive\fR] output\-format=pcs-commands|pcs-commands-verbose [dist=<dist>]
15f218
 Converts CMAN cluster configuration to a list of pcs commands which recreates the same cluster as Pacemaker cluster when executed.  Commands will be saved to 'output' file.  For other options see above.
15f218
 .TP
15f218
-export pcs\-commands|pcs\-commands\-verbose output=<filename>
15f218
-Creates a list of pcs commands which upon execution recreates the current cluster running on this node.  Commands will be saved to 'output' file.  Use pcs\-commands to get a simple list of commands, whereas pcs\-commands\-verbose creates a list including comments and debug messages.
15f218
+export pcs\-commands|pcs\-commands\-verbose output=<filename> [dist=<dist>]
15f218
+Creates a list of pcs commands which upon execution recreates the current cluster running on this node.  Commands will be saved to 'output' file or written to stdout if 'output' is not specified.  Use pcs\-commands to get a simple list of commands, whereas pcs\-commands\-verbose creates a list including comments and debug messages.  Optionally specify output version by setting 'dist' option e. g. rhel,6.8 or redhat,7.3 or debian,7 or ubuntu,trusty.  If 'dist' is not specified, it defaults to this node's version.
15f218
 .SS "pcsd"
15f218
 .TP
15f218
 certkey <certificate file> <key file>
15f218
diff --git a/pcs/usage.py b/pcs/usage.py
15f218
index 0605cd7..0474324 100644
15f218
--- a/pcs/usage.py
15f218
+++ b/pcs/usage.py
15f218
@@ -1173,7 +1173,7 @@ Commands:
15f218
         Restore cluster configuration to specified checkpoint.
15f218
 
15f218
     import-cman output=<filename> [input=<filename>] [--interactive]
15f218
-            [output-format=corosync.conf|cluster.conf]
15f218
+            [output-format=corosync.conf|cluster.conf] [dist=<dist>]
15f218
         Converts CMAN cluster configuration to Pacemaker cluster configuration.
15f218
         Converted configuration will be saved to 'output' file.  To send
15f218
         the configuration to the cluster nodes the 'pcs config restore'
15f218
@@ -1181,20 +1181,27 @@ Commands:
15f218
         prompted to solve incompatibilities manually.  If no input is specified
15f218
         /etc/cluster/cluster.conf will be used.  You can force to create output
15f218
         containing either cluster.conf or corosync.conf using the output-format
15f218
-        option.
15f218
+        option.  Optionally you can specify output version by setting 'dist'
15f218
+        option e. g. rhel,6.8 or redhat,7.3 or debian,7 or ubuntu,trusty.
15f218
+        If 'dist' is not specified, it defaults to this nodei's version if that
15f218
+        matches output-format, otherwise redhat,6.7 is used for cluster.conf
15f218
+        and redhat,7.1 is used for corosync.conf.
15f218
 
15f218
     import-cman output=<filename> [input=<filename>] [--interactive]
15f218
-            output-format=pcs-commands|pcs-commands-verbose
15f218
+            output-format=pcs-commands|pcs-commands-verbose [dist=<dist>]
15f218
         Converts CMAN cluster configuration to a list of pcs commands which
15f218
         recreates the same cluster as Pacemaker cluster when executed.  Commands
15f218
         will be saved to 'output' file.  For other options see above.
15f218
 
15f218
-    export pcs-commands|pcs-commands-verbose output=<filename>
15f218
+    export pcs-commands|pcs-commands-verbose [output=<filename>] [dist=<dist>]
15f218
         Creates a list of pcs commands which upon execution recreates
15f218
         the current cluster running on this node.  Commands will be saved
15f218
-        to 'output' file.  Use pcs-commands to get a simple list of commands,
15f218
-        whereas pcs-commands-verbose creates a list including comments and debug
15f218
-        messages.
15f218
+        to 'output' file or written to stdout if 'output' is not specified.  Use
15f218
+        pcs-commands to get a simple list of commands, whereas
15f218
+        pcs-commands-verbose creates a list including comments and debug
15f218
+        messages.  Optionally specify output version by setting 'dist' option
15f218
+        e. g. rhel,6.8 or redhat,7.3 or debian,7 or ubuntu,trusty.  If 'dist'
15f218
+        is not specified, it defaults to this node's version.
15f218
 """
15f218
     if pout:
15f218
         print(sub_usage(args, output))
15f218
-- 
15f218
1.8.3.1
15f218