def CheckPrereq(self):
    """Check prerequisites.

    This checks that the instance is in the cluster and is not running.

    """
    (self.op.instance_uuid, self.op.instance_name) = \
      ExpandInstanceUuidAndName(self.cfg, self.op.instance_uuid,
                                self.op.instance_name)
    instance = self.cfg.GetInstanceInfo(self.op.instance_uuid)
    assert instance is not None

    # It should actually not happen that an instance is running with a disabled
    # disk template, but in case it does, the renaming of file-based instances
    # will fail horribly. Thus, we test it before.
    for disk in self.cfg.GetInstanceDisks(instance.uuid):
      if (disk.dev_type in constants.DTS_FILEBASED and
          self.op.new_name != instance.name):
        # TODO: when disks are separate objects, this should check for disk
        # types, not disk templates.
        CheckDiskTemplateEnabled(self.cfg.GetClusterInfo(), disk.dev_type)

    CheckNodeOnline(self, instance.primary_node)
    CheckInstanceState(self, instance, INSTANCE_NOT_RUNNING,
                       msg="cannot rename")
    self.instance = instance

    self._PerformChecksAndResolveNewName()

    if self.op.new_name != instance.name:
      CheckInstanceExistence(self, self.op.new_name)
dataset/ETHPy150Open ganeti/ganeti/lib/cmdlib/instance.py/LUInstanceRename.CheckPrereq/original