]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/volumes/fs/operations/op_sm.py
3 from typing
import Dict
5 from ..exception
import OpSmException
8 INIT_STATE_KEY
= 'init'
10 FAILED_STATE
= 'failed'
11 FINAL_STATE
= 'complete'
12 CANCEL_STATE
= 'canceled'
15 INIT_STATE_KEY
: FINAL_STATE
,
19 INIT_STATE_KEY
: 'pending',
20 'pending' : ('in-progress', (FAILED_STATE
, CANCEL_STATE
)),
21 'in-progress' : (FINAL_STATE
, (FAILED_STATE
, CANCEL_STATE
)),
24 STATE_MACHINES_TYPES
= {
25 "subvolume" : OP_SM_SUBVOLUME
,
26 "clone" : OP_SM_CLONE
,
30 def is_final_state(state
):
31 return state
== OpSm
.FINAL_STATE
34 def is_failed_state(state
):
35 return state
== OpSm
.FAILED_STATE
or state
== OpSm
.CANCEL_STATE
38 def is_init_state(stm_type
, state
):
39 stm
= OpSm
.STATE_MACHINES_TYPES
.get(stm_type
, None)
41 raise OpSmException(-errno
.ENOENT
, "state machine type '{0}' not found".format(stm_type
))
42 init_state
= stm
.get(OpSm
.INIT_STATE_KEY
, None)
43 return init_state
== state
46 def get_init_state(stm_type
):
47 stm
= OpSm
.STATE_MACHINES_TYPES
.get(stm_type
, None)
49 raise OpSmException(-errno
.ENOENT
, "state machine type '{0}' not found".format(stm_type
))
50 init_state
= stm
.get(OpSm
.INIT_STATE_KEY
, None)
52 raise OpSmException(-errno
.ENOENT
, "initial state unavailable for state machine '{0}'".format(stm_type
))
56 def get_next_state(stm_type
, current_state
, ret
):
57 stm
= OpSm
.STATE_MACHINES_TYPES
.get(stm_type
, None)
59 raise OpSmException(-errno
.ENOENT
, "state machine type '{0}' not found".format(stm_type
))
60 next_state
= stm
.get(current_state
, None)
62 raise OpSmException(-errno
.EINVAL
, "invalid current state '{0}'".format(current_state
))
65 elif ret
== -errno
.EINTR
:
66 return next_state
[1][1]
68 return next_state
[1][0]