Revision 0e3baaf3

b/lib/bootstrap.py
199 199
                             " 10 seconds" % node_name)
200 200

  
201 201

  
202
def _InitFileStorage(file_storage_dir):
203
  """Initialize if needed the file storage.
204

  
205
  @param file_storage_dir: the user-supplied value
206
  @return: either empty string (if file storage was disabled at build
207
      time) or the normalized path to the storage directory
208

  
209
  """
210
  if not constants.ENABLE_FILE_STORAGE:
211
    return ""
212

  
213
  file_storage_dir = os.path.normpath(file_storage_dir)
214

  
215
  if not os.path.isabs(file_storage_dir):
216
    raise errors.OpPrereqError("The file storage directory you passed is"
217
                               " not an absolute path.", errors.ECODE_INVAL)
218

  
219
  if not os.path.exists(file_storage_dir):
220
    try:
221
      os.makedirs(file_storage_dir, 0750)
222
    except OSError, err:
223
      raise errors.OpPrereqError("Cannot create file storage directory"
224
                                 " '%s': %s" % (file_storage_dir, err),
225
                                 errors.ECODE_ENVIRON)
226

  
227
  if not os.path.isdir(file_storage_dir):
228
    raise errors.OpPrereqError("The file storage directory '%s' is not"
229
                               " a directory." % file_storage_dir,
230
                               errors.ECODE_ENVIRON)
231
  return file_storage_dir
232

  
233

  
202 234
def InitCluster(cluster_name, mac_prefix,
203 235
                master_netdev, file_storage_dir, candidate_pool_size,
204 236
                secondary_ip=None, vg_name=None, beparams=None,
......
267 299
                                 " you are not using lvm" % vgstatus,
268 300
                                 errors.ECODE_INVAL)
269 301

  
270
  file_storage_dir = os.path.normpath(file_storage_dir)
271

  
272
  if not os.path.isabs(file_storage_dir):
273
    raise errors.OpPrereqError("The file storage directory you passed is"
274
                               " not an absolute path.", errors.ECODE_INVAL)
275

  
276
  if not os.path.exists(file_storage_dir):
277
    try:
278
      os.makedirs(file_storage_dir, 0750)
279
    except OSError, err:
280
      raise errors.OpPrereqError("Cannot create file storage directory"
281
                                 " '%s': %s" % (file_storage_dir, err),
282
                                 errors.ECODE_ENVIRON)
283

  
284
  if not os.path.isdir(file_storage_dir):
285
    raise errors.OpPrereqError("The file storage directory '%s' is not"
286
                               " a directory." % file_storage_dir,
287
                               errors.ECODE_ENVIRON)
302
  file_storage_dir = _InitFileStorage(file_storage_dir)
288 303

  
289 304
  if not re.match("^[0-9a-z]{2}:[0-9a-z]{2}:[0-9a-z]{2}$", mac_prefix):
290 305
    raise errors.OpPrereqError("Invalid mac prefix given '%s'" % mac_prefix,
b/lib/cmdlib.py
560 560
    _CheckOSVariant(result.payload, os_name)
561 561

  
562 562

  
563
def _RequireFileStorage():
564
  """Checks that file storage is enabled.
565

  
566
  @raise errors.OpPrereqError: when file storage is disabled
567

  
568
  """
569
  if not constants.ENABLE_FILE_STORAGE:
570
    raise errors.OpPrereqError("File storage disabled at configure time",
571
                               errors.ECODE_INVAL)
572

  
573

  
563 574
def _CheckDiskTemplate(template):
564 575
  """Ensure a given disk template is valid.
565 576

  
......
568 579
    msg = ("Invalid disk template name '%s', valid templates are: %s" %
569 580
           (template, utils.CommaJoin(constants.DISK_TEMPLATES)))
570 581
    raise errors.OpPrereqError(msg, errors.ECODE_INVAL)
571
  if template == constants.DT_FILE and not constants.ENABLE_FILE_STORAGE:
572
    raise errors.OpPrereqError("File storage disabled at configure time",
582
  if template == constants.DT_FILE:
583
    _RequireFileStorage()
584

  
585

  
586
def _CheckStorageType(storage_type):
587
  """Ensure a given storage type is valid.
588

  
589
  """
590
  if storage_type not in constants.VALID_STORAGE_TYPES:
591
    raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
573 592
                               errors.ECODE_INVAL)
593
  if storage_type == constants.ST_FILE:
594
    _RequireFileStorage()
595

  
574 596

  
575 597

  
576 598
def _CheckInstanceDown(lu, instance, reason):
......
3079 3101
  REQ_BGL = False
3080 3102
  _FIELDS_STATIC = utils.FieldSet(constants.SF_NODE)
3081 3103

  
3082
  def ExpandNames(self):
3083
    storage_type = self.op.storage_type
3084

  
3085
    if storage_type not in constants.VALID_STORAGE_TYPES:
3086
      raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
3087
                                 errors.ECODE_INVAL)
3104
  def CheckArguments(self):
3105
    _CheckStorageType(self.op.storage_type)
3088 3106

  
3089 3107
    _CheckOutputFields(static=self._FIELDS_STATIC,
3090 3108
                       dynamic=utils.FieldSet(*constants.VALID_STORAGE_FIELDS),
3091 3109
                       selected=self.op.output_fields)
3092 3110

  
3111
  def ExpandNames(self):
3093 3112
    self.needed_locks = {}
3094 3113
    self.share_locks[locking.LEVEL_NODE] = 1
3095 3114

  
......
3178 3197
  def CheckArguments(self):
3179 3198
    self.opnode_name = _ExpandNodeName(self.cfg, self.op.node_name)
3180 3199

  
3181
    storage_type = self.op.storage_type
3182
    if storage_type not in constants.VALID_STORAGE_TYPES:
3183
      raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
3184
                                 errors.ECODE_INVAL)
3200
    _CheckStorageType(self.op.storage_type)
3185 3201

  
3186 3202
  def ExpandNames(self):
3187 3203
    self.needed_locks = {
......
5808 5824
    if len(secondary_nodes) != 0:
5809 5825
      raise errors.ProgrammerError("Wrong template configuration")
5810 5826

  
5827
    _RequireFileStorage()
5828

  
5811 5829
    for idx, disk in enumerate(disk_info):
5812 5830
      disk_index = idx + base_index
5813 5831
      disk_dev = objects.Disk(dev_type=constants.LD_FILE, size=disk["size"],
......
6629 6647
    else:
6630 6648
      network_port = None
6631 6649

  
6632
    ##if self.op.vnc_bind_address is None:
6633
    ##  self.op.vnc_bind_address = constants.VNC_DEFAULT_BIND_ADDRESS
6650
    if constants.ENABLE_FILE_STORAGE:
6651
      # this is needed because os.path.join does not accept None arguments
6652
      if self.op.file_storage_dir is None:
6653
        string_file_storage_dir = ""
6654
      else:
6655
        string_file_storage_dir = self.op.file_storage_dir
6634 6656

  
6635
    # this is needed because os.path.join does not accept None arguments
6636
    if self.op.file_storage_dir is None:
6637
      string_file_storage_dir = ""
6657
      # build the full file storage dir path
6658
      file_storage_dir = utils.PathJoin(self.cfg.GetFileStorageDir(),
6659
                                        string_file_storage_dir, instance)
6638 6660
    else:
6639
      string_file_storage_dir = self.op.file_storage_dir
6640

  
6641
    # build the full file storage dir path
6642
    file_storage_dir = utils.PathJoin(self.cfg.GetFileStorageDir(),
6643
                                      string_file_storage_dir, instance)
6661
      file_storage_dir = ""
6644 6662

  
6645 6663

  
6646 6664
    disks = _GenerateDiskTemplate(self,
......
7660 7678
  def CheckArguments(self):
7661 7679
    self.op.node_name = _ExpandNodeName(self.cfg, self.op.node_name)
7662 7680

  
7681
    _CheckStorageType(self.op.storage_type)
7682

  
7663 7683
  def ExpandNames(self):
7664 7684
    self.needed_locks = {
7665 7685
      locking.LEVEL_NODE: [self.op.node_name],

Also available in: Unified diff