pacemaker  1.1.18-7fdfbbe
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
remote.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #include <crm_internal.h>
19 #include <crm/msg_xml.h>
20 #include <crm/common/xml.h>
21 #include <crm/pengine/internal.h>
22 #include <glib.h>
23 
24 gboolean
26 {
27  node_t *node;
28 
29  if (rsc == NULL) {
30  return FALSE;
31  } else if (rsc->is_remote_node == FALSE) {
32  return FALSE;
33  }
34 
35  node = pe_find_node(data_set->nodes, rsc->id);
36  if (node == NULL) {
37  return FALSE;
38  }
39 
40  return is_baremetal_remote_node(node);
41 }
42 
43 gboolean
45 {
46  if (is_remote_node(node) && (node->details->remote_rsc == NULL || node->details->remote_rsc->container == FALSE)) {
47  return TRUE;
48  }
49  return FALSE;
50 }
51 
52 gboolean
54 {
55  if (is_remote_node(node) && (node->details->remote_rsc && node->details->remote_rsc->container)) {
56  return TRUE;
57  }
58  return FALSE;
59 }
60 
61 gboolean
63 {
64  if (node && node->details->type == node_remote) {
65  return TRUE;
66  }
67  return FALSE;
68 }
69 
70 resource_t *
72 {
73  if (is_set(data_set->flags, pe_flag_have_remote_nodes) == FALSE) {
74  return NULL;
75  }
76 
77  if (rsc->fillers) {
78  GListPtr gIter = NULL;
79  for (gIter = rsc->fillers; gIter != NULL; gIter = gIter->next) {
80  resource_t *filler = (resource_t *) gIter->data;
81 
82  if (filler->is_remote_node) {
83  return filler;
84  }
85  }
86  }
87  return NULL;
88 }
89 
90 gboolean
92 {
93  const char *class = crm_element_value(xml, XML_AGENT_ATTR_CLASS);
94  const char *provider = crm_element_value(xml, XML_AGENT_ATTR_PROVIDER);
95  const char *agent = crm_element_value(xml, XML_ATTR_TYPE);
96 
97  if (safe_str_eq(agent, "remote") && safe_str_eq(provider, "pacemaker")
99  return TRUE;
100  }
101  return FALSE;
102 }
103 
113 void
115  void (*helper)(const node_t*, void*), void *user_data)
116 {
117  GListPtr iter;
118 
119  CRM_CHECK(data_set && host && host->details && helper, return);
120  if (!is_set(data_set->flags, pe_flag_have_remote_nodes)) {
121  return;
122  }
123  for (iter = host->details->running_rsc; iter != NULL; iter = iter->next) {
124  resource_t *rsc = (resource_t *) iter->data;
125 
126  if (rsc->is_remote_node && (rsc->container != NULL)) {
127  node_t *guest_node = pe_find_node(data_set->nodes, rsc->id);
128 
129  if (guest_node) {
130  (*helper)(guest_node, user_data);
131  }
132  }
133  }
134 }
135 
157 xmlNode *
158 pe_create_remote_xml(xmlNode *parent, const char *uname,
159  const char *container_id, const char *migrateable,
160  const char *is_managed, const char *interval,
161  const char *monitor_timeout, const char *start_timeout,
162  const char *server, const char *port)
163 {
164  xmlNode *remote;
165  xmlNode *xml_sub;
166 
167  remote = create_xml_node(parent, XML_CIB_TAG_RESOURCE);
168 
169  // Add identity
170  crm_xml_add(remote, XML_ATTR_ID, uname);
172  crm_xml_add(remote, XML_AGENT_ATTR_PROVIDER, "pacemaker");
173  crm_xml_add(remote, XML_ATTR_TYPE, "remote");
174 
175  // Add meta-attributes
176  xml_sub = create_xml_node(remote, XML_TAG_META_SETS);
177  crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_META_SETS);
178  crm_create_nvpair_xml(xml_sub, NULL,
180  if (container_id) {
181  crm_create_nvpair_xml(xml_sub, NULL,
182  XML_RSC_ATTR_CONTAINER, container_id);
183  }
184  if (migrateable) {
185  crm_create_nvpair_xml(xml_sub, NULL,
186  XML_OP_ATTR_ALLOW_MIGRATE, migrateable);
187  }
188  if (is_managed) {
189  crm_create_nvpair_xml(xml_sub, NULL, XML_RSC_ATTR_MANAGED, is_managed);
190  }
191 
192  // Add instance attributes
193  if (port || server) {
194  xml_sub = create_xml_node(remote, XML_TAG_ATTR_SETS);
195  crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_ATTR_SETS);
196  if (server) {
197  crm_create_nvpair_xml(xml_sub, NULL, "addr", server);
198  }
199  if (port) {
200  crm_create_nvpair_xml(xml_sub, NULL, "port", port);
201  }
202  }
203 
204  // Add operations
205  if (interval || start_timeout) {
206  xml_sub = create_xml_node(remote, "operations");
207  if (interval) {
208  crm_create_op_xml(xml_sub, uname, "monitor", interval,
209  monitor_timeout);
210  }
211  if (start_timeout) {
212  crm_create_op_xml(xml_sub, uname, "start", "0", start_timeout);
213  }
214  }
215  return remote;
216 }
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:164
GListPtr nodes
Definition: status.h:107
#define XML_ATTR_TYPE
Definition: msg_xml.h:105
#define pe_flag_have_remote_nodes
Definition: status.h:80
resource_t * rsc_contains_remote_node(pe_working_set_t *data_set, resource_t *rsc)
Definition: remote.c:71
GListPtr running_rsc
Definition: status.h:153
node_t * pe_find_node(GListPtr node_list, const char *uname)
Definition: status.c:301
AIS_Host host
Definition: internal.h:52
resource_t * remote_rsc
Definition: status.h:156
gboolean is_remote_node
Definition: status.h:279
gboolean is_rsc_baremetal_remote_node(resource_t *rsc, pe_working_set_t *data_set)
Definition: remote.c:25
char * id
Definition: status.h:257
#define XML_TAG_ATTR_SETS
Definition: msg_xml.h:184
char uname[MAX_NAME]
Definition: internal.h:53
gboolean is_remote_node(node_t *node)
Definition: remote.c:62
struct node_shared_s * details
Definition: status.h:178
void pe_foreach_guest_node(const pe_working_set_t *data_set, const node_t *host, void(*helper)(const node_t *, void *), void *user_data)
Definition: remote.c:114
#define PCMK_RESOURCE_CLASS_OCF
Definition: services.h:57
xmlNode * pe_create_remote_xml(xmlNode *parent, const char *uname, const char *container_id, const char *migrateable, const char *is_managed, const char *interval, const char *monitor_timeout, const char *start_timeout, const char *server, const char *port)
Definition: remote.c:158
#define XML_RSC_ATTR_CONTAINER
Definition: msg_xml.h:229
#define XML_ATTR_ID
Definition: msg_xml.h:102
#define XML_CIB_TAG_RESOURCE
Definition: msg_xml.h:195
#define XML_BOOLEAN_TRUE
Definition: msg_xml.h:117
resource_t * container
Definition: status.h:307
gboolean is_baremetal_remote_node(node_t *node)
Definition: remote.c:44
gboolean is_container_remote_node(node_t *node)
Definition: remote.c:53
xmlNode * crm_create_op_xml(xmlNode *parent, const char *prefix, const char *task, const char *interval, const char *timeout)
Create a CIB XML element for an operation.
Definition: operations.c:439
#define XML_AGENT_ATTR_PROVIDER
Definition: msg_xml.h:254
#define XML_TAG_META_SETS
Definition: msg_xml.h:185
Wrappers for and extensions to libxml2.
#define XML_RSC_ATTR_MANAGED
Definition: msg_xml.h:218
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:2588
const char * crm_element_value(xmlNode *data, const char *name)
Definition: xml.c:5165
GListPtr fillers
Definition: status.h:308
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Definition: xml.c:2490
gboolean xml_contains_remote_node(xmlNode *xml)
Definition: remote.c:91
void crm_xml_set_id(xmlNode *xml, const char *format,...) __attribute__((__format__(__printf__
xmlNode * crm_create_nvpair_xml(xmlNode *parent, const char *id, const char *name, const char *value)
Create an XML name/value pair.
Definition: xml.c:4831
#define XML_RSC_ATTR_INTERNAL_RSC
Definition: msg_xml.h:230
enum node_type type
Definition: status.h:159
Definition: status.h:174
unsigned long long flags
Definition: status.h:95
#define safe_str_eq(a, b)
Definition: util.h:72
GList * GListPtr
Definition: crm.h:218
#define XML_OP_ATTR_ALLOW_MIGRATE
Definition: msg_xml.h:240
#define XML_AGENT_ATTR_CLASS
Definition: msg_xml.h:253