Revision 2a196443 lib/cmdlib.py

b/lib/cmdlib.py
13247 13247
    private.params = new_params
13248 13248
    private.filled = new_filled_params
13249 13249

  
13250
  def CheckPrereq(self): # pylint: disable=R0914
13250
  def _PreCheckDiskTemplate(self, pnode_info):
13251
    """CheckPrereq checks related to a new disk template."""
13252
    # Arguments are passed to avoid configuration lookups
13253
    instance = self.instance
13254
    pnode = instance.primary_node
13255
    cluster = self.cluster
13256
    if instance.disk_template == self.op.disk_template:
13257
      raise errors.OpPrereqError("Instance already has disk template %s" %
13258
                                 instance.disk_template, errors.ECODE_INVAL)
13259

  
13260
    if (instance.disk_template,
13261
        self.op.disk_template) not in self._DISK_CONVERSIONS:
13262
      raise errors.OpPrereqError("Unsupported disk template conversion from"
13263
                                 " %s to %s" % (instance.disk_template,
13264
                                                self.op.disk_template),
13265
                                 errors.ECODE_INVAL)
13266
    _CheckInstanceState(self, instance, INSTANCE_DOWN,
13267
                        msg="cannot change disk template")
13268
    if self.op.disk_template in constants.DTS_INT_MIRROR:
13269
      if self.op.remote_node == pnode:
13270
        raise errors.OpPrereqError("Given new secondary node %s is the same"
13271
                                   " as the primary node of the instance" %
13272
                                   self.op.remote_node, errors.ECODE_STATE)
13273
      _CheckNodeOnline(self, self.op.remote_node)
13274
      _CheckNodeNotDrained(self, self.op.remote_node)
13275
      # FIXME: here we assume that the old instance type is DT_PLAIN
13276
      assert instance.disk_template == constants.DT_PLAIN
13277
      disks = [{constants.IDISK_SIZE: d.size,
13278
                constants.IDISK_VG: d.logical_id[0]}
13279
               for d in instance.disks]
13280
      required = _ComputeDiskSizePerVG(self.op.disk_template, disks)
13281
      _CheckNodesFreeDiskPerVG(self, [self.op.remote_node], required)
13282

  
13283
      snode_info = self.cfg.GetNodeInfo(self.op.remote_node)
13284
      snode_group = self.cfg.GetNodeGroup(snode_info.group)
13285
      ipolicy = ganeti.masterd.instance.CalculateGroupIPolicy(cluster,
13286
                                                              snode_group)
13287
      _CheckTargetNodeIPolicy(self, ipolicy, instance, snode_info,
13288
                              ignore=self.op.ignore_ipolicy)
13289
      if pnode_info.group != snode_info.group:
13290
        self.LogWarning("The primary and secondary nodes are in two"
13291
                        " different node groups; the disk parameters"
13292
                        " from the first disk's node group will be"
13293
                        " used")
13294

  
13295
  def CheckPrereq(self):
13251 13296
    """Check prerequisites.
13252 13297

  
13253 13298
    This only checks the instance list against the existing names.
......
13325 13370
      "Can't modify disk template and apply disk changes at the same time"
13326 13371

  
13327 13372
    if self.op.disk_template:
13328
      if instance.disk_template == self.op.disk_template:
13329
        raise errors.OpPrereqError("Instance already has disk template %s" %
13330
                                   instance.disk_template, errors.ECODE_INVAL)
13331

  
13332
      if (instance.disk_template,
13333
          self.op.disk_template) not in self._DISK_CONVERSIONS:
13334
        raise errors.OpPrereqError("Unsupported disk template conversion from"
13335
                                   " %s to %s" % (instance.disk_template,
13336
                                                  self.op.disk_template),
13337
                                   errors.ECODE_INVAL)
13338
      _CheckInstanceState(self, instance, INSTANCE_DOWN,
13339
                          msg="cannot change disk template")
13340
      if self.op.disk_template in constants.DTS_INT_MIRROR:
13341
        if self.op.remote_node == pnode:
13342
          raise errors.OpPrereqError("Given new secondary node %s is the same"
13343
                                     " as the primary node of the instance" %
13344
                                     self.op.remote_node, errors.ECODE_STATE)
13345
        _CheckNodeOnline(self, self.op.remote_node)
13346
        _CheckNodeNotDrained(self, self.op.remote_node)
13347
        # FIXME: here we assume that the old instance type is DT_PLAIN
13348
        assert instance.disk_template == constants.DT_PLAIN
13349
        disks = [{constants.IDISK_SIZE: d.size,
13350
                  constants.IDISK_VG: d.logical_id[0]}
13351
                 for d in instance.disks]
13352
        required = _ComputeDiskSizePerVG(self.op.disk_template, disks)
13353
        _CheckNodesFreeDiskPerVG(self, [self.op.remote_node], required)
13354

  
13355
        snode_info = self.cfg.GetNodeInfo(self.op.remote_node)
13356
        snode_group = self.cfg.GetNodeGroup(snode_info.group)
13357
        ipolicy = ganeti.masterd.instance.CalculateGroupIPolicy(cluster,
13358
                                                                snode_group)
13359
        _CheckTargetNodeIPolicy(self, ipolicy, instance, snode_info,
13360
                                ignore=self.op.ignore_ipolicy)
13361
        if pnode_info.group != snode_info.group:
13362
          self.LogWarning("The primary and secondary nodes are in two"
13363
                          " different node groups; the disk parameters"
13364
                          " from the first disk's node group will be"
13365
                          " used")
13373
      self._PreCheckDiskTemplate(pnode_info)
13366 13374

  
13367 13375
    # hvparams processing
13368 13376
    if self.op.hvparams:

Also available in: Unified diff