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 #ifndef PCMK__CRM_COMMON_RULES__H 11 #define PCMK__CRM_COMMON_RULES__H 12 13 #include <glib.h> // guint, GHashTable 14 #include <regex.h> // regmatch_t 15 #include <libxml/tree.h> // xmlNode 16 #include <crm/common/iso8601.h> // crm_time_t 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 /*! 23 * \file 24 * \brief Scheduler API for rules 25 * \ingroup core 26 */ 27 28 /* Allowed subexpressions of a rule 29 * @COMPAT This should be made internal at an API compatibility break 30 */ 31 //!@{ 32 //! \deprecated For Pacemaker use only 33 enum expression_type { 34 pcmk__condition_unknown = 0, // Unknown or invalid condition 35 pcmk__condition_rule = 1, // Nested rule 36 pcmk__condition_attribute = 2, // Node attribute expression 37 pcmk__condition_location = 3, // Node location expression 38 pcmk__condition_datetime = 5, // Date/time expression 39 pcmk__condition_resource = 7, // Resource agent expression 40 pcmk__condition_operation = 8, // Operation expression 41 42 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1) 43 not_expr = pcmk__condition_unknown, 44 nested_rule = pcmk__condition_rule, 45 attr_expr = pcmk__condition_attribute, 46 loc_expr = pcmk__condition_location, 47 role_expr = 4, 48 time_expr = pcmk__condition_datetime, 49 version_expr = 6, 50 rsc_expr = pcmk__condition_resource, 51 op_expr = pcmk__condition_operation, 52 #endif 53 }; 54 //!@} 55 56 //! Data used to evaluate a rule (any NULL items are ignored) 57 typedef struct pcmk_rule_input { 58 // Used to evaluate date expressions 59 const crm_time_t *now; //!< Current time for rule evaluation purposes 60 61 // Used to evaluate resource type expressions 62 const char *rsc_standard; //!< Resource standard that rule applies to 63 const char *rsc_provider; //!< Resource provider that rule applies to 64 const char *rsc_agent; //!< Resource agent that rule applies to 65 66 // Used to evaluate operation type expressions 67 const char *op_name; //! Operation name that rule applies to 68 guint op_interval_ms; //! Operation interval that rule applies to 69 70 // Remaining members are used to evaluate node attribute expressions 71 72 /*! 73 * Node attributes for rule evaluation purposes 74 * 75 * \note Though not const, this is used only with g_hash_table_lookup(). 76 */ 77 GHashTable *node_attrs; 78 79 // Remaining members are used only within location constraint rules 80 81 /*! 82 * Resource parameters that can be used as the reference value source 83 * 84 * \note Though not const, this is used only with g_hash_table_lookup(). 85 */ 86 GHashTable *rsc_params; 87 88 /*! 89 * Resource meta-attributes that can be used as the reference value source 90 * 91 * \note Though not const, this is used only with g_hash_table_lookup(). 92 */ 93 GHashTable *rsc_meta; 94 95 //! Resource ID to compare against a location constraint's resource pattern 96 const char *rsc_id; 97 98 //! Resource pattern submatches (as set by regexec()) for rsc_id 99 const regmatch_t *rsc_id_submatches; 100 101 //! Number of entries in rsc_id_submatches 102 int rsc_id_nmatches; 103 } pcmk_rule_input_t; 104 105 int pcmk_evaluate_rule(xmlNode *rule, const pcmk_rule_input_t *rule_input, 106 crm_time_t *next_change); 107 108 #ifdef __cplusplus 109 } 110 #endif 111 112 #endif // PCMK__CRM_COMMON_RULES__H