]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/restful/common.py
1 # List of valid osd flags
3 'pause', 'noup', 'nodown', 'noout', 'noin', 'nobackfill',
4 'norecover', 'noscrub', 'nodeep-scrub',
7 # Implemented osd commands
8 OSD_IMPLEMENTED_COMMANDS
= [
9 'scrub', 'deep_scrub', 'repair'
12 # Valid values for the 'var' argument to 'ceph osd pool set'
14 'size', 'min_size', 'crash_replay_interval', 'pg_num',
15 'crush_rule', 'hashpspool', 'auid',
22 POOL_PROPERTIES
= POOL_PROPERTIES_1
+ POOL_PROPERTIES_2
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'),
30 POOL_ARGS
= POOL_PROPERTIES
+ [x
for x
,_
in POOL_QUOTA_PROPERTIES
]
33 # Transform command to a human readable form
34 def humanify_command(command
):
35 out
= [command
['prefix']]
37 for arg
, val
in command
.iteritems():
39 out
.append("%s=%s" % (str(arg
), str(val
)))
44 def invalid_pool_args(args
):
47 if arg
not in POOL_ARGS
:
53 def pool_update_commands(pool_name
, args
):
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']
60 # Run the first pool set and quota properties in parallel
61 for var
in POOL_PROPERTIES_1
:
64 'prefix': 'osd pool set',
70 for (var
, field
) in POOL_QUOTA_PROPERTIES
:
73 'prefix': 'osd pool set-quota',
76 'val': str(args
[var
]),
79 # The second pool set properties need to be run after the first wave
80 for var
in POOL_PROPERTIES_2
:
83 'prefix': 'osd pool set',
92 def crush_rule_osds(nodes
, rule
):
93 nodes_by_id
= dict((n
['id'], n
) for n
in nodes
)
95 def _gather_leaf_ids(node
):
97 return set([node
['id']])
100 for child_id
in node
['children']:
104 result |
= _gather_leaf_ids(nodes_by_id
[child_id
])
108 def _gather_descendent_ids(node
, typ
):
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
)
119 def _gather_osds(root
, steps
):
121 return set([root
['id']])
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':
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:])