Blob Blame History Raw
From 14a7cc23e9e3b619f280dcc6d5032a17e84283b0 Mon Sep 17 00:00:00 2001
From: Andrew Beekhof <andrew@beekhof.net>
Date: Wed, 22 Mar 2017 11:25:22 +1100
Subject: [PATCH 1/2] Remote: Allow the port to listen on to be specified on
 the commandline

---
 lrmd/main.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lrmd/main.c b/lrmd/main.c
index a3aa08f..ddba619 100644
--- a/lrmd/main.c
+++ b/lrmd/main.c
@@ -403,6 +403,9 @@ static struct crm_option long_options[] = {
     {"verbose", 0, 0,    'V', "\tIncrease debug output"},
 
     {"logfile", 1, 0,    'l', "\tSend logs to the additional named logfile"},
+#ifndef ENABLE_PCMK_REMOTE
+    {"port", 1, 0,       'p', "\tPort to listen on"},
+#endif
 
     /* For compatibility with the original lrmd */
     {"dummy",  0, 0, 'r', NULL, 1},
@@ -440,6 +443,9 @@ main(int argc, char **argv)
             case 'l':
                 crm_add_logfile(optarg);
                 break;
+            case 'p':
+                setenv("PCMK_remote_port", optarg, 1);
+                break;
             case 'V':
                 crm_bump_log_level(argc, argv);
                 break;
-- 
1.8.3.1


From 99502d17e5406c2402a4e630a3eaa95d2fe9434b Mon Sep 17 00:00:00 2001
From: Andrew Beekhof <andrew@beekhof.net>
Date: Wed, 22 Mar 2017 11:29:51 +1100
Subject: [PATCH 2/2] PE: Bundles: Better support for net=host, allow the
 pacemaker-remote port to change

---
 lib/pengine/container.c | 59 ++++++++++++++++++++++++++++++++++++++++++-------
 lib/pengine/variant.h   |  1 +
 pengine/container.c     | 13 +++++++----
 xml/resources-2.8.rng   |  3 +++
 4 files changed, 64 insertions(+), 12 deletions(-)

diff --git a/lib/pengine/container.c b/lib/pengine/container.c
index d7d47ad..4018f70 100644
--- a/lib/pengine/container.c
+++ b/lib/pengine/container.c
@@ -108,6 +108,22 @@ create_op(xmlNode *parent, const char *prefix, const char *task, const char *int
 }
 
 static bool
+valid_network(container_variant_data_t *data)
+{
+    if(data->ip_range_start) {
+        return TRUE;
+    }
+    if(data->control_port && crm_str_eq(data->docker_network, "host", TRUE)) {
+        if(data->replicas_per_host > 1) {
+            pe_err("Specifying the 'control-port' with 'internal-network=host' for %s requires 'replicas-per-host=1'", data->prefix);
+            data->replicas_per_host = 1;
+        }
+        return TRUE;
+    }
+    return FALSE;
+}
+
+static bool
 create_ip_resource(
     resource_t *parent, container_variant_data_t *data, container_grouping_t *tuple,
     pe_working_set_t * data_set) 
@@ -203,8 +219,12 @@ create_docker_resource(
         for(GListPtr pIter = data->ports; pIter != NULL; pIter = pIter->next) {
             char *port = pIter->data;
 
-            offset += snprintf(buffer+offset, max-offset, " -p %s:%s:%s",
-                               tuple->ipaddr, port, port);
+            if(tuple->ipaddr) {
+                offset += snprintf(buffer+offset, max-offset, " -p %s:%s:%s",
+                                   tuple->ipaddr, port, port);
+            } else {
+                offset += snprintf(buffer+offset, max-offset, " -p %s:%s", port, port);
+            }
         }
 
         if(data->docker_run_options) {
@@ -222,7 +242,15 @@ create_docker_resource(
         free(dbuffer);
 
         if(tuple->child) {
-            create_nvp(xml_obj, "run_cmd", SBIN_DIR"/pacemaker_remoted");
+            char *command = NULL;
+
+            if(data->control_port) {
+                command = crm_strdup_printf(SBIN_DIR"/pacemaker_remoted -p %s", data->control_port);
+            } else {
+                command = crm_strdup_printf(SBIN_DIR"/pacemaker_remoted -p %d", DEFAULT_REMOTE_PORT);
+            }
+            create_nvp(xml_obj, "run_cmd", command);
+            free(command);
 
             /* TODO: Allow users to specify their own?
              *
@@ -270,7 +298,7 @@ create_remote_resource(
     resource_t *parent, container_variant_data_t *data, container_grouping_t *tuple,
     pe_working_set_t * data_set) 
 {
-    if(tuple->ip && tuple->child) {
+    if(valid_network(data) && tuple->child) {
         node_t *node = NULL;
         xmlNode *xml_obj = NULL;
         xmlNode *xml_remote = NULL;
@@ -292,8 +320,17 @@ create_remote_resource(
         xml_obj = create_xml_node(xml_remote, XML_TAG_ATTR_SETS);
         crm_xml_set_id(xml_obj, "%s-attributes-%d", data->prefix, tuple->offset);
 
-        create_nvp(xml_obj, "addr", tuple->ipaddr);
-        create_nvp(xml_obj, "port", crm_itoa(DEFAULT_REMOTE_PORT));
+        if(tuple->ipaddr) {
+            create_nvp(xml_obj, "addr", tuple->ipaddr);
+        } else {
+            create_nvp(xml_obj, "addr", "localhost");
+        }
+
+        if(data->control_port) {
+            create_nvp(xml_obj, "port", data->control_port);
+        } else {
+            create_nvp(xml_obj, "port", crm_itoa(DEFAULT_REMOTE_PORT));
+        }
 
         xml_obj = create_xml_node(xml_remote, XML_TAG_META_SETS);
         crm_xml_set_id(xml_obj, "%s-meta-%d", data->prefix, tuple->offset);
@@ -405,6 +442,7 @@ container_unpack(resource_t * rsc, pe_working_set_t * data_set)
         container_data->ip_range_start = crm_element_value_copy(xml_obj, "ip-range-start");
         container_data->host_netmask = crm_element_value_copy(xml_obj, "host-netmask");
         container_data->host_network = crm_element_value_copy(xml_obj, "host-network");
+        container_data->control_port = crm_element_value_copy(xml_obj, "control-port");
         container_data->docker_network = crm_element_value_copy(xml_obj, "docker-network");
 
         for (xmlNode *xml_child = __xml_first_child_element(xml_obj); xml_child != NULL;
@@ -447,7 +485,7 @@ container_unpack(resource_t * rsc, pe_working_set_t * data_set)
     }
 
     xml_obj = first_named_child(rsc->xml, "primitive");
-    if(xml_obj && container_data->ip_range_start && container_data->replicas > 0) {
+    if(xml_obj && valid_network(container_data) && container_data->replicas > 0) {
         char *value = NULL;
         xmlNode *xml_set = NULL;
 
@@ -523,7 +561,11 @@ container_unpack(resource_t * rsc, pe_working_set_t * data_set)
         mount->flags = 1;
         container_data->mounts = g_list_append(container_data->mounts, mount);
 
-        container_data->ports = g_list_append(container_data->ports, crm_itoa(DEFAULT_REMOTE_PORT));
+        if(container_data->control_port) {
+            container_data->ports = g_list_append(container_data->ports, container_data->control_port);
+        } else {
+            container_data->ports = g_list_append(container_data->ports, crm_itoa(DEFAULT_REMOTE_PORT));
+        }
 
         if (common_unpack(xml_resource, &new_rsc, rsc, data_set) == FALSE) {
             pe_err("Failed unpacking resource %s", crm_element_value(rsc->xml, XML_ATTR_ID));
@@ -779,6 +821,7 @@ container_free(resource_t * rsc)
 
     free(container_data->prefix);
     free(container_data->image);
+    free(container_data->control_port);
     free(container_data->host_network);
     free(container_data->host_netmask);
     free(container_data->ip_range_start);
diff --git a/lib/pengine/variant.h b/lib/pengine/variant.h
index b02aeb0..4a9e2fe 100644
--- a/lib/pengine/variant.h
+++ b/lib/pengine/variant.h
@@ -87,6 +87,7 @@ typedef struct container_variant_data_s {
         const char *ip_last;
         char *host_network;
         char *host_netmask;
+        char *control_port;
         char *docker_network;
         char *ip_range_start;
         char *docker_host_options;
diff --git a/pengine/container.c b/pengine/container.c
index 84f2f16..b66b7b0 100644
--- a/pengine/container.c
+++ b/pengine/container.c
@@ -177,7 +177,6 @@ container_internal_constraints(resource_t * rsc, pe_working_set_t * data_set)
         }
 
         if(tuple->remote) {
-            CRM_ASSERT(tuple->ip);
             tuple->remote->cmds->internal_constraints(tuple->remote, data_set);
             // Start docker then remote
             new_rsc_order(
@@ -185,9 +184,15 @@ container_internal_constraints(resource_t * rsc, pe_working_set_t * data_set)
             new_rsc_order(
                 tuple->remote, RSC_STOP, tuple->docker, RSC_STOP, pe_order_implies_first, data_set);
 
-            id = crm_strdup_printf("%s-remote-with-ip-%d", rsc->id, tuple->offset);
-            rsc_colocation_new(id, NULL, INFINITY, tuple->remote, tuple->ip, NULL, NULL, data_set);
-            free(id);
+            if(tuple->ip) {
+                id = crm_strdup_printf("%s-remote-with-ip-%d", rsc->id, tuple->offset);
+                rsc_colocation_new(id, NULL, INFINITY, tuple->remote, tuple->ip, NULL, NULL, data_set);
+                free(id);
+            } else {
+                id = crm_strdup_printf("%s-remote-with-docker-%d", rsc->id, tuple->offset);
+                rsc_colocation_new(id, NULL, INFINITY, tuple->remote, tuple->docker, NULL, NULL, data_set);
+                free(id);
+            }
         }
 
         if(tuple->child) {
diff --git a/xml/resources-2.8.rng b/xml/resources-2.8.rng
index 6329fea..1382bba 100644
--- a/xml/resources-2.8.rng
+++ b/xml/resources-2.8.rng
@@ -100,6 +100,9 @@
 	      <attribute name="ip-range-start"><text/></attribute>
 	    </optional>
 	    <optional>
+	      <attribute name="control-port"><data type="integer"/></attribute>
+	    </optional>
+	    <optional>
 	      <attribute name="host-network"><text/></attribute>
 	    </optional>
 	    <optional>
-- 
1.8.3.1