root/lib/pengine/remote.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. is_rsc_baremetal_remote_node
  2. is_baremetal_remote_node
  3. is_container_remote_node
  4. is_remote_node
  5. rsc_contains_remote_node
  6. xml_contains_remote_node
  7. pe_foreach_guest_node
  8. pe_create_remote_xml

   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
  25 is_rsc_baremetal_remote_node(resource_t *rsc, pe_working_set_t * data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
  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
  44 is_baremetal_remote_node(node_t *node)
     /* [previous][next][first][last][top][bottom][index][help] */
  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
  53 is_container_remote_node(node_t *node)
     /* [previous][next][first][last][top][bottom][index][help] */
  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
  62 is_remote_node(node_t *node)
     /* [previous][next][first][last][top][bottom][index][help] */
  63 {
  64     if (node && node->details->type == node_remote) {
  65         return TRUE;
  66     }
  67     return FALSE;
  68 }
  69 
  70 resource_t *
  71 rsc_contains_remote_node(pe_working_set_t * data_set, resource_t *rsc)
     /* [previous][next][first][last][top][bottom][index][help] */
  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
  91 xml_contains_remote_node(xmlNode *xml)
     /* [previous][next][first][last][top][bottom][index][help] */
  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")
  98         && safe_str_eq(class, PCMK_RESOURCE_CLASS_OCF)) {
  99         return TRUE;
 100     }
 101     return FALSE;
 102 }
 103 
 104 /*!
 105  * \internal
 106  * \brief Execute a supplied function for each guest node running on a host
 107  *
 108  * \param[in]     data_set   Working set for cluster
 109  * \param[in]     host       Host node to check
 110  * \param[in]     helper     Function to call for each guest node
 111  * \param[in,out] user_data  Pointer to pass to helper function
 112  */
 113 void
 114 pe_foreach_guest_node(const pe_working_set_t *data_set, const node_t *host,
     /* [previous][next][first][last][top][bottom][index][help] */
 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 
 136 /*!
 137  * \internal
 138  * \brief Create CIB XML for an implicit remote connection
 139  *
 140  * \param[in] parent           If not NULL, use as parent XML element
 141  * \param[in] uname            Name of Pacemaker Remote node
 142  * \param[in] container        If not NULL, use this as connection container
 143  * \param[in] migrateable      If not NULL, use as allow-migrate value
 144  * \param[in] is_managed       If not NULL, use as is-managed value
 145  * \param[in] interval         If not NULL, create recurring monitor with this interval
 146  * \param[in] monitor_timeout  If not NULL, use as remote connect timeout
 147  * \param[in] start_timeout    If not NULL, use as remote connect timeout
 148  * \param[in] server           If not NULL, use as remote server value
 149  * \param[in] port             If not NULL, use as remote port value
 150  *
 151  * \note We should standardize on a single interval and monitor_timeout, but
 152  *       that would cause LRM history entries in active mixed-version clusters
 153  *       (and regression tests) to require a new monitor operation due to
 154  *       changed parameters. It might be worthwhile to do at a significant
 155  *       version bump.
 156  */
 157 xmlNode *
 158 pe_create_remote_xml(xmlNode *parent, const char *uname,
     /* [previous][next][first][last][top][bottom][index][help] */
 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);
 171     crm_xml_add(remote, XML_AGENT_ATTR_CLASS, PCMK_RESOURCE_CLASS_OCF);
 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,
 179                           XML_RSC_ATTR_INTERNAL_RSC, XML_BOOLEAN_TRUE);
 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 }

/* [previous][next][first][last][top][bottom][index][help] */