Revision 417eabe2

b/lib/cmdlib.py
6015 6015
      else:
6016 6016
        has_no_adopt = True
6017 6017
    if has_adopt and has_no_adopt:
6018
      raise errors.OpPrereqError("Either all disks have are adoped or none is",
6018
      raise errors.OpPrereqError("Either all disks are adopted or none is",
6019 6019
                                 errors.ECODE_INVAL)
6020 6020
    if has_adopt:
6021 6021
      if self.op.disk_template != constants.DT_PLAIN:
......
6031 6031

  
6032 6032
    self.adopt_disks = has_adopt
6033 6033

  
6034
    # verify creation mode
6035
    if self.op.mode not in (constants.INSTANCE_CREATE,
6036
                            constants.INSTANCE_IMPORT):
6037
      raise errors.OpPrereqError("Invalid instance creation mode '%s'" %
6038
                                 self.op.mode, errors.ECODE_INVAL)
6039

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

  
6043
    # instance name verification
6044
    if self.op.name_check:
6045
      self.hostname1 = utils.GetHostInfo(self.op.instance_name)
6046
      self.op.instance_name = self.hostname1.name
6047
      # used in CheckPrereq for ip ping check
6048
      self.check_ip = self.hostname1.ip
6049
    else:
6050
      self.check_ip = None
6051

  
6052
    # file storage checks
6053
    if (self.op.file_driver and
6054
        not self.op.file_driver in constants.FILE_DRIVER):
6055
      raise errors.OpPrereqError("Invalid file driver name '%s'" %
6056
                                 self.op.file_driver, errors.ECODE_INVAL)
6057

  
6058
    if self.op.file_storage_dir and os.path.isabs(self.op.file_storage_dir):
6059
      raise errors.OpPrereqError("File storage directory path not absolute",
6060
                                 errors.ECODE_INVAL)
6061

  
6062
    ### Node/iallocator related checks
6063
    if [self.op.iallocator, self.op.pnode].count(None) != 1:
6064
      raise errors.OpPrereqError("One and only one of iallocator and primary"
6065
                                 " node must be given",
6066
                                 errors.ECODE_INVAL)
6067

  
6068
    if self.op.mode == constants.INSTANCE_IMPORT:
6069
      # On import force_variant must be True, because if we forced it at
6070
      # initial install, our only chance when importing it back is that it
6071
      # works again!
6072
      self.op.force_variant = True
6073

  
6074
      if self.op.no_install:
6075
        self.LogInfo("No-installation mode has no effect during import")
6076

  
6077
    else: # INSTANCE_CREATE
6078
      if getattr(self.op, "os_type", None) is None:
6079
        raise errors.OpPrereqError("No guest OS specified",
6080
                                   errors.ECODE_INVAL)
6081
      self.op.force_variant = getattr(self.op, "force_variant", False)
6082

  
6034 6083
  def ExpandNames(self):
6035 6084
    """ExpandNames for CreateInstance.
6036 6085

  
......
6041 6090

  
6042 6091
    # cheap checks, mostly valid constants given
6043 6092

  
6044
    # verify creation mode
6045
    if self.op.mode not in (constants.INSTANCE_CREATE,
6046
                            constants.INSTANCE_IMPORT):
6047
      raise errors.OpPrereqError("Invalid instance creation mode '%s'" %
6048
                                 self.op.mode, errors.ECODE_INVAL)
6049

  
6050
    # disk template and mirror node verification
6051
    _CheckDiskTemplate(self.op.disk_template)
6052

  
6053 6093
    if self.op.hypervisor is None:
6054 6094
      self.op.hypervisor = self.cfg.GetHypervisorType()
6055 6095

  
......
6078 6118

  
6079 6119
    #### instance parameters check
6080 6120

  
6081
    # instance name verification
6082
    if self.op.name_check:
6083
      hostname1 = utils.GetHostInfo(self.op.instance_name)
6084
      self.op.instance_name = instance_name = hostname1.name
6085
      # used in CheckPrereq for ip ping check
6086
      self.check_ip = hostname1.ip
6087
    else:
6088
      instance_name = self.op.instance_name
6089
      self.check_ip = None
6090

  
6121
    instance_name = self.op.instance_name
6091 6122
    # this is just a preventive check, but someone might still add this
6092 6123
    # instance in the meantime, and creation will fail at lock-add time
6093 6124
    if instance_name in self.cfg.GetInstanceList():
......
6119 6150
          raise errors.OpPrereqError("IP address set to auto but name checks"
6120 6151
                                     " have been skipped. Aborting.",
6121 6152
                                     errors.ECODE_INVAL)
6122
        nic_ip = hostname1.ip
6153
        nic_ip = self.hostname1.ip
6123 6154
      else:
6124 6155
        if not utils.IsValidIP(ip):
6125 6156
          raise errors.OpPrereqError("Given IP address '%s' doesn't look"
......
6187 6218
        new_disk["adopt"] = disk["adopt"]
6188 6219
      self.disks.append(new_disk)
6189 6220

  
6190
    # file storage checks
6191
    if (self.op.file_driver and
6192
        not self.op.file_driver in constants.FILE_DRIVER):
6193
      raise errors.OpPrereqError("Invalid file driver name '%s'" %
6194
                                 self.op.file_driver, errors.ECODE_INVAL)
6195

  
6196
    if self.op.file_storage_dir and os.path.isabs(self.op.file_storage_dir):
6197
      raise errors.OpPrereqError("File storage directory path not absolute",
6198
                                 errors.ECODE_INVAL)
6199

  
6200
    ### Node/iallocator related checks
6201
    if [self.op.iallocator, self.op.pnode].count(None) != 1:
6202
      raise errors.OpPrereqError("One and only one of iallocator and primary"
6203
                                 " node must be given",
6204
                                 errors.ECODE_INVAL)
6205

  
6206 6221
    if self.op.iallocator:
6207 6222
      self.needed_locks[locking.LEVEL_NODE] = locking.ALL_SET
6208 6223
    else:
......
6236 6251
          self.op.src_path = src_path = \
6237 6252
            utils.PathJoin(constants.EXPORT_DIR, src_path)
6238 6253

  
6239
      # On import force_variant must be True, because if we forced it at
6240
      # initial install, our only chance when importing it back is that it
6241
      # works again!
6242
      self.op.force_variant = True
6243

  
6244
      if self.op.no_install:
6245
        self.LogInfo("No-installation mode has no effect during import")
6246

  
6247
    else: # INSTANCE_CREATE
6248
      if getattr(self.op, "os_type", None) is None:
6249
        raise errors.OpPrereqError("No guest OS specified",
6250
                                   errors.ECODE_INVAL)
6251
      self.op.force_variant = getattr(self.op, "force_variant", False)
6252

  
6253 6254
  def _RunAllocator(self):
6254 6255
    """Run the allocator based on input opcode.
6255 6256

  

Also available in: Unified diff