Currently, the code base mostly uses strings to represent actions
(like 'start', 'redeploy, 'reconfig', ...). Add a new Action class
to utils.py to have a crisper typing-friendly representation for
actions.
This is added to support net new code. While I'd like to see this
used more the goal is to prevent errors in the new approach and I
don't plan on immediately going back through all of cephadm
and finding and replacing all action strings right away.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
import socket
from enum import Enum
from functools import wraps
-from typing import Optional, Callable, TypeVar, List, NewType, TYPE_CHECKING, Any, NamedTuple
+from typing import (
+ Any,
+ Callable,
+ List,
+ NamedTuple,
+ NewType,
+ Optional,
+ TYPE_CHECKING,
+ TypeVar,
+ Union,
+)
from orchestrator import OrchestratorError
import hashlib
return self.value
+class Action(str, Enum):
+ NO_ACTION = ''
+ RECONFIG = 'reconfig'
+ REDEPLOY = 'redeploy'
+ RESTART = 'restart'
+ ROTATE_KEY = 'rotate-key'
+ START = 'start'
+ STOP = 'stop'
+
+ @classmethod
+ def create(cls, action: Union[str, 'Action', None]) -> 'Action':
+ if not action:
+ return cls.NO_ACTION
+ return cls(action)
+
+ def __str__(self) -> str:
+ return self.value
+
+
def name_to_config_section(name: str) -> ConfEntity:
"""
Map from daemon names to ceph entity names (as seen in config)