Revision 3d736ac9

b/lib/cmdlib.py
10725 10725
        nic.nicparams = dict(netparams)
10726 10726
        if nic.ip is not None:
10727 10727
          if nic.ip.lower() == constants.NIC_IP_POOL:
10728
            try:
10729
              nic.ip = self.cfg.GenerateIp(net_uuid, False, self.proc.GetECId())
10730
            except errors.ReservationError:
10731
              raise errors.OpPrereqError("Unable to get a free IP for NIC %d"
10732
                                         " from the address pool" % idx,
10733
                                         errors.ECODE_STATE)
10728
            nic.ip = self.cfg.GenerateIp(net_uuid, False, self.proc.GetECId())
10734 10729
            self.LogInfo("Chose IP %s from network %s", nic.ip, nobj.name)
10735 10730
          else:
10736
            try:
10737
              self.cfg.ReserveIp(net_uuid, nic.ip, False, self.proc.GetECId())
10738
            except errors.ReservationError:
10739
              raise errors.OpPrereqError("IP address %s already in use"
10740
                                         " or does not belong to network %s" %
10741
                                         (nic.ip, nobj.name),
10742
                                         errors.ECODE_NOTUNIQUE)
10731
            self.cfg.ReserveIp(net_uuid, nic.ip, False, self.proc.GetECId())
10743 10732

  
10744 10733
      # net is None, ip None or given
10745 10734
      elif self.op.conflicts_check:
......
13450 13439
      new_net_uuid = self.cfg.LookupNetwork(new_net_uuid_or_name)
13451 13440
      new_net_obj = self.cfg.GetNetwork(new_net_uuid)
13452 13441

  
13453
    if old_net_uuid:
13454
      old_net_obj = self.cfg.GetNetwork(old_net_uuid)
13455

  
13456 13442
    if new_net_uuid:
13457 13443
      netparams = self.cfg.GetGroupNetParams(new_net_uuid, pnode)
13458 13444
      if not netparams:
......
13529 13515
        # if IP is pool then require a network and generate one IP
13530 13516
        if new_ip.lower() == constants.NIC_IP_POOL:
13531 13517
          if new_net_uuid:
13532
            try:
13533
              new_ip = self.cfg.GenerateIp(new_net_uuid, False,
13518
            new_ip = self.cfg.GenerateIp(new_net_uuid, False,
13534 13519
                                           self.proc.GetECId())
13535
            except errors.ReservationError:
13536
              raise errors.OpPrereqError("Unable to get a free IP"
13537
                                         " from the address pool",
13538
                                         errors.ECODE_STATE)
13539
            self.LogInfo("Chose IP %s from network %s",
13540
                         new_ip,
13541
                         new_net_obj.name)
13520
            self.LogInfo("Got IP %s from network %s", new_ip, new_net_obj.name)
13542 13521
            params[constants.INIC_IP] = new_ip
13543 13522
          else:
13544 13523
            raise errors.OpPrereqError("ip=pool, but no network found",
13545 13524
                                       errors.ECODE_INVAL)
13546 13525
        # Reserve new IP if in the new network if any
13547 13526
        elif new_net_uuid:
13548
          try:
13549
            self.cfg.ReserveIp(new_net_uuid, new_ip, False, self.proc.GetECId())
13550
            self.LogInfo("Reserving IP %s in network %s",
13551
                         new_ip, new_net_obj.name)
13552
          except errors.ReservationError:
13553
            raise errors.OpPrereqError("IP %s not available in network %s" %
13554
                                       (new_ip, new_net_obj.name),
13555
                                       errors.ECODE_NOTUNIQUE)
13527
          self.cfg.ReserveIp(new_net_uuid, new_ip, False, self.proc.GetECId())
13528
          self.LogInfo("Reserving IP %s in network %s",
13529
                       new_ip, new_net_obj.name)
13556 13530
        # new network is None so check if new IP is a conflicting IP
13557 13531
        elif self.op.conflicts_check:
13558 13532
          _CheckForConflictingIp(self, new_ip, pnode)
13559 13533

  
13560 13534
      # release old IP if old network is not None
13561 13535
      if old_ip and old_net_uuid:
13562
        try:
13563
          self.cfg.ReleaseIp(old_net_uuid, old_ip, False, self.proc.GetECId())
13564
        except errors.AddressPoolError:
13565
          logging.warning("Release IP %s not contained in network %s",
13566
                          old_ip, old_net_obj.name)
13536
        self.cfg.ReleaseIp(old_net_uuid, old_ip, False, self.proc.GetECId())
13567 13537

  
13568 13538
    # there are no changes in (ip, network) tuple and old network is not None
13569 13539
    elif (old_net_uuid is not None and
......
16399 16369
    if self.op.conflicts_check:
16400 16370
      for node in self.cfg.GetAllNodesInfo().values():
16401 16371
        for ip in [node.primary_ip, node.secondary_ip]:
16402
          try:
16403
            if pool.Contains(ip):
16404
              pool.Reserve(ip)
16405
              self.LogInfo("Reserved IP address of node '%s' (%s)",
16406
                           node.name, ip)
16407
          except errors.AddressPoolError, err:
16408
            self.LogWarning("Cannot reserve IP address '%s' of node '%s': %s",
16409
                            ip, node.name, err)
16372
          if pool.Contains(ip):
16373
            pool.Reserve(ip, True)
16374
            self.LogInfo("Reserved IP address of node '%s' (%s)",
16375
                         node.name, ip)
16410 16376

  
16411 16377
      master_ip = self.cfg.GetClusterInfo().master_ip
16412
      try:
16413
        if pool.Contains(master_ip):
16414
          pool.Reserve(master_ip)
16415
          self.LogInfo("Reserved cluster master IP address (%s)", master_ip)
16416
      except errors.AddressPoolError, err:
16417
        self.LogWarning("Cannot reserve cluster master IP address (%s): %s",
16418
                        master_ip, err)
16378
      if pool.Contains(master_ip):
16379
        pool.Reserve(master_ip)
16380
        self.LogInfo("Reserved cluster master IP address (%s)", master_ip)
16419 16381

  
16420 16382
    if self.op.add_reserved_ips:
16421 16383
      for ip in self.op.add_reserved_ips:
16422
        try:
16384
        if pool.Contains(ip):
16423 16385
          pool.Reserve(ip, external=True)
16424
        except errors.AddressPoolError, err:
16425
          raise errors.OpExecError("Cannot reserve IP address '%s': %s" %
16426
                                   (ip, err))
16427 16386

  
16428 16387
    self.cfg.AddNetwork(self.nobj, self.proc.GetECId(), check_uuid=False)
16429 16388
    del self.remove_locks[locking.LEVEL_NETWORK]
b/lib/config.py
378 378
      try:
379 379
        ip = pool.GenerateFree()
380 380
      except errors.AddressPoolError:
381
        raise errors.ReservationError("Cannot generate IP. Network is full")
381
        raise errors.OpPrereqError("Cannot generate IP. Network is full",
382
                                   errors.ECODE_STATE)
382 383
      return (constants.RESERVE_ACTION, ip, net_uuid, external)
383 384

  
384 385
    _, address, _, _ = self._temporary_ips.Generate([], gen_one, ec_id)

Also available in: Unified diff