]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/restful/common.py
bump version to 18.2.2-pve1
[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', 'pg_num',
15 'crush_rule', 'hashpspool',
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.items():
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 def crush_rule_osds(node_buckets, rule):
92 nodes_by_id = dict((b['id'], b) for b in node_buckets)
93
94 def _gather_leaf_ids(node_id):
95 if node_id >= 0:
96 return set([node_id])
97
98 result = set()
99 for item in nodes_by_id[node_id]['items']:
100 result |= _gather_leaf_ids(item['id'])
101
102 return result
103
104 def _gather_descendent_ids(node, typ):
105 result = set()
106 for item in node['items']:
107 if item['id'] >= 0:
108 if typ == "osd":
109 result.add(item['id'])
110 else:
111 child_node = nodes_by_id[item['id']]
112 if child_node['type_name'] == typ:
113 result.add(child_node['id'])
114 elif 'items' 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 descendent_ids = _gather_descendent_ids(root, step['type'])
128 for node_id in descendent_ids:
129 if node_id >= 0:
130 osds.add(node_id)
131 else:
132 osds |= _gather_osds(nodes_by_id[node_id], steps[1:])
133 elif step['op'] == 'chooseleaf_firstn':
134 # Choose all descendents of the current node of type 'type',
135 # and select all leaves beneath those
136 descendent_ids = _gather_descendent_ids(root, step['type'])
137 for node_id in descendent_ids:
138 if node_id >= 0:
139 osds.add(node_id)
140 else:
141 for desc_node in nodes_by_id[node_id]['items']:
142 # Short circuit another iteration to find the emit
143 # and assume anything we've done a chooseleaf on
144 # is going to be part of the selected set of osds
145 osds |= _gather_leaf_ids(desc_node['id'])
146 elif step['op'] == 'emit':
147 if root['id'] >= 0:
148 osds |= root['id']
149
150 return osds
151
152 osds = set()
153 for i, step in enumerate(rule['steps']):
154 if step['op'] == 'take':
155 osds |= _gather_osds(nodes_by_id[step['item']], rule['steps'][i + 1:])
156 return osds