@return: the desired exit code
"""
- # TODO: Default to ST_FILE if LVM is disabled on the cluster
- if opts.user_storage_type is None:
- opts.user_storage_type = constants.ST_LVM_PV
-
- storage_type = ConvertStorageType(opts.user_storage_type)
-
selected_fields = ParseFields(opts.output, _LIST_STOR_DEF_FIELDS)
op = opcodes.OpNodeQueryStorage(nodes=args,
- storage_type=storage_type,
+ storage_type=opts.user_storage_type,
output_fields=selected_fields)
output = SubmitOpCode(op, opts=opts)
locking.LEVEL_NODE_ALLOC: locking.ALL_SET,
}
+ def _DetermineStorageType(self):
+ """Determines the default storage type of the cluster.
+
+ """
+ enabled_disk_templates = self.cfg.GetClusterInfo().enabled_disk_templates
+ default_storage_type = \
+ constants.MAP_DISK_TEMPLATE_STORAGE_TYPE[enabled_disk_templates[0]]
+ return default_storage_type
+
def CheckPrereq(self):
"""Check prerequisites.
"""
- CheckStorageTypeEnabled(self.cfg.GetClusterInfo(), self.op.storage_type)
+ if self.op.storage_type:
+ CheckStorageTypeEnabled(self.cfg.GetClusterInfo(), self.op.storage_type)
+ self.storage_type = self.op.storage_type
+ else:
+ self.storage_type = self._DetermineStorageType()
+ if self.storage_type not in constants.STS_REPORT:
+ raise errors.OpPrereqError(
+ "Storage reporting for storage type '%s' is not supported. Please"
+ " use the --storage-type option to specify one of the supported"
+ " storage types (%s) or set the default disk template to one that"
+ " supports storage reporting." %
+ (self.storage_type, utils.CommaJoin(constants.STS_REPORT)))
def Exec(self, feedback_fn):
"""Computes the list of nodes and their attributes.
"""
+ if self.op.storage_type:
+ self.storage_type = self.op.storage_type
+ else:
+ self.storage_type = self._DetermineStorageType()
+
self.node_uuids = self.owned_locks(locking.LEVEL_NODE)
# Always get name to sort by
field_idx = dict([(name, idx) for (idx, name) in enumerate(fields)])
name_idx = field_idx[constants.SF_NAME]
- st_args = _GetStorageTypeArgs(self.cfg, self.op.storage_type)
+ st_args = _GetStorageTypeArgs(self.cfg, self.storage_type)
data = self.rpc.call_storage_list(self.node_uuids,
- self.op.storage_type, st_args,
+ self.storage_type, st_args,
self.op.name, fields)
result = []
if field == constants.SF_NODE:
val = node_name
elif field == constants.SF_TYPE:
- val = self.op.storage_type
+ val = self.storage_type
elif field in field_idx:
val = row[field_idx[field]]
else:
def testErrors(self):
clfactory = _FakeClientFactory(_FakeClient)
+ # storage type which does not support space reporting
queryargs = {
- "output_fields": "name,other",
+ "storage_type": constants.ST_DISKLESS,
}
handler = _CreateHandler(rlib2.R_2_nodes_name_storage,
- ["node10538"], queryargs, {}, clfactory)
+ ["node21273"], queryargs, {}, clfactory)
self.assertRaises(http.HttpBadRequest, handler.GET)
queryargs = {