Commit 9e5442ce authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Add new opcode to list physical volumes

Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarIustin Pop <>
parent 6032697c
......@@ -2306,6 +2306,106 @@ class LUQueryNodeVolumes(NoHooksLU):
return output
class LUQueryNodeStorage(NoHooksLU):
"""Logical unit for getting information on storage units on node(s).
_OP_REQP = ["nodes", "storage_type", "output_fields"]
REQ_BGL = False
_FIELDS_STATIC = utils.FieldSet("node")
def ExpandNames(self):
storage_type = self.op.storage_type
if storage_type not in constants.VALID_STORAGE_FIELDS:
raise errors.OpPrereqError("Unknown storage type: %s" % storage_type)
dynamic_fields = constants.VALID_STORAGE_FIELDS[storage_type]
self.needed_locks = {}
self.share_locks[locking.LEVEL_NODE] = 1
if self.op.nodes:
self.needed_locks[locking.LEVEL_NODE] = \
_GetWantedNodes(self, self.op.nodes)
self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
def CheckPrereq(self):
"""Check prerequisites.
This checks that the fields required are valid output fields.
""" = getattr(self.op, "name", None)
self.nodes = self.acquired_locks[locking.LEVEL_NODE]
def Exec(self, feedback_fn):
"""Computes the list of nodes and their attributes.
# Special case for file storage
if self.op.storage_type == constants.ST_FILE:
st_args = [self.cfg.GetFileStorageDir()]
st_args = []
# Always get name to sort by
if constants.SF_NAME in self.op.output_fields:
fields = self.op.output_fields[:]
fields = [constants.SF_NAME] + self.op.output_fields
# Never ask for node as it's only known to the LU
while "node" in fields:
field_idx = dict([(name, idx) for (idx, name) in enumerate(fields)])
name_idx = field_idx[constants.SF_NAME]
data = self.rpc.call_storage_list(self.nodes,
self.op.storage_type, st_args,, fields)
result = []
for node in utils.NiceSort(self.nodes):
nresult = data[node]
if nresult.offline:
msg = nresult.fail_msg
if msg:
self.LogWarning("Can't get storage data from node %s: %s", node, msg)
rows = dict([(row[name_idx], row) for row in nresult.payload])
for name in utils.NiceSort(rows.keys()):
row = rows[name]
out = []
for field in self.op.output_fields:
if field == "node":
val = node
elif field in field_idx:
val = row[field_idx[field]]
raise errors.ParameterError(field)
return result
class LUAddNode(LogicalUnit):
"""Logical unit for adding node to the cluster.
......@@ -54,6 +54,7 @@ class Processor(object):
opcodes.OpAddNode: cmdlib.LUAddNode,
opcodes.OpQueryNodes: cmdlib.LUQueryNodes,
opcodes.OpQueryNodeVolumes: cmdlib.LUQueryNodeVolumes,
opcodes.OpQueryNodeStorage: cmdlib.LUQueryNodeStorage,
opcodes.OpRemoveNode: cmdlib.LURemoveNode,
opcodes.OpSetNodeParams: cmdlib.LUSetNodeParams,
opcodes.OpPowercycleNode: cmdlib.LUPowercycleNode,
......@@ -328,6 +328,17 @@ class OpQueryNodeVolumes(OpCode):
__slots__ = OpCode.__slots__ + ["nodes", "output_fields"]
class OpQueryNodeStorage(OpCode):
"""Get information on storage for node(s)."""
__slots__ = OpCode.__slots__ + [
class OpSetNodeParams(OpCode):
"""Change the parameters of a node."""
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment