10 from mgr_module
import MgrModule
12 from .common
import NotAuthorizedError
13 from .mirror_snapshot_schedule
import MirrorSnapshotScheduleHandler
14 from .perf
import PerfHandler
15 from .task
import TaskHandler
16 from .trash_purge_schedule
import TrashPurgeScheduleHandler
19 class Module(MgrModule
):
22 "cmd": "rbd mirror snapshot schedule add "
23 "name=level_spec,type=CephString "
24 "name=interval,type=CephString "
25 "name=start_time,type=CephString,req=false ",
26 "desc": "Add rbd mirror snapshot schedule",
30 "cmd": "rbd mirror snapshot schedule remove "
31 "name=level_spec,type=CephString "
32 "name=interval,type=CephString,req=false "
33 "name=start_time,type=CephString,req=false ",
34 "desc": "Remove rbd mirror snapshot schedule",
38 "cmd": "rbd mirror snapshot schedule list "
39 "name=level_spec,type=CephString,req=false ",
40 "desc": "List rbd mirror snapshot schedule",
44 "cmd": "rbd mirror snapshot schedule status "
45 "name=level_spec,type=CephString,req=false ",
46 "desc": "Show rbd mirror snapshot schedule status",
50 "cmd": "rbd perf image stats "
51 "name=pool_spec,type=CephString,req=false "
52 "name=sort_by,type=CephChoices,strings="
53 "write_ops|write_bytes|write_latency|"
54 "read_ops|read_bytes|read_latency,"
56 "desc": "Retrieve current RBD IO performance stats",
60 "cmd": "rbd perf image counters "
61 "name=pool_spec,type=CephString,req=false "
62 "name=sort_by,type=CephChoices,strings="
63 "write_ops|write_bytes|write_latency|"
64 "read_ops|read_bytes|read_latency,"
66 "desc": "Retrieve current RBD IO performance counters",
70 "cmd": "rbd task add flatten "
71 "name=image_spec,type=CephString",
72 "desc": "Flatten a cloned image asynchronously in the background",
76 "cmd": "rbd task add remove "
77 "name=image_spec,type=CephString",
78 "desc": "Remove an image asynchronously in the background",
82 "cmd": "rbd task add trash remove "
83 "name=image_id_spec,type=CephString",
84 "desc": "Remove an image from the trash asynchronously in the background",
88 "cmd": "rbd task add migration execute "
89 "name=image_spec,type=CephString",
90 "desc": "Execute an image migration asynchronously in the background",
94 "cmd": "rbd task add migration commit "
95 "name=image_spec,type=CephString",
96 "desc": "Commit an executed migration asynchronously in the background",
100 "cmd": "rbd task add migration abort "
101 "name=image_spec,type=CephString",
102 "desc": "Abort a prepared migration asynchronously in the background",
106 "cmd": "rbd task cancel "
107 "name=task_id,type=CephString ",
108 "desc": "Cancel a pending or running asynchronous task",
112 "cmd": "rbd task list "
113 "name=task_id,type=CephString,req=false ",
114 "desc": "List pending or running asynchronous tasks",
118 "cmd": "rbd trash purge schedule add "
119 "name=level_spec,type=CephString "
120 "name=interval,type=CephString "
121 "name=start_time,type=CephString,req=false ",
122 "desc": "Add rbd trash purge schedule",
126 "cmd": "rbd trash purge schedule remove "
127 "name=level_spec,type=CephString "
128 "name=interval,type=CephString,req=false "
129 "name=start_time,type=CephString,req=false ",
130 "desc": "Remove rbd trash purge schedule",
134 "cmd": "rbd trash purge schedule list "
135 "name=level_spec,type=CephString,req=false ",
136 "desc": "List rbd trash purge schedule",
140 "cmd": "rbd trash purge schedule status "
141 "name=level_spec,type=CephString,req=false ",
142 "desc": "Show rbd trash purge schedule status",
147 {'name': MirrorSnapshotScheduleHandler
.MODULE_OPTION_NAME
},
148 {'name': TrashPurgeScheduleHandler
.MODULE_OPTION_NAME
},
151 mirror_snapshot_schedule
= None
154 trash_purge_schedule
= None
156 def __init__(self
, *args
, **kwargs
):
157 super(Module
, self
).__init
__(*args
, **kwargs
)
158 self
.rados
.wait_for_latest_osdmap()
159 self
.mirror_snapshot_schedule
= MirrorSnapshotScheduleHandler(self
)
160 self
.perf
= PerfHandler(self
)
161 self
.task
= TaskHandler(self
)
162 self
.trash_purge_schedule
= TrashPurgeScheduleHandler(self
)
164 def handle_command(self
, inbuf
, cmd
):
165 # ensure we have latest pools available
166 self
.rados
.wait_for_latest_osdmap()
168 prefix
= cmd
['prefix']
171 if prefix
.startswith('rbd mirror snapshot schedule '):
172 return self
.mirror_snapshot_schedule
.handle_command(
173 inbuf
, prefix
[29:], cmd
)
174 elif prefix
.startswith('rbd perf '):
175 return self
.perf
.handle_command(inbuf
, prefix
[9:], cmd
)
176 elif prefix
.startswith('rbd task '):
177 return self
.task
.handle_command(inbuf
, prefix
[9:], cmd
)
178 elif prefix
.startswith('rbd trash purge schedule '):
179 return self
.trash_purge_schedule
.handle_command(
180 inbuf
, prefix
[25:], cmd
)
182 except NotAuthorizedError
:
184 except Exception as ex
:
185 # log the full traceback but don't send it to the CLI user
186 self
.log
.fatal("Fatal runtime error: {}\n{}".format(
187 ex
, traceback
.format_exc()))
190 except rados
.Error
as ex
:
191 return -ex
.errno
, "", str(ex
)
192 except rbd
.OSError as ex
:
193 return -ex
.errno
, "", str(ex
)
194 except rbd
.Error
as ex
:
195 return -errno
.EINVAL
, "", str(ex
)
196 except KeyError as ex
:
197 return -errno
.ENOENT
, "", str(ex
)
198 except ValueError as ex
:
199 return -errno
.EINVAL
, "", str(ex
)
200 except NotAuthorizedError
as ex
:
201 return -errno
.EACCES
, "", str(ex
)
203 raise NotImplementedError(cmd
['prefix'])