root/lib/common/roles.c

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

DEFINITIONS

This source file includes following definitions.
  1. pcmk_role_text
  2. pcmk_parse_role

   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 <crm/common/scheduler.h>
  13 #include <crm/common/scheduler_internal.h>
  14 
  15 /*!
  16  * \brief Get readable description of a resource role
  17  *
  18  * \param[in] role  Resource role
  19  *
  20  * \return Static string describing \p role, suitable for logging or display
  21  */
  22 const char *
  23 pcmk_role_text(enum rsc_role_e role)
     /* [previous][next][first][last][top][bottom][index][help] */
  24 {
  25     switch (role) {
  26         case pcmk_role_stopped:
  27             return PCMK_ROLE_STOPPED;
  28 
  29         case pcmk_role_started:
  30             return PCMK_ROLE_STARTED;
  31 
  32         case pcmk_role_unpromoted:
  33 #ifdef PCMK__COMPAT_2_0
  34             return PCMK__ROLE_UNPROMOTED_LEGACY;
  35 #else
  36             return PCMK_ROLE_UNPROMOTED;
  37 #endif
  38 
  39         case pcmk_role_promoted:
  40 #ifdef PCMK__COMPAT_2_0
  41             return PCMK__ROLE_PROMOTED_LEGACY;
  42 #else
  43             return PCMK_ROLE_PROMOTED;
  44 #endif
  45 
  46         default: // pcmk_role_unknown
  47             return PCMK__ROLE_UNKNOWN;
  48     }
  49 }
  50 
  51 /*!
  52  * \brief Parse a resource role from a string role specification
  53  *
  54  * \param[in] role  Role specification
  55  *
  56  * \return Resource role corresponding to \p role
  57  */
  58 enum rsc_role_e
  59 pcmk_parse_role(const char *role)
     /* [previous][next][first][last][top][bottom][index][help] */
  60 {
  61     if (pcmk__str_eq(role, PCMK__ROLE_UNKNOWN,
  62                      pcmk__str_casei|pcmk__str_null_matches)) {
  63         return pcmk_role_unknown;
  64     } else if (pcmk__str_eq(role, PCMK_ROLE_STOPPED, pcmk__str_casei)) {
  65         return pcmk_role_stopped;
  66     } else if (pcmk__str_eq(role, PCMK_ROLE_STARTED, pcmk__str_casei)) {
  67         return pcmk_role_started;
  68     } else if (pcmk__str_eq(role, PCMK__ROLE_UNPROMOTED_LEGACY, pcmk__str_casei)) {
  69         pcmk__warn_once(pcmk__wo_slave_role,
  70                         "Support for the " PCMK__ROLE_UNPROMOTED_LEGACY
  71                         " role is deprecated and will be removed in a "
  72                         "future release. Use " PCMK_ROLE_UNPROMOTED
  73                         " instead.");
  74         return pcmk_role_unpromoted;
  75     } else if (pcmk__str_eq(role, PCMK_ROLE_UNPROMOTED, pcmk__str_casei)) {
  76         return pcmk_role_unpromoted;
  77     } else if (pcmk__str_eq(role, PCMK__ROLE_PROMOTED_LEGACY, pcmk__str_casei)) {
  78         pcmk__warn_once(pcmk__wo_master_role,
  79                         "Support for the " PCMK__ROLE_PROMOTED_LEGACY
  80                         " role is deprecated and will be removed in a "
  81                         "future release. Use " PCMK_ROLE_PROMOTED
  82                         " instead.");
  83         return pcmk_role_promoted;
  84     } else if (pcmk__str_eq(role, PCMK_ROLE_PROMOTED, pcmk__str_casei)) {
  85         return pcmk_role_promoted;
  86     }
  87     return pcmk_role_unknown; // Invalid role given
  88 }

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