Revision 294254b1 lib/cmdlib/common.py
b/lib/cmdlib/common.py | ||
---|---|---|
1133 | 1133 |
raise errors.OpPrereqError("The following disk template are allowed" |
1134 | 1134 |
" by the ipolicy, but not enabled on the" |
1135 | 1135 |
" cluster: %s" % utils.CommaJoin(not_enabled)) |
1136 |
|
|
1137 |
|
|
1138 |
def CheckDiskAccessModeValidity(parameters): |
|
1139 |
"""Checks if the access parameter is legal. |
|
1140 |
|
|
1141 |
@see: L{CheckDiskAccessModeConsistency} for cluster consistency checks. |
|
1142 |
@raise errors.OpPrereqError: if the check fails. |
|
1143 |
|
|
1144 |
""" |
|
1145 |
if constants.DT_RBD in parameters: |
|
1146 |
access = parameters[constants.DT_RBD].get(constants.RBD_ACCESS, |
|
1147 |
constants.DISK_KERNELSPACE) |
|
1148 |
if access not in constants.DISK_VALID_ACCESS_MODES: |
|
1149 |
valid_vals_str = utils.CommaJoin(constants.DISK_VALID_ACCESS_MODES) |
|
1150 |
raise errors.OpPrereqError("Invalid value of '{d}:{a}': '{v}' (expected" |
|
1151 |
" one of {o})".format(d=constants.DT_RBD, |
|
1152 |
a=constants.RBD_ACCESS, |
|
1153 |
v=access, |
|
1154 |
o=valid_vals_str)) |
|
1155 |
|
|
1156 |
|
|
1157 |
def CheckDiskAccessModeConsistency(parameters, cfg, group=None): |
|
1158 |
"""Checks if the access param is consistent with the cluster configuration. |
|
1159 |
|
|
1160 |
@note: requires a configuration lock to run. |
|
1161 |
@param parameters: the parameters to validate |
|
1162 |
@param cfg: the cfg object of the cluster |
|
1163 |
@param group: if set, only check for consistency within this group. |
|
1164 |
@raise errors.OpPrereqError: if the LU attempts to change the access parameter |
|
1165 |
to an invalid value, such as "pink bunny". |
|
1166 |
@raise errors.OpPrereqError: if the LU attempts to change the access parameter |
|
1167 |
to an inconsistent value, such as asking for RBD |
|
1168 |
userspace access to the chroot hypervisor. |
|
1169 |
|
|
1170 |
""" |
|
1171 |
CheckDiskAccessModeValidity(parameters) |
|
1172 |
|
|
1173 |
if constants.DT_RBD in parameters: |
|
1174 |
access = parameters[constants.DT_RBD].get(constants.RBD_ACCESS, |
|
1175 |
constants.DISK_KERNELSPACE) |
|
1176 |
|
|
1177 |
#Check the combination of instance hypervisor, disk template and access |
|
1178 |
#protocol is sane. |
|
1179 |
inst_uuids = cfg.GetNodeGroupInstances(group) if group else \ |
|
1180 |
cfg.GetInstanceList() |
|
1181 |
|
|
1182 |
for entry in inst_uuids: |
|
1183 |
#hyp, disk, access |
|
1184 |
inst = cfg.GetInstanceInfo(entry) |
|
1185 |
hv = inst.hypervisor |
|
1186 |
dt = inst.disk_template |
|
1187 |
|
|
1188 |
#do not check for disk types that don't have this setting. |
|
1189 |
if dt != constants.DT_RBD: |
|
1190 |
continue |
|
1191 |
|
|
1192 |
if not IsValidDiskAccessModeCombination(hv, dt, access): |
|
1193 |
raise errors.OpPrereqError("Instance {i}: cannot use '{a}' access" |
|
1194 |
" setting with {h} hypervisor and {d} disk" |
|
1195 |
" type.".format(i=inst.name, |
|
1196 |
a=access, |
|
1197 |
h=hv, |
|
1198 |
d=dt)) |
|
1199 |
|
|
1200 |
|
|
1201 |
def IsValidDiskAccessModeCombination(hv, disk_template, mode): |
|
1202 |
"""Checks if an hypervisor can read a disk template with given mode. |
|
1203 |
|
|
1204 |
@param hv: the hypervisor that will access the data |
|
1205 |
@param disk_template: the disk template the data is stored as |
|
1206 |
@param mode: how the hypervisor should access the data |
|
1207 |
@return: True if the hypervisor can read a given read disk_template |
|
1208 |
in the specified mode. |
|
1209 |
|
|
1210 |
""" |
|
1211 |
if mode == constants.DISK_KERNELSPACE: |
|
1212 |
return True |
|
1213 |
|
|
1214 |
if (hv == constants.HT_KVM and |
|
1215 |
disk_template == constants.DT_RBD and |
|
1216 |
mode == constants.DISK_USERSPACE): |
|
1217 |
return True |
|
1218 |
|
|
1219 |
# Everything else: |
|
1220 |
return False |
Also available in: Unified diff