Revision 3039e2dc lib/cmdlib/cluster.py

b/lib/cmdlib/cluster.py
609 609
                               (netmask), errors.ECODE_INVAL)
610 610

  
611 611

  
612
def CheckFileStoragePathVsEnabledDiskTemplates(
613
    logging_warn_fn, file_storage_dir, enabled_disk_templates):
614
  """Checks whether the given file storage directory is acceptable.
615

  
616
  @type logging_warn_fn: function
617
  @param logging_warn_fn: function which accepts a string and logs it
618
  @type file_storage_dir: string
619
  @param file_storage_dir: the directory to be used for file-based instances
620
  @type enabled_disk_templates: list of string
621
  @param enabled_disk_templates: the list of enabled disk templates
622

  
623
  Note: This function is public, because it is also used in bootstrap.py.
624
  """
625
  file_storage_enabled = constants.DT_FILE in enabled_disk_templates
626
  if file_storage_dir is not None:
627
    if file_storage_dir == "":
628
      if file_storage_enabled:
629
        raise errors.OpPrereqError("Unsetting the file storage directory"
630
                                   " while having file storage enabled"
631
                                   " is not permitted.")
632
    else:
633
      if not file_storage_enabled:
634
        logging_warn_fn("Specified a file storage directory, although file"
635
                        " storage is not enabled.")
636
  else:
637
    raise errors.ProgrammerError("Received file storage dir with value"
638
                                 " 'None'.")
639

  
640

  
612 641
class LUClusterSetParams(LogicalUnit):
613 642
  """Change the parameters of the cluster.
614 643

  
......
752 781
    self._CheckVgName(vm_capable_node_uuids, enabled_disk_templates,
753 782
                      new_enabled_disk_templates)
754 783

  
784
    if self.op.file_storage_dir is not None:
785
      CheckFileStoragePathVsEnabledDiskTemplates(
786
          self.LogWarning, self.op.file_storage_dir, enabled_disk_templates)
787

  
755 788
    if self.op.drbd_helper:
756 789
      # checks given drbd helper on all nodes
757 790
      helpers = self.rpc.call_drbd_helper(node_uuids)
......
998 1031
        raise errors.OpPrereqError("Please specify a volume group when"
999 1032
                                   " enabling lvm-based disk-templates.")
1000 1033

  
1034
  def _SetFileStorageDir(self, feedback_fn):
1035
    """Set the file storage directory.
1036

  
1037
    """
1038
    if self.op.file_storage_dir is not None:
1039
      if self.cluster.file_storage_dir == self.op.file_storage_dir:
1040
        feedback_fn("Global file storage dir already set to value '%s'"
1041
                    % self.cluster.file_storage_dir)
1042
      else:
1043
        self.cluster.file_storage_dir = self.op.file_storage_dir
1044

  
1001 1045
  def Exec(self, feedback_fn):
1002 1046
    """Change the parameters of the cluster.
1003 1047

  
......
1007 1051
        list(set(self.op.enabled_disk_templates))
1008 1052

  
1009 1053
    self._SetVgName(feedback_fn)
1054
    self._SetFileStorageDir(feedback_fn)
1010 1055

  
1011 1056
    if self.op.drbd_helper is not None:
1012 1057
      if not constants.DT_DRBD8 in self.cluster.enabled_disk_templates:

Also available in: Unified diff