Revision 1f7c8208 lib/cmdlib/instance.py

b/lib/cmdlib/instance.py
49 49
  LoadNodeEvacResult, CheckIAllocatorOrNode, CheckParamsNotGlobal, \
50 50
  IsExclusiveStorageEnabledNode, CheckHVParams, CheckOSParams, \
51 51
  AnnotateDiskParams, GetUpdatedParams, ExpandInstanceUuidAndName, \
52
  ComputeIPolicySpecViolation, CheckInstanceState, ExpandNodeUuidAndName
52
  ComputeIPolicySpecViolation, CheckInstanceState, ExpandNodeUuidAndName, \
53
  CheckDiskTemplateEnabled
53 54
from ganeti.cmdlib.instance_storage import CreateDisks, \
54 55
  CheckNodesFreeDiskPerVG, WipeDisks, WipeOrCleanupDisks, WaitForSync, \
55 56
  IsExclusiveStorageEnabledNodeUuid, CreateSingleBlockDev, ComputeDisks, \
......
334 335
      # chicken-and-egg problem, it should be possible to specify just a node
335 336
      # group from the iallocator and take the ipolicy from that.
336 337
      self.op.disk_template = cluster.enabled_disk_templates[0]
337
    if not self.op.disk_template in cluster.enabled_disk_templates:
338
      raise errors.OpPrereqError("Cannot create an instance with disk template"
339
                                 " '%s', because it is not enabled in the"
340
                                 " cluster. Enabled disk templates are: %s." %
341
                                 (self.op.disk_template,
342
                                  ",".join(cluster.enabled_disk_templates)))
338
    CheckDiskTemplateEnabled(cluster, self.op.disk_template)
343 339

  
344 340
  def _CheckDiskArguments(self):
345 341
    """Checks validity of disk-related arguments.
......
1469 1465
                                self.op.instance_name)
1470 1466
    instance = self.cfg.GetInstanceInfo(self.op.instance_uuid)
1471 1467
    assert instance is not None
1468

  
1469
    # It should actually not happen that an instance is running with a disabled
1470
    # disk template, but in case it does, the renaming of file-based instances
1471
    # will fail horribly. Thus, we test it before.
1472
    if (instance.disk_template in constants.DTS_FILEBASED and
1473
        self.op.new_name != instance.name):
1474
      CheckDiskTemplateEnabled(self.cfg.GetClusterInfo(),
1475
                               instance.disk_template)
1476

  
1472 1477
    CheckNodeOnline(self, instance.primary_node)
1473 1478
    CheckInstanceState(self, instance, INSTANCE_NOT_RUNNING,
1474 1479
                       msg="cannot rename")

Also available in: Unified diff