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             return PCMK_ROLE_UNPROMOTED;
  34 
  35         case pcmk_role_promoted:
  36             return PCMK_ROLE_PROMOTED;
  37 
  38         default: // pcmk_role_unknown
  39             return PCMK__ROLE_UNKNOWN;
  40     }
  41 }
  42 
  43 /*!
  44  * \brief Parse a resource role from a string role specification
  45  *
  46  * \param[in] role  Role specification
  47  *
  48  * \return Resource role corresponding to \p role
  49  */
  50 enum rsc_role_e
  51 pcmk_parse_role(const char *role)
     /* [previous][next][first][last][top][bottom][index][help] */
  52 {
  53     if (pcmk__str_eq(role, PCMK__ROLE_UNKNOWN,
  54                      pcmk__str_casei|pcmk__str_null_matches)) {
  55         return pcmk_role_unknown;
  56     } else if (pcmk__str_eq(role, PCMK_ROLE_STOPPED, pcmk__str_casei)) {
  57         return pcmk_role_stopped;
  58     } else if (pcmk__str_eq(role, PCMK_ROLE_STARTED, pcmk__str_casei)) {
  59         return pcmk_role_started;
  60     } else if (pcmk__str_eq(role, PCMK__ROLE_UNPROMOTED_LEGACY, pcmk__str_casei)) {
  61         pcmk__warn_once(pcmk__wo_slave_role,
  62                         "Support for the " PCMK__ROLE_UNPROMOTED_LEGACY
  63                         " role is deprecated and will be removed in a "
  64                         "future release. Use " PCMK_ROLE_UNPROMOTED
  65                         " instead.");
  66         return pcmk_role_unpromoted;
  67     } else if (pcmk__str_eq(role, PCMK_ROLE_UNPROMOTED, pcmk__str_casei)) {
  68         return pcmk_role_unpromoted;
  69     } else if (pcmk__str_eq(role, PCMK__ROLE_PROMOTED_LEGACY, pcmk__str_casei)) {
  70         pcmk__warn_once(pcmk__wo_master_role,
  71                         "Support for the " PCMK__ROLE_PROMOTED_LEGACY
  72                         " role is deprecated and will be removed in a "
  73                         "future release. Use " PCMK_ROLE_PROMOTED
  74                         " instead.");
  75         return pcmk_role_promoted;
  76     } else if (pcmk__str_eq(role, PCMK_ROLE_PROMOTED, pcmk__str_casei)) {
  77         return pcmk_role_promoted;
  78     }
  79     return pcmk_role_unknown; // Invalid role given
  80 }

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