Revision c89eb67d lib/cmdlib/cluster.py

b/lib/cmdlib/cluster.py
741 741
       unset whether there are instances still using it.
742 742

  
743 743
    """
744
    lvm_is_enabled = utils.IsLvmEnabled(enabled_disk_templates)
745
    lvm_gets_enabled = utils.LvmGetsEnabled(enabled_disk_templates,
746
                                            new_enabled_disk_templates)
747
    current_vg_name = self.cfg.GetVGName()
748

  
749
    if self.op.vg_name == '':
750
      if lvm_is_enabled:
751
        raise errors.OpPrereqError("Cannot unset volume group if lvm-based"
752
                                   " disk templates are or get enabled.")
753

  
754
    if self.op.vg_name is None:
755
      if current_vg_name is None and lvm_is_enabled:
756
        raise errors.OpPrereqError("Please specify a volume group when"
757
                                   " enabling lvm-based disk-templates.")
758

  
744 759
    if self.op.vg_name is not None and not self.op.vg_name:
745 760
      if self.cfg.HasAnyDiskOfType(constants.LD_LV):
746 761
        raise errors.OpPrereqError("Cannot disable lvm storage while lvm-based"
747 762
                                   " instances exist", errors.ECODE_INVAL)
748 763

  
749
    if (self.op.vg_name is not None and
750
        utils.IsLvmEnabled(enabled_disk_templates)) or \
751
           (self.cfg.GetVGName() is not None and
752
            utils.LvmGetsEnabled(enabled_disk_templates,
753
                                 new_enabled_disk_templates)):
764
    if (self.op.vg_name is not None and lvm_is_enabled) or \
765
        (self.cfg.GetVGName() is not None and lvm_gets_enabled):
754 766
      self._CheckVgNameOnNodes(node_uuids)
755 767

  
756 768
  def _CheckVgNameOnNodes(self, node_uuids):
......
774 786
                                   (self.cfg.GetNodeName(node_uuid), vgstatus),
775 787
                                   errors.ECODE_ENVIRON)
776 788

  
777
  def _GetEnabledDiskTemplates(self, cluster):
789
  @staticmethod
790
  def _GetEnabledDiskTemplatesInner(op_enabled_disk_templates,
791
                                    old_enabled_disk_templates):
778 792
    """Determines the enabled disk templates and the subset of disk templates
779 793
       that are newly enabled by this operation.
780 794

  
781 795
    """
782 796
    enabled_disk_templates = None
783 797
    new_enabled_disk_templates = []
784
    if self.op.enabled_disk_templates:
785
      enabled_disk_templates = self.op.enabled_disk_templates
798
    if op_enabled_disk_templates:
799
      enabled_disk_templates = op_enabled_disk_templates
786 800
      new_enabled_disk_templates = \
787 801
        list(set(enabled_disk_templates)
788
             - set(cluster.enabled_disk_templates))
802
             - set(old_enabled_disk_templates))
789 803
    else:
790
      enabled_disk_templates = cluster.enabled_disk_templates
804
      enabled_disk_templates = old_enabled_disk_templates
791 805
    return (enabled_disk_templates, new_enabled_disk_templates)
792 806

  
807
  def _GetEnabledDiskTemplates(self, cluster):
808
    """Determines the enabled disk templates and the subset of disk templates
809
       that are newly enabled by this operation.
810

  
811
    """
812
    return self._GetEnabledDiskTemplatesInner(self.op.enabled_disk_templates,
813
                                              cluster.enabled_disk_templates)
814

  
793 815
  def _CheckIpolicy(self, cluster, enabled_disk_templates):
794 816
    """Checks the ipolicy.
795 817

  
......
1069 1091

  
1070 1092
    """
1071 1093
    if self.op.vg_name is not None:
1072
      if self.op.vg_name and not \
1073
           utils.IsLvmEnabled(self.cluster.enabled_disk_templates):
1074
        feedback_fn("Note that you specified a volume group, but did not"
1075
                    " enable any lvm disk template.")
1076 1094
      new_volume = self.op.vg_name
1077 1095
      if not new_volume:
1078
        if utils.IsLvmEnabled(self.cluster.enabled_disk_templates):
1079
          raise errors.OpPrereqError("Cannot unset volume group if lvm-based"
1080
                                     " disk templates are enabled.")
1081 1096
        new_volume = None
1082 1097
      if new_volume != self.cfg.GetVGName():
1083 1098
        self.cfg.SetVGName(new_volume)
1084 1099
      else:
1085 1100
        feedback_fn("Cluster LVM configuration already in desired"
1086 1101
                    " state, not changing")
1087
    else:
1088
      if utils.IsLvmEnabled(self.cluster.enabled_disk_templates) and \
1089
          not self.cfg.GetVGName():
1090
        raise errors.OpPrereqError("Please specify a volume group when"
1091
                                   " enabling lvm-based disk-templates.")
1092 1102

  
1093 1103
  def _SetFileStorageDir(self, feedback_fn):
1094 1104
    """Set the file storage directory.

Also available in: Unified diff