1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
"""
RBD support module
"""
import errno
import rados
import rbd
import traceback
from mgr_module import MgrModule
from .common import NotAuthorizedError
from .mirror_snapshot_schedule import MirrorSnapshotScheduleHandler
from .perf import PerfHandler
from .task import TaskHandler
from .trash_purge_schedule import TrashPurgeScheduleHandler
class Module(MgrModule):
COMMANDS = [
{
"cmd": "rbd mirror snapshot schedule add "
"name=level_spec,type=CephString "
"name=interval,type=CephString "
"name=start_time,type=CephString,req=false ",
"desc": "Add rbd mirror snapshot schedule",
"perm": "w"
},
{
"cmd": "rbd mirror snapshot schedule remove "
"name=level_spec,type=CephString "
"name=interval,type=CephString,req=false "
"name=start_time,type=CephString,req=false ",
"desc": "Remove rbd mirror snapshot schedule",
"perm": "w"
},
{
"cmd": "rbd mirror snapshot schedule list "
"name=level_spec,type=CephString,req=false ",
"desc": "List rbd mirror snapshot schedule",
"perm": "r"
},
{
"cmd": "rbd mirror snapshot schedule status "
"name=level_spec,type=CephString,req=false ",
"desc": "Show rbd mirror snapshot schedule status",
"perm": "r"
},
{
"cmd": "rbd perf image stats "
"name=pool_spec,type=CephString,req=false "
"name=sort_by,type=CephChoices,strings="
"write_ops|write_bytes|write_latency|"
"read_ops|read_bytes|read_latency,"
"req=false ",
"desc": "Retrieve current RBD IO performance stats",
"perm": "r"
},
{
"cmd": "rbd perf image counters "
"name=pool_spec,type=CephString,req=false "
"name=sort_by,type=CephChoices,strings="
"write_ops|write_bytes|write_latency|"
"read_ops|read_bytes|read_latency,"
"req=false ",
"desc": "Retrieve current RBD IO performance counters",
"perm": "r"
},
{
"cmd": "rbd task add flatten "
"name=image_spec,type=CephString",
"desc": "Flatten a cloned image asynchronously in the background",
"perm": "w"
},
{
"cmd": "rbd task add remove "
"name=image_spec,type=CephString",
"desc": "Remove an image asynchronously in the background",
"perm": "w"
},
{
"cmd": "rbd task add trash remove "
"name=image_id_spec,type=CephString",
"desc": "Remove an image from the trash asynchronously in the background",
"perm": "w"
},
{
"cmd": "rbd task add migration execute "
"name=image_spec,type=CephString",
"desc": "Execute an image migration asynchronously in the background",
"perm": "w"
},
{
"cmd": "rbd task add migration commit "
"name=image_spec,type=CephString",
"desc": "Commit an executed migration asynchronously in the background",
"perm": "w"
},
{
"cmd": "rbd task add migration abort "
"name=image_spec,type=CephString",
"desc": "Abort a prepared migration asynchronously in the background",
"perm": "w"
},
{
"cmd": "rbd task cancel "
"name=task_id,type=CephString ",
"desc": "Cancel a pending or running asynchronous task",
"perm": "r"
},
{
"cmd": "rbd task list "
"name=task_id,type=CephString,req=false ",
"desc": "List pending or running asynchronous tasks",
"perm": "r"
},
{
"cmd": "rbd trash purge schedule add "
"name=level_spec,type=CephString "
"name=interval,type=CephString "
"name=start_time,type=CephString,req=false ",
"desc": "Add rbd trash purge schedule",
"perm": "w"
},
{
"cmd": "rbd trash purge schedule remove "
"name=level_spec,type=CephString "
"name=interval,type=CephString,req=false "
"name=start_time,type=CephString,req=false ",
"desc": "Remove rbd trash purge schedule",
"perm": "w"
},
{
"cmd": "rbd trash purge schedule list "
"name=level_spec,type=CephString,req=false ",
"desc": "List rbd trash purge schedule",
"perm": "r"
},
{
"cmd": "rbd trash purge schedule status "
"name=level_spec,type=CephString,req=false ",
"desc": "Show rbd trash purge schedule status",
"perm": "r"
}
]
MODULE_OPTIONS = [
{'name': MirrorSnapshotScheduleHandler.MODULE_OPTION_NAME},
{'name': MirrorSnapshotScheduleHandler.MODULE_OPTION_NAME_MAX_CONCURRENT_SNAP_CREATE, 'type': 'int', 'default': 10},
{'name': TrashPurgeScheduleHandler.MODULE_OPTION_NAME},
]
mirror_snapshot_schedule = None
perf = None
task = None
trash_purge_schedule = None
def __init__(self, *args, **kwargs):
super(Module, self).__init__(*args, **kwargs)
self.rados.wait_for_latest_osdmap()
self.mirror_snapshot_schedule = MirrorSnapshotScheduleHandler(self)
self.perf = PerfHandler(self)
self.task = TaskHandler(self)
self.trash_purge_schedule = TrashPurgeScheduleHandler(self)
def handle_command(self, inbuf, cmd):
# ensure we have latest pools available
self.rados.wait_for_latest_osdmap()
prefix = cmd['prefix']
try:
try:
if prefix.startswith('rbd mirror snapshot schedule '):
return self.mirror_snapshot_schedule.handle_command(
inbuf, prefix[29:], cmd)
elif prefix.startswith('rbd perf '):
return self.perf.handle_command(inbuf, prefix[9:], cmd)
elif prefix.startswith('rbd task '):
return self.task.handle_command(inbuf, prefix[9:], cmd)
elif prefix.startswith('rbd trash purge schedule '):
return self.trash_purge_schedule.handle_command(
inbuf, prefix[25:], cmd)
except NotAuthorizedError:
raise
except Exception as ex:
# log the full traceback but don't send it to the CLI user
self.log.fatal("Fatal runtime error: {}\n{}".format(
ex, traceback.format_exc()))
raise
except rados.Error as ex:
return -ex.errno, "", str(ex)
except rbd.OSError as ex:
return -ex.errno, "", str(ex)
except rbd.Error as ex:
return -errno.EINVAL, "", str(ex)
except KeyError as ex:
return -errno.ENOENT, "", str(ex)
except ValueError as ex:
return -errno.EINVAL, "", str(ex)
except NotAuthorizedError as ex:
return -errno.EACCES, "", str(ex)
raise NotImplementedError(cmd['prefix'])
|