Revision f276c4b5 lib/cmdlib.py

b/lib/cmdlib.py
568 568
    msg = ("Invalid disk template name '%s', valid templates are: %s" %
569 569
           (template, utils.CommaJoin(constants.DISK_TEMPLATES)))
570 570
    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",
573
                               errors.ECODE_INVAL)
571 574

  
572 575

  
573 576
def _CheckInstanceDown(lu, instance, reason):
......
5973 5976
  """
5974 5977
  HPATH = "instance-add"
5975 5978
  HTYPE = constants.HTYPE_INSTANCE
5976
  _OP_REQP = ["instance_name", "disks", "disk_template",
5979
  _OP_REQP = ["instance_name", "disks",
5977 5980
              "mode", "start",
5978 5981
              "wait_for_sync", "ip_check", "nics",
5979 5982
              "hvparams", "beparams"]
......
5984 5987

  
5985 5988
    """
5986 5989
    # set optional parameters to none if they don't exist
5987
    for attr in ["pnode", "snode", "iallocator", "hypervisor"]:
5990
    for attr in ["pnode", "snode", "iallocator", "hypervisor",
5991
                 "disk_template"]:
5988 5992
      if not hasattr(self.op, attr):
5989 5993
        setattr(self.op, attr, None)
5990 5994

  
......
6003 6007
      # TODO: make the ip check more flexible and not depend on the name check
6004 6008
      raise errors.OpPrereqError("Cannot do ip checks without a name check",
6005 6009
                                 errors.ECODE_INVAL)
6006
    if (self.op.disk_template == constants.DT_FILE and
6007
        not constants.ENABLE_FILE_STORAGE):
6008
      raise errors.OpPrereqError("File storage disabled at configure time",
6009
                                 errors.ECODE_INVAL)
6010 6010
    # check disk information: either all adopt, or no adopt
6011 6011
    has_adopt = has_no_adopt = False
6012 6012
    for disk in self.op.disks:
......
6037 6037
      raise errors.OpPrereqError("Invalid instance creation mode '%s'" %
6038 6038
                                 self.op.mode, errors.ECODE_INVAL)
6039 6039

  
6040
    # disk template
6041
    _CheckDiskTemplate(self.op.disk_template)
6042

  
6043 6040
    # instance name verification
6044 6041
    if self.op.name_check:
6045 6042
      self.hostname1 = utils.GetHostInfo(self.op.instance_name)
......
6079 6076
        raise errors.OpPrereqError("No guest OS specified",
6080 6077
                                   errors.ECODE_INVAL)
6081 6078
      self.op.force_variant = getattr(self.op, "force_variant", False)
6079
      if self.op.disk_template is None:
6080
        raise errors.OpPrereqError("No disk template specified",
6081
                                   errors.ECODE_INVAL)
6082 6082

  
6083 6083
  def ExpandNames(self):
6084 6084
    """ExpandNames for CreateInstance.
......
6248 6248
                                 errors.ECODE_ENVIRON)
6249 6249
    return export_info
6250 6250

  
6251
  def _ReadExportParams(self, einfo):
6252
    """Use export parameters as defaults.
6253

  
6254
    In case the opcode doesn't specify (as in override) some instance
6255
    parameters, then try to use them from the export information, if
6256
    that declares them.
6257

  
6258
    """
6259
    if self.op.disk_template is None:
6260
      if einfo.has_option(constants.INISECT_INS, "disk_template"):
6261
        self.op.disk_template = einfo.get(constants.INISECT_INS,
6262
                                          "disk_template")
6263
      else:
6264
        raise errors.OpPrereqError("No disk template specified and the export"
6265
                                   " is missing the disk_template information",
6266
                                   errors.ECODE_INVAL)
6267

  
6251 6268
  def CheckPrereq(self):
6252 6269
    """Check prerequisites.
6253 6270

  
6254 6271
    """
6255 6272
    if self.op.mode == constants.INSTANCE_IMPORT:
6256 6273
      export_info = self._ReadExportInfo()
6274
      self._ReadExportParams(export_info)
6275

  
6276
    _CheckDiskTemplate(self.op.disk_template)
6257 6277

  
6258 6278
    if (not self.cfg.GetVGName() and
6259 6279
        self.op.disk_template not in constants.DTS_NOT_LVM):

Also available in: Unified diff