Revision 9d276e93

b/lib/cmdlib/common.py
1086 1086
                               (disk_template,
1087 1087
                                ",".join(cluster.enabled_disk_templates)))
1088 1088

  
1089

  
1090
def CheckStorageTypeEnabled(cluster, storage_type):
1091
  """Helper function to check if a storage type is enabled.
1092

  
1093
  @type cluster: C{objects.Cluster}
1094
  @param cluster: the cluster's configuration
1095
  @type storage_type: str
1096
  @param storage_type: the storage type to be checked
1097

  
1098
  """
1099
  assert storage_type is not None
1100
  assert storage_type in constants.VALID_STORAGE_TYPES
1101
  # special case for lvm-pv, because it cannot be enabled
1102
  # via disk templates
1103
  if storage_type == constants.ST_LVM_PV:
1104
    CheckStorageTypeEnabled(cluster, constants.ST_LVM_VG)
1105
  else:
1106
    possible_disk_templates = \
1107
        utils.storage.GetDiskTemplatesOfStorageType(storage_type)
1108
    for disk_template in possible_disk_templates:
1109
      if disk_template in cluster.enabled_disk_templates:
1110
        return
1111
    raise errors.OpPrereqError("No disk template of storage type '%s' is"
1112
                               " enabled in this cluster. Enabled disk"
1113
                               " templates are: %s" % (storage_type,
1114
                               ",".join(cluster.enabled_disk_templates)))
b/lib/cmdlib/instance.py
2592 2592
                                 self.instance.disk_template,
2593 2593
                                 errors.ECODE_INVAL)
2594 2594

  
2595
    if not self.cluster.IsDiskTemplateEnabled(self.instance.disk_template):
2596
      raise errors.OpPrereqError("Disk template '%s' is not enabled for this"
2597
                                 " cluster." % self.instance.disk_template)
2598

  
2595 2599
    if (self.instance.disk_template,
2596 2600
        self.op.disk_template) not in self._DISK_CONVERSIONS:
2597 2601
      raise errors.OpPrereqError("Unsupported disk template conversion from"
b/lib/cmdlib/instance_storage.py
34 34
from ganeti.masterd import iallocator
35 35
from ganeti import objects
36 36
from ganeti import utils
37
from ganeti import opcodes
38 37
from ganeti import rpc
39 38
from ganeti.cmdlib.base import LogicalUnit, NoHooksLU, Tasklet
40 39
from ganeti.cmdlib.common import INSTANCE_DOWN, INSTANCE_NOT_RUNNING, \
b/lib/cmdlib/node.py
45 45
  CheckInstanceState, INSTANCE_DOWN, GetUpdatedParams, \
46 46
  AdjustCandidatePool, CheckIAllocatorOrNode, LoadNodeEvacResult, \
47 47
  GetWantedNodes, MapInstanceLvsToNodes, RunPostHook, \
48
  FindFaultyInstanceDisks
48
  FindFaultyInstanceDisks, CheckStorageTypeEnabled
49 49

  
50 50

  
51 51
def _DecideSelfPromotion(lu, exceptions=None):
......
1130 1130
                                 (storage_type, list(diff)),
1131 1131
                                 errors.ECODE_INVAL)
1132 1132

  
1133
  def CheckPrereq(self):
1134
    """Check prerequisites.
1135

  
1136
    """
1137
    CheckStorageTypeEnabled(self.cfg.GetClusterInfo(), self.op.storage_type)
1138

  
1133 1139
  def ExpandNames(self):
1134 1140
    self.needed_locks = {
1135 1141
      locking.LEVEL_NODE: self.op.node_uuid,
......
1386 1392
        locking.LEVEL_NODE_ALLOC: locking.ALL_SET,
1387 1393
        }
1388 1394

  
1395
  def CheckPrereq(self):
1396
    """Check prerequisites.
1397

  
1398
    """
1399
    CheckStorageTypeEnabled(self.cfg.GetClusterInfo(), self.op.storage_type)
1400

  
1389 1401
  def Exec(self, feedback_fn):
1390 1402
    """Computes the list of nodes and their attributes.
1391 1403

  
......
1588 1600
    """Check prerequisites.
1589 1601

  
1590 1602
    """
1603
    CheckStorageTypeEnabled(self.cfg.GetClusterInfo(), self.op.storage_type)
1604

  
1591 1605
    # Check whether any instance on this node has faulty disks
1592 1606
    for inst in _GetNodeInstances(self.cfg, self.op.node_uuid):
1593 1607
      if not inst.disks_active:
b/lib/opcodes.py
326 326
    })
327 327

  
328 328

  
329
def RequireFileStorage():
330
  """Checks that file storage is enabled.
331

  
332
  While it doesn't really fit into this module, L{utils} was deemed too large
333
  of a dependency to be imported for just one or two functions.
334

  
335
  @raise errors.OpPrereqError: when file storage is disabled
336

  
337
  """
338
  if not constants.ENABLE_FILE_STORAGE:
339
    raise errors.OpPrereqError("File storage disabled at configure time",
340
                               errors.ECODE_INVAL)
341

  
342

  
343 329
def RequireSharedFileStorage():
344 330
  """Checks that shared file storage is enabled.
345 331

  
......
354 340
                               " configure time", errors.ECODE_INVAL)
355 341

  
356 342

  
357
@ht.WithDesc("CheckFileStorage")
358
def _CheckFileStorage(value):
359
  """Ensures file storage is enabled if used.
360

  
361
  """
362
  if value == constants.DT_FILE:
363
    RequireFileStorage()
364
  elif value == constants.DT_SHARED_FILE:
365
    RequireSharedFileStorage()
366
  return True
367

  
368

  
369 343
def _BuildDiskTemplateCheck(accept_none):
370 344
  """Builds check for disk template.
371 345

  
......
379 353
  if accept_none:
380 354
    template_check = ht.TMaybe(template_check)
381 355

  
382
  return ht.TAnd(template_check, _CheckFileStorage)
356
  return template_check
383 357

  
384 358

  
385 359
def _CheckStorageType(storage_type):
......
389 363
  if storage_type not in constants.VALID_STORAGE_TYPES:
390 364
    raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
391 365
                               errors.ECODE_INVAL)
392
  if storage_type == constants.ST_FILE:
393
    # TODO: What about shared file storage?
394
    RequireFileStorage()
395 366
  return True
396 367

  
397 368

  

Also available in: Unified diff