]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/restful/common.py
update sources to 12.2.8
[ceph.git] / ceph / src / pybind / mgr / restful / common.py
1 # List of valid osd flags
2 OSD_FLAGS = [
3 'pause', 'noup', 'nodown', 'noout', 'noin', 'nobackfill',
4 'norecover', 'noscrub', 'nodeep-scrub',
5 ]
6
7 # Implemented osd commands
8 OSD_IMPLEMENTED_COMMANDS = [
9 'scrub', 'deep_scrub', 'repair'
10 ]
11
12 # Valid values for the 'var' argument to 'ceph osd pool set'
13 POOL_PROPERTIES_1 = [
14 'size', 'min_size', 'crash_replay_interval', 'pg_num',
15 'crush_rule', 'hashpspool', 'auid',
16 ]
17
18 POOL_PROPERTIES_2 = [
19 'pgp_num'
20 ]
21
22 POOL_PROPERTIES = POOL_PROPERTIES_1 + POOL_PROPERTIES_2
23
24 # Valid values for the 'ceph osd pool set-quota' command
25 POOL_QUOTA_PROPERTIES = [
26 ('quota_max_bytes', 'max_bytes'),
27 ('quota_max_objects', 'max_objects'),
28 ]
29
30 POOL_ARGS = POOL_PROPERTIES + [x for x,_ in POOL_QUOTA_PROPERTIES]
31
32
33 # Transform command to a human readable form
34 def humanify_command(command):
35 out = [command['prefix']]
36
37 for arg, val in command.iteritems():
38 if arg != 'prefix':
39 out.append("%s=%s" % (str(arg), str(val)))
40
41 return " ".join(out)
42
43
44 def invalid_pool_args(args):
45 invalid = []
46 for arg in args:
47 if arg not in POOL_ARGS:
48 invalid.append(arg)
49
50 return invalid
51
52
53 def pool_update_commands(pool_name, args):
54 commands = [[], []]
55
56 # We should increase pgp_num when we are re-setting pg_num
57 if 'pg_num' in args and 'pgp_num' not in args:
58 args['pgp_num'] = args['pg_num']
59
60 # Run the first pool set and quota properties in parallel
61 for var in POOL_PROPERTIES_1:
62 if var in args:
63 commands[0].append({
64 'prefix': 'osd pool set',
65 'pool': pool_name,
66 'var': var,
67 'val': args[var],
68 })
69
70 for (var, field) in POOL_QUOTA_PROPERTIES:
71 if var in args:
72 commands[0].append({
73 'prefix': 'osd pool set-quota',
74 'pool': pool_name,
75 'field': field,
76 'val': str(args[var]),
77 })
78
79 # The second pool set properties need to be run after the first wave
80 for var in POOL_PROPERTIES_2:
81 if var in args:
82 commands[1].append({
83 'prefix': 'osd pool set',
84 'pool': pool_name,
85 'var': var,
86 'val': args[var],
87 })
88
89 return commands
90
91
92 def crush_rule_osds(nodes, rule):
93 nodes_by_id = dict((n['id'], n) for n in nodes)
94
95 def _gather_leaf_ids(node):
96 if node['id'] >= 0:
97 return set([node['id']])
98
99 result = set()
100 for child_id in node['children']:
101 if child_id >= 0:
102 result.add(child_id)
103 else:
104 result |= _gather_leaf_ids(nodes_by_id[child_id])
105
106 return result
107
108 def _gather_descendent_ids(node, typ):
109 result = set()
110 for child_id in node['children']:
111 child_node = nodes_by_id[child_id]
112 if child_node['type'] == typ:
113 result.add(child_node['id'])
114 elif 'children' in child_node:
115 result |= _gather_descendent_ids(child_node, typ)
116
117 return result
118
119 def _gather_osds(root, steps):
120 if root['id'] >= 0:
121 return set([root['id']])
122
123 osds = set()
124 step = steps[0]
125 if step['op'] == 'choose_firstn':
126 # Choose all descendents of the current node of type 'type'
127 d = _gather_descendent_ids(root, step['type'])
128 for desc_node in [nodes_by_id[i] for i in d]:
129 osds |= _gather_osds(desc_node, steps[1:])
130 elif step['op'] == 'chooseleaf_firstn':
131 # Choose all descendents of the current node of type 'type',
132 # and select all leaves beneath those
133 for desc_node in [nodes_by_id[i] for i in _gather_descendent_ids(root, step['type'])]:
134 # Short circuit another iteration to find the emit
135 # and assume anything we've done a chooseleaf on
136 # is going to be part of the selected set of osds
137 osds |= _gather_leaf_ids(desc_node)
138 elif step['op'] == 'emit':
139 if root['id'] >= 0:
140 osds |= root['id']
141
142 return osds
143
144 osds = set()
145 for i, step in enumerate(rule['steps']):
146 if step['op'] == 'take':
147 osds |= _gather_osds(nodes_by_id[step['item']], rule['steps'][i + 1:])
148 return osds