Blame SOURCES/040-bundle-control-port.patch

60de42
From 14a7cc23e9e3b619f280dcc6d5032a17e84283b0 Mon Sep 17 00:00:00 2001
60de42
From: Andrew Beekhof <andrew@beekhof.net>
60de42
Date: Wed, 22 Mar 2017 11:25:22 +1100
60de42
Subject: [PATCH 1/2] Remote: Allow the port to listen on to be specified on
60de42
 the commandline
60de42
60de42
---
60de42
 lrmd/main.c | 6 ++++++
60de42
 1 file changed, 6 insertions(+)
60de42
60de42
diff --git a/lrmd/main.c b/lrmd/main.c
60de42
index a3aa08f..ddba619 100644
60de42
--- a/lrmd/main.c
60de42
+++ b/lrmd/main.c
60de42
@@ -403,6 +403,9 @@ static struct crm_option long_options[] = {
60de42
     {"verbose", 0, 0,    'V', "\tIncrease debug output"},
60de42
 
60de42
     {"logfile", 1, 0,    'l', "\tSend logs to the additional named logfile"},
60de42
+#ifndef ENABLE_PCMK_REMOTE
60de42
+    {"port", 1, 0,       'p', "\tPort to listen on"},
60de42
+#endif
60de42
 
60de42
     /* For compatibility with the original lrmd */
60de42
     {"dummy",  0, 0, 'r', NULL, 1},
60de42
@@ -440,6 +443,9 @@ main(int argc, char **argv)
60de42
             case 'l':
60de42
                 crm_add_logfile(optarg);
60de42
                 break;
60de42
+            case 'p':
60de42
+                setenv("PCMK_remote_port", optarg, 1);
60de42
+                break;
60de42
             case 'V':
60de42
                 crm_bump_log_level(argc, argv);
60de42
                 break;
60de42
-- 
60de42
1.8.3.1
60de42
60de42
60de42
From 99502d17e5406c2402a4e630a3eaa95d2fe9434b Mon Sep 17 00:00:00 2001
60de42
From: Andrew Beekhof <andrew@beekhof.net>
60de42
Date: Wed, 22 Mar 2017 11:29:51 +1100
60de42
Subject: [PATCH 2/2] PE: Bundles: Better support for net=host, allow the
60de42
 pacemaker-remote port to change
60de42
60de42
---
60de42
 lib/pengine/container.c | 59 ++++++++++++++++++++++++++++++++++++++++++-------
60de42
 lib/pengine/variant.h   |  1 +
60de42
 pengine/container.c     | 13 +++++++----
60de42
 xml/resources-2.8.rng   |  3 +++
60de42
 4 files changed, 64 insertions(+), 12 deletions(-)
60de42
60de42
diff --git a/lib/pengine/container.c b/lib/pengine/container.c
60de42
index d7d47ad..4018f70 100644
60de42
--- a/lib/pengine/container.c
60de42
+++ b/lib/pengine/container.c
60de42
@@ -108,6 +108,22 @@ create_op(xmlNode *parent, const char *prefix, const char *task, const char *int
60de42
 }
60de42
 
60de42
 static bool
60de42
+valid_network(container_variant_data_t *data)
60de42
+{
60de42
+    if(data->ip_range_start) {
60de42
+        return TRUE;
60de42
+    }
60de42
+    if(data->control_port && crm_str_eq(data->docker_network, "host", TRUE)) {
60de42
+        if(data->replicas_per_host > 1) {
60de42
+            pe_err("Specifying the 'control-port' with 'internal-network=host' for %s requires 'replicas-per-host=1'", data->prefix);
60de42
+            data->replicas_per_host = 1;
60de42
+        }
60de42
+        return TRUE;
60de42
+    }
60de42
+    return FALSE;
60de42
+}
60de42
+
60de42
+static bool
60de42
 create_ip_resource(
60de42
     resource_t *parent, container_variant_data_t *data, container_grouping_t *tuple,
60de42
     pe_working_set_t * data_set) 
60de42
@@ -203,8 +219,12 @@ create_docker_resource(
60de42
         for(GListPtr pIter = data->ports; pIter != NULL; pIter = pIter->next) {
60de42
             char *port = pIter->data;
60de42
 
60de42
-            offset += snprintf(buffer+offset, max-offset, " -p %s:%s:%s",
60de42
-                               tuple->ipaddr, port, port);
60de42
+            if(tuple->ipaddr) {
60de42
+                offset += snprintf(buffer+offset, max-offset, " -p %s:%s:%s",
60de42
+                                   tuple->ipaddr, port, port);
60de42
+            } else {
60de42
+                offset += snprintf(buffer+offset, max-offset, " -p %s:%s", port, port);
60de42
+            }
60de42
         }
60de42
 
60de42
         if(data->docker_run_options) {
60de42
@@ -222,7 +242,15 @@ create_docker_resource(
60de42
         free(dbuffer);
60de42
 
60de42
         if(tuple->child) {
60de42
-            create_nvp(xml_obj, "run_cmd", SBIN_DIR"/pacemaker_remoted");
60de42
+            char *command = NULL;
60de42
+
60de42
+            if(data->control_port) {
60de42
+                command = crm_strdup_printf(SBIN_DIR"/pacemaker_remoted -p %s", data->control_port);
60de42
+            } else {
60de42
+                command = crm_strdup_printf(SBIN_DIR"/pacemaker_remoted -p %d", DEFAULT_REMOTE_PORT);
60de42
+            }
60de42
+            create_nvp(xml_obj, "run_cmd", command);
60de42
+            free(command);
60de42
 
60de42
             /* TODO: Allow users to specify their own?
60de42
              *
60de42
@@ -270,7 +298,7 @@ create_remote_resource(
60de42
     resource_t *parent, container_variant_data_t *data, container_grouping_t *tuple,
60de42
     pe_working_set_t * data_set) 
60de42
 {
60de42
-    if(tuple->ip && tuple->child) {
60de42
+    if(valid_network(data) && tuple->child) {
60de42
         node_t *node = NULL;
60de42
         xmlNode *xml_obj = NULL;
60de42
         xmlNode *xml_remote = NULL;
60de42
@@ -292,8 +320,17 @@ create_remote_resource(
60de42
         xml_obj = create_xml_node(xml_remote, XML_TAG_ATTR_SETS);
60de42
         crm_xml_set_id(xml_obj, "%s-attributes-%d", data->prefix, tuple->offset);
60de42
 
60de42
-        create_nvp(xml_obj, "addr", tuple->ipaddr);
60de42
-        create_nvp(xml_obj, "port", crm_itoa(DEFAULT_REMOTE_PORT));
60de42
+        if(tuple->ipaddr) {
60de42
+            create_nvp(xml_obj, "addr", tuple->ipaddr);
60de42
+        } else {
60de42
+            create_nvp(xml_obj, "addr", "localhost");
60de42
+        }
60de42
+
60de42
+        if(data->control_port) {
60de42
+            create_nvp(xml_obj, "port", data->control_port);
60de42
+        } else {
60de42
+            create_nvp(xml_obj, "port", crm_itoa(DEFAULT_REMOTE_PORT));
60de42
+        }
60de42
 
60de42
         xml_obj = create_xml_node(xml_remote, XML_TAG_META_SETS);
60de42
         crm_xml_set_id(xml_obj, "%s-meta-%d", data->prefix, tuple->offset);
60de42
@@ -405,6 +442,7 @@ container_unpack(resource_t * rsc, pe_working_set_t * data_set)
60de42
         container_data->ip_range_start = crm_element_value_copy(xml_obj, "ip-range-start");
60de42
         container_data->host_netmask = crm_element_value_copy(xml_obj, "host-netmask");
60de42
         container_data->host_network = crm_element_value_copy(xml_obj, "host-network");
60de42
+        container_data->control_port = crm_element_value_copy(xml_obj, "control-port");
60de42
         container_data->docker_network = crm_element_value_copy(xml_obj, "docker-network");
60de42
 
60de42
         for (xmlNode *xml_child = __xml_first_child_element(xml_obj); xml_child != NULL;
60de42
@@ -447,7 +485,7 @@ container_unpack(resource_t * rsc, pe_working_set_t * data_set)
60de42
     }
60de42
 
60de42
     xml_obj = first_named_child(rsc->xml, "primitive");
60de42
-    if(xml_obj && container_data->ip_range_start && container_data->replicas > 0) {
60de42
+    if(xml_obj && valid_network(container_data) && container_data->replicas > 0) {
60de42
         char *value = NULL;
60de42
         xmlNode *xml_set = NULL;
60de42
 
60de42
@@ -523,7 +561,11 @@ container_unpack(resource_t * rsc, pe_working_set_t * data_set)
60de42
         mount->flags = 1;
60de42
         container_data->mounts = g_list_append(container_data->mounts, mount);
60de42
 
60de42
-        container_data->ports = g_list_append(container_data->ports, crm_itoa(DEFAULT_REMOTE_PORT));
60de42
+        if(container_data->control_port) {
60de42
+            container_data->ports = g_list_append(container_data->ports, container_data->control_port);
60de42
+        } else {
60de42
+            container_data->ports = g_list_append(container_data->ports, crm_itoa(DEFAULT_REMOTE_PORT));
60de42
+        }
60de42
 
60de42
         if (common_unpack(xml_resource, &new_rsc, rsc, data_set) == FALSE) {
60de42
             pe_err("Failed unpacking resource %s", crm_element_value(rsc->xml, XML_ATTR_ID));
60de42
@@ -779,6 +821,7 @@ container_free(resource_t * rsc)
60de42
 
60de42
     free(container_data->prefix);
60de42
     free(container_data->image);
60de42
+    free(container_data->control_port);
60de42
     free(container_data->host_network);
60de42
     free(container_data->host_netmask);
60de42
     free(container_data->ip_range_start);
60de42
diff --git a/lib/pengine/variant.h b/lib/pengine/variant.h
60de42
index b02aeb0..4a9e2fe 100644
60de42
--- a/lib/pengine/variant.h
60de42
+++ b/lib/pengine/variant.h
60de42
@@ -87,6 +87,7 @@ typedef struct container_variant_data_s {
60de42
         const char *ip_last;
60de42
         char *host_network;
60de42
         char *host_netmask;
60de42
+        char *control_port;
60de42
         char *docker_network;
60de42
         char *ip_range_start;
60de42
         char *docker_host_options;
60de42
diff --git a/pengine/container.c b/pengine/container.c
60de42
index 84f2f16..b66b7b0 100644
60de42
--- a/pengine/container.c
60de42
+++ b/pengine/container.c
60de42
@@ -177,7 +177,6 @@ container_internal_constraints(resource_t * rsc, pe_working_set_t * data_set)
60de42
         }
60de42
 
60de42
         if(tuple->remote) {
60de42
-            CRM_ASSERT(tuple->ip);
60de42
             tuple->remote->cmds->internal_constraints(tuple->remote, data_set);
60de42
             // Start docker then remote
60de42
             new_rsc_order(
60de42
@@ -185,9 +184,15 @@ container_internal_constraints(resource_t * rsc, pe_working_set_t * data_set)
60de42
             new_rsc_order(
60de42
                 tuple->remote, RSC_STOP, tuple->docker, RSC_STOP, pe_order_implies_first, data_set);
60de42
 
60de42
-            id = crm_strdup_printf("%s-remote-with-ip-%d", rsc->id, tuple->offset);
60de42
-            rsc_colocation_new(id, NULL, INFINITY, tuple->remote, tuple->ip, NULL, NULL, data_set);
60de42
-            free(id);
60de42
+            if(tuple->ip) {
60de42
+                id = crm_strdup_printf("%s-remote-with-ip-%d", rsc->id, tuple->offset);
60de42
+                rsc_colocation_new(id, NULL, INFINITY, tuple->remote, tuple->ip, NULL, NULL, data_set);
60de42
+                free(id);
60de42
+            } else {
60de42
+                id = crm_strdup_printf("%s-remote-with-docker-%d", rsc->id, tuple->offset);
60de42
+                rsc_colocation_new(id, NULL, INFINITY, tuple->remote, tuple->docker, NULL, NULL, data_set);
60de42
+                free(id);
60de42
+            }
60de42
         }
60de42
 
60de42
         if(tuple->child) {
60de42
diff --git a/xml/resources-2.8.rng b/xml/resources-2.8.rng
60de42
index 6329fea..1382bba 100644
60de42
--- a/xml/resources-2.8.rng
60de42
+++ b/xml/resources-2.8.rng
60de42
@@ -100,6 +100,9 @@
60de42
 	      <attribute name="ip-range-start"><text/></attribute>
60de42
 	    </optional>
60de42
 	    <optional>
60de42
+	      <attribute name="control-port"><data type="integer"/></attribute>
60de42
+	    </optional>
60de42
+	    <optional>
60de42
 	      <attribute name="host-network"><text/></attribute>
60de42
 	    </optional>
60de42
 	    <optional>
60de42
-- 
60de42
1.8.3.1
60de42