+ storage_info = _GetNamedNodeInfo(
+ storage_units,
+ (lambda (storage_type, storage_key, storage_params):
+ _ApplyStorageInfoFunction(storage_type, storage_key, storage_params)))
+ hv_info = _GetHvInfoAll(hv_specs)
+ return (bootid, storage_info, hv_info)
+
+
+def _GetFileStorageSpaceInfo(path, params):
+ """Wrapper around filestorage.GetSpaceInfo.
+
+ The purpose of this wrapper is to call filestorage.GetFileStorageSpaceInfo
+ and ignore the *args parameter to not leak it into the filestorage
+ module's code.
+
+ @see: C{filestorage.GetFileStorageSpaceInfo} for description of the
+ parameters.
+
+ """
+ _CheckStorageParams(params, 0)
+ return filestorage.GetFileStorageSpaceInfo(path)
+
+
+# FIXME: implement storage reporting for all missing storage types.
+_STORAGE_TYPE_INFO_FN = {
+ constants.ST_BLOCK: None,
+ constants.ST_DISKLESS: None,
+ constants.ST_EXT: None,
+ constants.ST_FILE: _GetFileStorageSpaceInfo,
+ constants.ST_LVM_PV: _GetLvmPvSpaceInfo,
+ constants.ST_LVM_VG: _GetLvmVgSpaceInfo,
+ constants.ST_RADOS: None,
+}
+
+
+def _ApplyStorageInfoFunction(storage_type, storage_key, *args):
+ """Looks up and applies the correct function to calculate free and total
+ storage for the given storage type.
+
+ @type storage_type: string
+ @param storage_type: the storage type for which the storage shall be reported.
+ @type storage_key: string
+ @param storage_key: identifier of a storage unit, e.g. the volume group name
+ of an LVM storage unit
+ @type args: any
+ @param args: various parameters that can be used for storage reporting. These
+ parameters and their semantics vary from storage type to storage type and
+ are just propagated in this function.
+ @return: the results of the application of the storage space function (see
+ _STORAGE_TYPE_INFO_FN) if storage space reporting is implemented for that
+ storage type
+ @raises NotImplementedError: for storage types who don't support space
+ reporting yet
+ """
+ fn = _STORAGE_TYPE_INFO_FN[storage_type]
+ if fn is not None:
+ return fn(storage_key, *args)
+ else:
+ raise NotImplementedError
+
+
+def _CheckExclusivePvs(pvi_list):
+ """Check that PVs are not shared among LVs
+
+ @type pvi_list: list of L{objects.LvmPvInfo} objects
+ @param pvi_list: information about the PVs
+
+ @rtype: list of tuples (string, list of strings)
+ @return: offending volumes, as tuples: (pv_name, [lv1_name, lv2_name...])
+
+ """
+ res = []
+ for pvi in pvi_list:
+ if len(pvi.lv_list) > 1:
+ res.append((pvi.name, pvi.lv_list))
+ return res
+
+
+def _VerifyHypervisors(what, vm_capable, result, all_hvparams,
+ get_hv_fn=hypervisor.GetHypervisor):
+ """Verifies the hypervisor. Appends the results to the 'results' list.
+
+ @type what: C{dict}
+ @param what: a dictionary of things to check
+ @type vm_capable: boolean
+ @param vm_capable: whether or not this node is vm capable
+ @type result: dict
+ @param result: dictionary of verification results; results of the
+ verifications in this function will be added here
+ @type all_hvparams: dict of dict of string
+ @param all_hvparams: dictionary mapping hypervisor names to hvparams
+ @type get_hv_fn: function
+ @param get_hv_fn: function to retrieve the hypervisor, to improve testability
+
+ """
+ if not vm_capable:
+ return
+
+ if constants.NV_HYPERVISOR in what:
+ result[constants.NV_HYPERVISOR] = {}
+ for hv_name in what[constants.NV_HYPERVISOR]:
+ hvparams = all_hvparams[hv_name]
+ try:
+ val = get_hv_fn(hv_name).Verify(hvparams=hvparams)
+ except errors.HypervisorError, err:
+ val = "Error while checking hypervisor: %s" % str(err)
+ result[constants.NV_HYPERVISOR][hv_name] = val