root/lib/pengine/rules_compat.c

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

DEFINITIONS

This source file includes following definitions.
  1. test_rule
  2. map_rule_input
  3. pe_eval_nvpairs
  4. pe_unpack_nvpairs

   1 /*
   2  * Copyright 2004-2024 the Pacemaker project contributors
   3  *
   4  * The version control history for this file may have further details.
   5  *
   6  * This source code is licensed under the GNU Lesser General Public License
   7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <stdio.h>                      // NULL
  13 #include <glib.h>                       // gboolean, GList, GHashTable
  14 #include <libxml/tree.h>                // xmlNode
  15 
  16 #include <crm/crm.h>
  17 #include <crm/common/iso8601.h>         // crm_time_t
  18 #include <crm/common/roles.h>           // enum rsc_role_e
  19 
  20 #include <crm/common/xml.h>
  21 #include <crm/common/rules.h>           // pcmk_rule_input_t, etc.
  22 #include <crm/common/nvpair_internal.h> // pcmk__nvpair_unpack_t, etc.
  23 
  24 CRM_TRACE_INIT_DATA(pe_rules);
  25 
  26 // Deprecated functions kept only for backward API compatibility
  27 // LCOV_EXCL_START
  28 
  29 #include <crm/pengine/common_compat.h>
  30 #include <crm/pengine/rules_compat.h>
  31 
  32 gboolean
  33 test_rule(xmlNode * rule, GHashTable * node_hash, enum rsc_role_e role, crm_time_t * now)
     /* [previous][next][first][last][top][bottom][index][help] */
  34 {
  35     pcmk_rule_input_t rule_input = {
  36         .node_attrs = node_hash,
  37         .now = now,
  38     };
  39 
  40     return pcmk_evaluate_rule(rule, &rule_input, NULL) == pcmk_rc_ok;
  41 }
  42 
  43 /*!
  44  * \internal
  45  * \brief Map pe_rule_eval_data_t to pcmk_rule_input_t
  46  *
  47  * \param[out] new  New data struct
  48  * \param[in]  old  Old data struct
  49  */
  50 static void
  51 map_rule_input(pcmk_rule_input_t *new, const pe_rule_eval_data_t *old)
     /* [previous][next][first][last][top][bottom][index][help] */
  52 {
  53     if (old == NULL) {
  54         return;
  55     }
  56     new->now = old->now;
  57     new->node_attrs = old->node_hash;
  58     if (old->rsc_data != NULL) {
  59         new->rsc_standard = old->rsc_data->standard;
  60         new->rsc_provider = old->rsc_data->provider;
  61         new->rsc_agent = old->rsc_data->agent;
  62     }
  63     if (old->match_data != NULL) {
  64         new->rsc_params = old->match_data->params;
  65         new->rsc_meta = old->match_data->meta;
  66         if (old->match_data->re != NULL) {
  67             new->rsc_id = old->match_data->re->string;
  68             new->rsc_id_submatches = old->match_data->re->pmatch;
  69             new->rsc_id_nmatches = old->match_data->re->nregs;
  70         }
  71     }
  72     if (old->op_data != NULL) {
  73         new->op_name = old->op_data->op_name;
  74         new->op_interval_ms = old->op_data->interval;
  75     }
  76 }
  77 
  78 void
  79 pe_eval_nvpairs(xmlNode *top, const xmlNode *xml_obj, const char *set_name,
     /* [previous][next][first][last][top][bottom][index][help] */
  80                 const pe_rule_eval_data_t *rule_data, GHashTable *hash,
  81                 const char *always_first, gboolean overwrite,
  82                 crm_time_t *next_change)
  83 {
  84     GList *pairs = pcmk__xe_dereference_children(xml_obj, set_name);
  85 
  86     if (pairs) {
  87         pcmk__nvpair_unpack_t data = {
  88             .values = hash,
  89             .first_id = always_first,
  90             .overwrite = overwrite,
  91             .next_change = next_change,
  92         };
  93 
  94         map_rule_input(&(data.rule_input), rule_data);
  95 
  96         pairs = g_list_sort_with_data(pairs, pcmk__cmp_nvpair_blocks, &data);
  97         g_list_foreach(pairs, pcmk__unpack_nvpair_block, &data);
  98         g_list_free(pairs);
  99     }
 100 }
 101 
 102 void
 103 pe_unpack_nvpairs(xmlNode *top, const xmlNode *xml_obj, const char *set_name,
     /* [previous][next][first][last][top][bottom][index][help] */
 104                   GHashTable *node_hash, GHashTable *hash,
 105                   const char *always_first, gboolean overwrite,
 106                   crm_time_t *now, crm_time_t *next_change)
 107 {
 108     pe_rule_eval_data_t rule_data = {
 109         .node_hash = node_hash,
 110         .now = now,
 111         .match_data = NULL,
 112         .rsc_data = NULL,
 113         .op_data = NULL
 114     };
 115 
 116     pe_eval_nvpairs(NULL, xml_obj, set_name, &rule_data, hash,
 117                     always_first, overwrite, next_change);
 118 }
 119 
 120 // LCOV_EXCL_STOP
 121 // End deprecated API

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