Permalink
Browse files

PE: Bundles: Better support for net=host, allow the pacemaker-remote …

…port to change
  • Loading branch information...
beekhof committed Mar 22, 2017
1 parent 14a7cc2 commit 99502d17e5406c2402a4e630a3eaa95d2fe9434b
Showing with 64 additions and 12 deletions.
  1. +51 −8 lib/pengine/container.c
  2. +1 −0 lib/pengine/variant.h
  3. +9 −4 pengine/container.c
  4. +3 −0 xml/resources-2.8.rng
View
@@ -107,6 +107,22 @@ create_op(xmlNode *parent, const char *prefix, const char *task, const char *int
crm_xml_add(xml_op, "name", task);
}
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,
@@ -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_add(xml_obj, XML_ATTR_ID, id); free(id);
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));
}
id = crm_strdup_printf("%s-meta-%d", data->prefix, tuple->offset);
xml_obj = create_xml_node(xml_remote, XML_TAG_META_SETS);
@@ -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);
View
@@ -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;
View
@@ -177,17 +177,22 @@ 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(
tuple->docker, RSC_START, tuple->remote, RSC_START, pe_order_runnable_left, 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) {
View
@@ -99,6 +99,9 @@
<optional>
<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>

0 comments on commit 99502d1

Please sign in to comment.