Revision b954f097 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
5163 | 5163 |
return self.oq.OldStyleQuery(self) |
5164 | 5164 |
|
5165 | 5165 |
|
5166 |
class _ExtStorageQuery(_QueryBase): |
|
5167 |
FIELDS = query.EXTSTORAGE_FIELDS |
|
5168 |
|
|
5169 |
def ExpandNames(self, lu): |
|
5170 |
# Lock all nodes in shared mode |
|
5171 |
# Temporary removal of locks, should be reverted later |
|
5172 |
# TODO: reintroduce locks when they are lighter-weight |
|
5173 |
lu.needed_locks = {} |
|
5174 |
#self.share_locks[locking.LEVEL_NODE] = 1 |
|
5175 |
#self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET |
|
5176 |
|
|
5177 |
# The following variables interact with _QueryBase._GetNames |
|
5178 |
if self.names: |
|
5179 |
self.wanted = self.names |
|
5180 |
else: |
|
5181 |
self.wanted = locking.ALL_SET |
|
5182 |
|
|
5183 |
self.do_locking = self.use_locking |
|
5184 |
|
|
5185 |
def DeclareLocks(self, lu, level): |
|
5186 |
pass |
|
5187 |
|
|
5188 |
@staticmethod |
|
5189 |
def _DiagnoseByProvider(rlist): |
|
5190 |
"""Remaps a per-node return list into an a per-provider per-node dictionary |
|
5191 |
|
|
5192 |
@param rlist: a map with node names as keys and ExtStorage objects as values |
|
5193 |
|
|
5194 |
@rtype: dict |
|
5195 |
@return: a dictionary with extstorage providers as keys and as |
|
5196 |
value another map, with nodes as keys and tuples of |
|
5197 |
(path, status, diagnose, parameters) as values, eg:: |
|
5198 |
|
|
5199 |
{"provider1": {"node1": [(/usr/lib/..., True, "", [])] |
|
5200 |
"node2": [(/srv/..., False, "missing file")] |
|
5201 |
"node3": [(/srv/..., True, "", [])] |
|
5202 |
} |
|
5203 |
|
|
5204 |
""" |
|
5205 |
all_es = {} |
|
5206 |
# we build here the list of nodes that didn't fail the RPC (at RPC |
|
5207 |
# level), so that nodes with a non-responding node daemon don't |
|
5208 |
# make all OSes invalid |
|
5209 |
good_nodes = [node_name for node_name in rlist |
|
5210 |
if not rlist[node_name].fail_msg] |
|
5211 |
for node_name, nr in rlist.items(): |
|
5212 |
if nr.fail_msg or not nr.payload: |
|
5213 |
continue |
|
5214 |
for (name, path, status, diagnose, params) in nr.payload: |
|
5215 |
if name not in all_es: |
|
5216 |
# build a list of nodes for this os containing empty lists |
|
5217 |
# for each node in node_list |
|
5218 |
all_es[name] = {} |
|
5219 |
for nname in good_nodes: |
|
5220 |
all_es[name][nname] = [] |
|
5221 |
# convert params from [name, help] to (name, help) |
|
5222 |
params = [tuple(v) for v in params] |
|
5223 |
all_es[name][node_name].append((path, status, diagnose, params)) |
|
5224 |
return all_es |
|
5225 |
|
|
5226 |
def _GetQueryData(self, lu): |
|
5227 |
"""Computes the list of nodes and their attributes. |
|
5228 |
|
|
5229 |
""" |
|
5230 |
# Locking is not used |
|
5231 |
assert not (compat.any(lu.glm.is_owned(level) |
|
5232 |
for level in locking.LEVELS |
|
5233 |
if level != locking.LEVEL_CLUSTER) or |
|
5234 |
self.do_locking or self.use_locking) |
|
5235 |
|
|
5236 |
valid_nodes = [node.name |
|
5237 |
for node in lu.cfg.GetAllNodesInfo().values() |
|
5238 |
if not node.offline and node.vm_capable] |
|
5239 |
pol = self._DiagnoseByProvider(lu.rpc.call_extstorage_diagnose(valid_nodes)) |
|
5240 |
|
|
5241 |
data = {} |
|
5242 |
|
|
5243 |
nodegroup_list = lu.cfg.GetNodeGroupList() |
|
5244 |
|
|
5245 |
for (es_name, es_data) in pol.items(): |
|
5246 |
# For every provider compute the nodegroup validity. |
|
5247 |
# To do this we need to check the validity of each node in es_data |
|
5248 |
# and then construct the corresponding nodegroup dict: |
|
5249 |
# { nodegroup1: status |
|
5250 |
# nodegroup2: status |
|
5251 |
# } |
|
5252 |
ndgrp_data = {} |
|
5253 |
for nodegroup in nodegroup_list: |
|
5254 |
ndgrp = lu.cfg.GetNodeGroup(nodegroup) |
|
5255 |
|
|
5256 |
nodegroup_nodes = ndgrp.members |
|
5257 |
nodegroup_name = ndgrp.name |
|
5258 |
node_statuses = [] |
|
5259 |
|
|
5260 |
for node in nodegroup_nodes: |
|
5261 |
if node in valid_nodes: |
|
5262 |
if es_data[node] != []: |
|
5263 |
node_status = es_data[node][0][1] |
|
5264 |
node_statuses.append(node_status) |
|
5265 |
else: |
|
5266 |
node_statuses.append(False) |
|
5267 |
|
|
5268 |
if False in node_statuses: |
|
5269 |
ndgrp_data[nodegroup_name] = False |
|
5270 |
else: |
|
5271 |
ndgrp_data[nodegroup_name] = True |
|
5272 |
|
|
5273 |
# Compute the provider's parameters |
|
5274 |
parameters = set() |
|
5275 |
for idx, esl in enumerate(es_data.values()): |
|
5276 |
valid = bool(esl and esl[0][1]) |
|
5277 |
if not valid: |
|
5278 |
break |
|
5279 |
|
|
5280 |
node_params = esl[0][3] |
|
5281 |
if idx == 0: |
|
5282 |
# First entry |
|
5283 |
parameters.update(node_params) |
|
5284 |
else: |
|
5285 |
# Filter out inconsistent values |
|
5286 |
parameters.intersection_update(node_params) |
|
5287 |
|
|
5288 |
params = list(parameters) |
|
5289 |
|
|
5290 |
# Now fill all the info for this provider |
|
5291 |
info = query.ExtStorageInfo(name=es_name, node_status=es_data, |
|
5292 |
nodegroup_status=ndgrp_data, |
|
5293 |
parameters=params) |
|
5294 |
|
|
5295 |
data[es_name] = info |
|
5296 |
|
|
5297 |
# Prepare data in requested order |
|
5298 |
return [data[name] for name in self._GetNames(lu, pol.keys(), None) |
|
5299 |
if name in data] |
|
5300 |
|
|
5301 |
|
|
5302 |
class LUExtStorageDiagnose(NoHooksLU): |
|
5303 |
"""Logical unit for ExtStorage diagnose/query. |
|
5304 |
|
|
5305 |
""" |
|
5306 |
REQ_BGL = False |
|
5307 |
|
|
5308 |
def CheckArguments(self): |
|
5309 |
self.eq = _ExtStorageQuery(qlang.MakeSimpleFilter("name", self.op.names), |
|
5310 |
self.op.output_fields, False) |
|
5311 |
|
|
5312 |
def ExpandNames(self): |
|
5313 |
self.eq.ExpandNames(self) |
|
5314 |
|
|
5315 |
def Exec(self, feedback_fn): |
|
5316 |
return self.eq.OldStyleQuery(self) |
|
5317 |
|
|
5318 |
|
|
5166 | 5319 |
class LUNodeRemove(LogicalUnit): |
5167 | 5320 |
"""Logical unit for removing a node. |
5168 | 5321 |
|
... | ... | |
16604 | 16757 |
constants.QR_GROUP: _GroupQuery, |
16605 | 16758 |
constants.QR_NETWORK: _NetworkQuery, |
16606 | 16759 |
constants.QR_OS: _OsQuery, |
16760 |
constants.QR_EXTSTORAGE: _ExtStorageQuery, |
|
16607 | 16761 |
constants.QR_EXPORT: _ExportQuery, |
16608 | 16762 |
} |
16609 | 16763 |
|
Also available in: Unified diff