Revision 63742d78 lib/cmdlib.py

b/lib/cmdlib.py
11019 11019

  
11020 11020
  def ExpandNames(self):
11021 11021
    self._ExpandAndLockInstance()
11022
    # Can't even acquire node locks in shared mode as upcoming changes in
11023
    # Ganeti 2.6 will start to modify the node object on disk conversion
11022 11024
    self.needed_locks[locking.LEVEL_NODE] = []
11025
    self.needed_locks[locking.LEVEL_NODE_RES] = []
11023 11026
    self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
11024 11027

  
11025 11028
  def DeclareLocks(self, level):
......
11028 11031
      if self.op.disk_template and self.op.remote_node:
11029 11032
        self.op.remote_node = _ExpandNodeName(self.cfg, self.op.remote_node)
11030 11033
        self.needed_locks[locking.LEVEL_NODE].append(self.op.remote_node)
11034
    elif level == locking.LEVEL_NODE_RES and self.op.disk_template:
11035
      # Copy node locks
11036
      self.needed_locks[locking.LEVEL_NODE_RES] = \
11037
        self.needed_locks[locking.LEVEL_NODE][:]
11031 11038

  
11032 11039
  def BuildHooksEnv(self):
11033 11040
    """Build hooks env.
......
11361 11368
                                     (disk_op, len(instance.disks)),
11362 11369
                                     errors.ECODE_INVAL)
11363 11370

  
11364
    return
11365

  
11366 11371
  def _ConvertPlainToDrbd(self, feedback_fn):
11367 11372
    """Converts an instance from plain to drbd.
11368 11373

  
......
11372 11377
    pnode = instance.primary_node
11373 11378
    snode = self.op.remote_node
11374 11379

  
11380
    assert instance.disk_template == constants.DT_PLAIN
11381

  
11375 11382
    # create a fake disk info for _GenerateDiskTemplate
11376 11383
    disk_info = [{constants.IDISK_SIZE: d.size, constants.IDISK_MODE: d.mode,
11377 11384
                  constants.IDISK_VG: d.logical_id[0]}
......
11408 11415
    instance.disks = new_disks
11409 11416
    self.cfg.Update(instance, feedback_fn)
11410 11417

  
11418
    # Release node locks while waiting for sync
11419
    _ReleaseLocks(self, locking.LEVEL_NODE)
11420

  
11411 11421
    # disks are created, waiting for sync
11412 11422
    disk_abort = not _WaitForSync(self, instance,
11413 11423
                                  oneshot=not self.op.wait_for_sync)
......
11415 11425
      raise errors.OpExecError("There are some degraded disks for"
11416 11426
                               " this instance, please cleanup manually")
11417 11427

  
11428
    # Node resource locks will be released by caller
11429

  
11418 11430
  def _ConvertDrbdToPlain(self, feedback_fn):
11419 11431
    """Converts an instance from drbd to plain.
11420 11432

  
11421 11433
    """
11422 11434
    instance = self.instance
11435

  
11423 11436
    assert len(instance.secondary_nodes) == 1
11437
    assert instance.disk_template == constants.DT_DRBD8
11438

  
11424 11439
    pnode = instance.primary_node
11425 11440
    snode = instance.secondary_nodes[0]
11426 11441
    feedback_fn("Converting template to plain")
......
11438 11453
    instance.disk_template = constants.DT_PLAIN
11439 11454
    self.cfg.Update(instance, feedback_fn)
11440 11455

  
11456
    # Release locks in case removing disks takes a while
11457
    _ReleaseLocks(self, locking.LEVEL_NODE)
11458

  
11441 11459
    feedback_fn("Removing volumes on the secondary node...")
11442 11460
    for disk in old_disks:
11443 11461
      self.cfg.SetDiskID(disk, snode)
......
11455 11473
        self.LogWarning("Could not remove metadata for disk %d on node %s,"
11456 11474
                        " continuing anyway: %s", idx, pnode, msg)
11457 11475

  
11476
    # Node resource locks will be released by caller
11477

  
11458 11478
  def Exec(self, feedback_fn):
11459 11479
    """Modifies an instance.
11460 11480

  
......
11466 11486
    for warn in self.warn:
11467 11487
      feedback_fn("WARNING: %s" % warn)
11468 11488

  
11489
    assert ((self.op.disk_template is None) ^
11490
            bool(self.owned_locks(locking.LEVEL_NODE_RES))), \
11491
      "Not owning any node resource locks"
11492

  
11469 11493
    result = []
11470 11494
    instance = self.instance
11471 11495
    # disk changes
......
11523 11547
                       disk_dict[constants.IDISK_MODE]))
11524 11548

  
11525 11549
    if self.op.disk_template:
11550
      if __debug__:
11551
        check_nodes = set(instance.all_nodes)
11552
        if self.op.remote_node:
11553
          check_nodes.add(self.op.remote_node)
11554
        for level in [locking.LEVEL_NODE, locking.LEVEL_NODE_RES]:
11555
          owned = self.owned_locks(level)
11556
          assert not (check_nodes - owned), \
11557
            ("Not owning the correct locks, owning %r, expected at least %r" %
11558
             (owned, check_nodes))
11559

  
11526 11560
      r_shut = _ShutdownInstanceDisks(self, instance)
11527 11561
      if not r_shut:
11528 11562
        raise errors.OpExecError("Cannot shutdown instance disks, unable to"
......
11535 11569
        raise
11536 11570
      result.append(("disk_template", self.op.disk_template))
11537 11571

  
11572
      assert instance.disk_template == self.op.disk_template, \
11573
        ("Expected disk template '%s', found '%s'" %
11574
         (self.op.disk_template, instance.disk_template))
11575

  
11576
    # Release node and resource locks if there are any (they might already have
11577
    # been released during disk conversion)
11578
    _ReleaseLocks(self, locking.LEVEL_NODE)
11579
    _ReleaseLocks(self, locking.LEVEL_NODE_RES)
11580

  
11538 11581
    # NIC changes
11539 11582
    for nic_op, nic_dict in self.op.nics:
11540 11583
      if nic_op == constants.DDM_REMOVE:
......
11587 11630

  
11588 11631
    self.cfg.Update(instance, feedback_fn)
11589 11632

  
11633
    assert not (self.owned_locks(locking.LEVEL_NODE_RES) or
11634
                self.owned_locks(locking.LEVEL_NODE)), \
11635
      "All node locks should have been released by now"
11636

  
11590 11637
    return result
11591 11638

  
11592 11639
  _DISK_CONVERSIONS = {

Also available in: Unified diff